Header menu logo FSharp.Collections.Builders

Default Module

Exposes type-inference-friendly collection builders.

Example

The type of xs is inferred to be seq<int>.

 let f xs =
     resizeArray {
         for x in xs -> x * x
     }
val f: xs: 'a -> 'b
val xs: 'a

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 =
     resizeArray {
         for x in xs -> x * x
     }
val f: xs: 'a -> 'b
val xs: 'a
 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.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 * '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:
Returns: CollectionBuilderCode<^c>
Modifiers: inline
Type parameters: 'a, 'b, ^c, 'd

Extended Type: DictionaryBuilder

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

this.YieldFrom

Full Usage: this.YieldFrom

Parameters:
    xs : 'a seq

Returns: CollectionBuilderCode<Set<'a>>
Modifiers: inline
Type parameters: 'a

Extended Type: SetBuilder

xs : 'a seq
Returns: CollectionBuilderCode<Set<'a>>

this.YieldFrom

Full Usage: this.YieldFrom

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

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

Extended Type: MapBuilder

xs : ('a * 'b) seq
Returns: CollectionBuilderCode<Map<'a, 'b>>

this.YieldFrom

Full Usage: this.YieldFrom

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

Extended Type: MapBuilder

xs : KeyValuePair<'a, 'b> seq
Returns: CollectionBuilderCode<Map<'a, 'b>>

Type something to start searching.