Header menu logo FSharp.Collections.Builders

Specialized Module

Contains specialized overloads of for and yield! that give increased iteration performance for common collection types at the cost of requiring that the type of the collection being iterated be statically known.

Example

The type of xs must be annotated or otherwise known, but once it is, the appropriate specialized iteration technique will be used.

 let f (xs : int list) =
     resizeArray {
         for x in xs -> x * x
     }
val f: xs: int list -> 'a
val xs: int list
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
type 'T list = List<'T>
xs is known to be a list because of the call to List.length.
 let g xs =
     let len = List.length xs
     resizeArray {
         for x in xs -> x * len
     }
val g: xs: 'a list -> 'b
val xs: 'a list
val len: int
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val length: list: 'T list -> int

Functions and values

Function or value Description

collection

Full Usage: collection

Returns: GenericCollectionBuilder<'Collection>

Builds a collection of the inferred or specified type using computation expression syntax.

Returns: GenericCollectionBuilder<'Collection>
Example

 let xs = [|2..100|]
 let ys = collection<ResizeArray<int>> { 0; 1; yield! xs }
 let zs = collection<HashSet<int>> { 0; 1; yield! xs }
val xs: int array
val ys: obj
type ResizeArray<'T> = System.Collections.Generic.List<'T>
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
val zs: obj
 let xs = [|2..100|]
 let ys : ResizeArray<int> = collection { 0; 1; yield! xs }
 let zs : HashSet<int> = collection { 0; 1; yield! xs }
val xs: int array
val ys: ResizeArray<int>
type ResizeArray<'T> = System.Collections.Generic.List<'T>
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
val zs: obj

dict'

Full Usage: dict'

Returns: GenericDictionaryBuilder<'Dictionary>

Builds a dictionary of the inferred or specified type using computation expression syntax.

Returns: GenericDictionaryBuilder<'Dictionary>
Example

 let m = dict'<Dictionary<int, int>> { 0, 0; 1, 1 }
 let m = dict'<SortedDictionary<int, int>> { 0, 0; 1, 1 }
val m: obj
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
 let m : Dictionary<int, int> = dict' { 0, 0; 1, 1 }
 let m : SortedDictionary<int, int> = dict' { 0, 0; 1, 1 }
val m: obj
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

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

dictionary

Full Usage: dictionary

Returns: DictionaryBuilder<'Key, 'Value>

Builds a Dictionary using computation expression syntax.

Returns: DictionaryBuilder<'Key, 'Value>
Example

 let m = dictionary { 1, "a"; 2, "b"; 3, "c" }
val m: obj

hashSet

Full Usage: hashSet

Returns: HashSetBuilder<'T>

Builds a HashSet using computation expression syntax.

Returns: HashSetBuilder<'T>
Example

 let xs = hashSet { 1; 2; 3 }
val xs: obj

immutableArray

Full Usage: immutableArray

Returns: ImmutableArrayBuilder<'T>

Builds an ImmutableArray using computation expression syntax.

Returns: ImmutableArrayBuilder<'T>
Example

 let xs = immutableArray { 1; 2; 3 }
val xs: obj

immutableDictionary

Full Usage: immutableDictionary

Returns: ImmutableDictionaryBuilder<'Key, 'Value>

Builds an ImmutableDictionary using computation expression syntax.

Returns: ImmutableDictionaryBuilder<'Key, 'Value>
Example

 let m = immutableDictionary { 1, "a"; 2, "b"; 3, "c" }
val m: obj

immutableHashSet

Full Usage: immutableHashSet

Returns: ImmutableHashSetBuilder<'T>

Builds an ImmutableHashSet using computation expression syntax.

Returns: ImmutableHashSetBuilder<'T>
Example

 let xs = immutableHashSet { 1; 2; 3 }
val xs: obj

immutableList

Full Usage: immutableList

Returns: ImmutableListBuilder<'T>

Builds an ImmutableList using computation expression syntax.

Returns: ImmutableListBuilder<'T>
Example

 let xs = immutableList { 1; 2; 3 }
val xs: obj

immutableSortedDictionary

Full Usage: immutableSortedDictionary

Returns: ImmutableSortedDictionaryBuilder<'Key, 'Value>

Builds an ImmutableSortedDictionary using computation expression syntax.

Returns: ImmutableSortedDictionaryBuilder<'Key, 'Value>
Example

 let m = immutableSortedDictionary { 1, "a"; 2, "b"; 3, "c" }
val m: obj

immutableSortedSet

Full Usage: immutableSortedSet

Returns: ImmutableSortedSetBuilder<'T>

Builds an ImmutableSortedSet using computation expression syntax.

Returns: ImmutableSortedSetBuilder<'T>
Example

 let xs = immutableSortedSet { 1; 2; 3 }
val xs: obj

map

Full Usage: map

Returns: MapBuilder<'Key, 'Value>

Builds a Map using computation expression syntax.

Returns: MapBuilder<'Key, 'Value>
Example

 let m = map { 1, "a"; 2, "b"; 3, "c" }
val m: obj

resizeArray

Full Usage: resizeArray

Returns: ResizeArrayBuilder<'T>

Builds a List using computation expression syntax.

Returns: ResizeArrayBuilder<'T>
Example

 let f (xs : int list) =
     resizeArray {
         for x in xs -> x * x
     }
val f: xs: int list -> 'a
val xs: int list
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
type 'T list = List<'T>
 let a = 1
 let xs = [|2..100|]
 let ys = resizeArray { 0; 1; yield! xs }
val a: int
val xs: int array
val ys: obj

set'

Full Usage: set'

Returns: SetBuilder<'T>

Builds a Set using computation expression syntax.

Returns: SetBuilder<'T>
Example

 let xs = set' { 1; 2; 3 }
val xs: obj

sortedDictionary

Full Usage: sortedDictionary

Returns: SortedDictionaryBuilder<'Key, 'Value>

Builds a SortedDictionary using computation expression syntax.

Returns: SortedDictionaryBuilder<'Key, 'Value>
Example

 let m = sortedDictionary { 1, "a"; 2, "b"; 3, "c" }
val m: obj

sortedSet

Full Usage: sortedSet

Returns: SortedSetBuilder<'T>

Builds a SortedSet using computation expression syntax.

Returns: SortedSetBuilder<'T>
Example

 let xs = sortedSet { 1; 2; 3 }
val xs: obj

sum

Full Usage: sum

Returns: SumBuilder

Computes a sum using computation expression syntax.

Returns: SumBuilder
Example

 let s = sum { 1; 2; 3 }
val s: obj
 let xs = [1..100]
 let s = sum { for x in xs -> x }
val xs: int list
val s: obj
 let xs = [4..100]
 let s = sum { 1; 2; 3; yield! xs }
val xs: int list
val s: obj

Σ

Full Usage: Σ

Returns: SumBuilder

Computes a sum using computation expression syntax.

Returns: SumBuilder
Example

 let s = Σ { 1; 2; 3 }
val s: obj
 let xs = [1..100]
 let s = Σ { for x in xs -> x }
val xs: int list
val s: obj
 let xs = [4..100]
 let s = Σ { 1; 2; 3; yield! xs }
val xs: int list
val s: obj

Type extensions

Type extension Description

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<'b>
Modifiers: inline
Type parameters: 'a, 'b

Extended Type: CollectionBuilderBase

sequence : 'a seq
body : 'a -> CollectionBuilderCode<'b>
Returns: CollectionBuilderCode<'b>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<'b>
Modifiers: inline
Type parameters: 'a, 'b

Extended Type: CollectionBuilderBase

list : 'a list
body : 'a -> CollectionBuilderCode<'b>
Returns: CollectionBuilderCode<'b>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<'b>
Modifiers: inline
Type parameters: 'a, 'b

Extended Type: CollectionBuilderBase

array : 'a array
body : 'a -> CollectionBuilderCode<'b>
Returns: CollectionBuilderCode<'b>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<'b>
Modifiers: inline
Type parameters: 'a, 'b

Extended Type: CollectionBuilderBase

set : Set<'a>
body : 'a -> CollectionBuilderCode<'b>
Returns: CollectionBuilderCode<'b>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<'c>
Modifiers: inline
Type parameters: 'a, 'b, 'c

Extended Type: CollectionBuilderBase

map : Map<'a, 'b>
body : 'a * 'b -> CollectionBuilderCode<'c>
Returns: CollectionBuilderCode<'c>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<'b>
Modifiers: inline
Type parameters: 'a, 'b

Extended Type: CollectionBuilderBase

resizeArray : ResizeArray<'a>
body : 'a -> CollectionBuilderCode<'b>
Returns: CollectionBuilderCode<'b>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<'b>
Modifiers: inline
Type parameters: 'a, 'b

Extended Type: CollectionBuilderBase

immutableArray : ImmutableArray<'a>
body : 'a -> CollectionBuilderCode<'b>
Returns: CollectionBuilderCode<'b>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<'b>
Modifiers: inline
Type parameters: 'a, 'b

Extended Type: CollectionBuilderBase

immutableArrayBuilder : Builder<'a>
body : 'a -> CollectionBuilderCode<'b>
Returns: CollectionBuilderCode<'b>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, ^b, ^c

Extended Type: SumBuilder

span : Span<'a>
body : 'a -> CollectionBuilderCode<^b>
Returns: CollectionBuilderCode<^c>

this.For

Full Usage: this.For

Parameters:
Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, ^b, ^c

Extended Type: SumBuilder

span : ReadOnlySpan<'a>
body : 'a -> CollectionBuilderCode<^b>
Returns: CollectionBuilderCode<^c>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : 'a seq

Returns: CollectionBuilderCode<^b>
Modifiers: inline
Type parameters: 'a, ^b, 'c

Extended Type: CollectionBuilder

xs : 'a seq
Returns: CollectionBuilderCode<^b>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : 'a list

Returns: CollectionBuilderCode<^b>
Modifiers: inline
Type parameters: 'a, ^b, 'c

Extended Type: CollectionBuilder

xs : 'a list
Returns: CollectionBuilderCode<^b>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : 'a array

Returns: CollectionBuilderCode<^b>
Modifiers: inline
Type parameters: 'a, ^b, 'c

Extended Type: CollectionBuilder

xs : 'a array
Returns: CollectionBuilderCode<^b>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : ResizeArray<'a>

Returns: CollectionBuilderCode<^b>
Modifiers: inline
Type parameters: 'a, ^b, 'c

Extended Type: CollectionBuilder

xs : ResizeArray<'a>
Returns: CollectionBuilderCode<^b>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
Returns: CollectionBuilderCode<^b>
Modifiers: inline
Type parameters: 'a, ^b, 'c

Extended Type: CollectionBuilder

xs : Set<'a>
Returns: CollectionBuilderCode<^b>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : Map<'a, 'b>

Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: CollectionBuilder

xs : Map<'a, 'b>
Returns: CollectionBuilderCode<^c>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
Returns: CollectionBuilderCode<^b>
Modifiers: inline
Type parameters: 'a, ^b, 'c

Extended Type: CollectionBuilder

xs : ImmutableArray<'a>
Returns: CollectionBuilderCode<^b>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : ('a * 'b) seq

Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: DictionaryBuilder

xs : ('a * 'b) seq
Returns: CollectionBuilderCode<^c>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : ('a * 'b) list

Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: DictionaryBuilder

xs : ('a * 'b) list
Returns: CollectionBuilderCode<^c>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : ('a * 'b) array

Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: DictionaryBuilder

xs : ('a * 'b) array
Returns: CollectionBuilderCode<^c>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : ResizeArray<'a * 'b>

Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: DictionaryBuilder

xs : ResizeArray<'a * 'b>
Returns: CollectionBuilderCode<^c>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : Set<'a * 'b>

Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: DictionaryBuilder

xs : Set<'a * 'b>
Returns: CollectionBuilderCode<^c>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : Map<'a, 'b>

Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: DictionaryBuilder

xs : Map<'a, 'b>
Returns: CollectionBuilderCode<^c>

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: DictionaryBuilder

xs : ImmutableArray<'a * 'b>
Returns: CollectionBuilderCode<^c>

Type something to start searching.