41 people like it.

LinkedList extensions

LinkedList functional extension providing find and findi higher order functions that take a predicate function.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
[<RequireQualifiedAccess>]
module LinkedList =   
   open System.Collections.Generic
   let empty<'a> = LinkedList<'a>()
   let find (f:'a->bool) (xs:LinkedList<'a>) =
      let node = ref xs.First
      while (!node <> null && not <| f((!node).Value)) do 
         node := (!node).Next
      !node
   let findi (f:int->'a->bool) (xs:LinkedList<'a>) =
      let node = ref xs.First
      let i = ref 0
      while (!node <> null && not <| f (!i) (!node).Value) do 
         incr i; node := (!node).Next
      if !node = null then -1 else !i
Multiple items
type RequireQualifiedAccessAttribute =
  inherit Attribute
  new : unit -> RequireQualifiedAccessAttribute

Full name: Microsoft.FSharp.Core.RequireQualifiedAccessAttribute

--------------------
new : unit -> RequireQualifiedAccessAttribute
module LinkedList

from Script
namespace System
namespace System.Collections
namespace System.Collections.Generic
val empty<'a> : LinkedList<'a>

Full name: Script.LinkedList.empty
Multiple items
type LinkedList<'T> =
  new : unit -> LinkedList<'T> + 1 overload
  member AddAfter : node:LinkedListNode<'T> * value:'T -> LinkedListNode<'T> + 1 overload
  member AddBefore : node:LinkedListNode<'T> * value:'T -> LinkedListNode<'T> + 1 overload
  member AddFirst : value:'T -> LinkedListNode<'T> + 1 overload
  member AddLast : value:'T -> LinkedListNode<'T> + 1 overload
  member Clear : unit -> unit
  member Contains : value:'T -> bool
  member CopyTo : array:'T[] * index:int -> unit
  member Count : int
  member Find : value:'T -> LinkedListNode<'T>
  ...
  nested type Enumerator

Full name: System.Collections.Generic.LinkedList<_>

--------------------
LinkedList() : unit
LinkedList(collection: IEnumerable<'T>) : unit
val find : f:('a -> bool) -> xs:LinkedList<'a> -> LinkedListNode<'a>

Full name: Script.LinkedList.find
val f : ('a -> bool)
type bool = System.Boolean

Full name: Microsoft.FSharp.Core.bool
val xs : LinkedList<'a>
val node : LinkedListNode<'a> ref
Multiple items
val ref : value:'T -> 'T ref

Full name: Microsoft.FSharp.Core.Operators.ref

--------------------
type 'T ref = Ref<'T>

Full name: Microsoft.FSharp.Core.ref<_>
property LinkedList.First: LinkedListNode<'a>
val not : value:bool -> bool

Full name: Microsoft.FSharp.Core.Operators.not
val findi : f:(int -> 'a -> bool) -> xs:LinkedList<'a> -> int

Full name: Script.LinkedList.findi
val f : (int -> 'a -> bool)
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val i : int ref
val incr : cell:int ref -> unit

Full name: Microsoft.FSharp.Core.Operators.incr
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/2g
Posted:13 years ago
Author:Phillip Trelford
Tags: linkedlist