Contains operations for working with values of type seq.
Function or value  Description  

Example
([1; 2], [3; 4]) > Seq.allPairsEvaluates to a sequence yielding the same results as seq { (1, 3); (1, 4); (2, 3); (2, 4) } 


The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
Seq.append [1; 2] [3; 4]Evaluates to a sequence yielding the same results as seq { 1; 2; 3; 4 }


Full Usage:
Seq.average source
Parameters:
seq<^T>

The input sequence.
Returns: ^T
The average.
Modifiers: inline Type parameters: ^T 
The elements are averaged using the
Example
[1.0; 2.0; 3.0] > Seq.averageEvaluates to 2.0
Example
[] > Seq.averageThrows ArgumentException


Full Usage:
Seq.averageBy projection source
Parameters:
'T > ^U

A function applied to transform each element of the sequence.
source : seq<'T>

The input sequence.
Returns: ^U
The average.
Modifiers: inline Type parameters: 'T, ^U 
Returns the average of the results generated by applying the function to each element of the sequence.
The elements are averaged using the
Example
type Foo = { Bar: float } let input = seq { {Bar = 2.0}; {Bar = 4.0} } input > Seq.averageBy (fun foo > foo.Bar)Evaluates to 3.0
Example
type Foo = { Bar: float } Seq.empty > Seq.averageBy (fun (foo: Foo) > foo.Bar)Throws ArgumentException



The result sequence will have the same elements as the input sequence. The result can be enumerated multiple times. The input sequence will be enumerated at most once and only as far as is necessary. Caching a sequence is typically useful when repeatedly evaluating items in the original sequence is computationally expensive or if iterating the sequence causes sideeffects that the user does not want to be repeated multiple times. Enumeration of the result sequence is thread safe in the sense that multiple independent IEnumerator values may be used simultaneously from different threads (accesses to the internal lookaside table are thread safe). Each individual IEnumerator is not typically thread safe and should not be accessed concurrently. Once enumeration of the input sequence has started, it's enumerator will be kept live by this object until the enumeration has completed. At that point, the enumerator will be disposed. The enumerator may be disposed and underlying cache storage released by converting the returned sequence object to type IDisposable, and calling the Dispose method on this object. The sequence object may then be reenumerated and a fresh enumerator will be used.
Example
let fibSeq =(0, 1) > Seq.unfold (fun (a,b) > Some(a + b, (b, a + b))) let fibSeq3 = fibSeq > Seq.take 3 > Seq.cache fibSeq3Evaluates to a sequence yielding the same results as seq { 1; 2; 3 } ,
and it will not do the calculation again when called.


Full Usage:
Seq.cast source
Parameters:
IEnumerable

The input sequence.
Returns: seq<'T>
The result sequence.

The use of this function usually requires a type annotation. An incorrect type annotation may result in runtime type errors. Individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
[box 1; box 2; box 3] > Seq.cast<int>Evaluates to a sequence yielding the same results as seq { 1; 2; 3 } , explicitly typed as seq<int> .



Applies the given function to each element of the sequence. Returns a sequence comprised of the results "x" for each element where the function returns Some(x). The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
[Some 1; None; Some 2] > Seq.choose idEvaluates to a sequence yielding the same results as seq { 1; 2 }
Example
[1; 2; 3] > Seq.choose (fun n > if n % 2 = 0 then Some n else None)Evaluates to a sequence yielding the same results as seq { 2 }



Example
[1; 2; 3] > Seq.chunkBySize 2Evaluates to a sequence yielding the same results as seq { [1; 2]; [3] }
Example
[1; 2; 3] > Seq.chunkBySize 2Throws ArgumentException



Remember sequence is lazy, effects are delayed until it is enumerated.
Example
type Foo = { Bar: int seq } let input = seq { {Bar = [1; 2]}; {Bar = [3; 4]} } input > Seq.collect (fun foo > foo.Bar)Evaluates to a sequence yielding the same results as seq { 1; 2; 3; 4 }
Example
let input = [[1; 2]; [3; 4]] input > Seq.collect idEvaluates to a sequence yielding the same results as seq { 1; 2; 3; 4 }


Full Usage:
Seq.compareWith comparer source1 source2
Parameters:
'T > 'T > int

A function that takes an element from each sequence and returns an int.
If it evaluates to a nonzero value iteration is stopped and that value is returned.
source1 : seq<'T>

The first input sequence.
source2 : seq<'T>

The second input sequence.
Returns: int
Returns the first nonzero result from the comparison function. If the end of a sequence
is reached it returns a 1 if the first sequence is shorter and a 1 if the second sequence
is shorter.

Example
let closerToNextDozen a b = (a % 12).CompareTo(b % 12) let input1 = [1; 10] let input2 = [1; 10] (input1, input2) > Seq.compareWith closerToNextDozenEvaluates to 0
Example
let closerToNextDozen a b = (a % 12).CompareTo(b % 12) let input1 = [1; 5] let input2 = [1; 8] (input1, input2) > Seq.compareWith closerToNextDozenEvaluates to 1
Example
let closerToNextDozen a b = (a % 12).CompareTo(b % 12) let input1 = [1; 11] let input2 = [1; 13] (input1, input2) > Seq.compareWith closerToNextDozenEvaluates to 1
Example
let closerToNextDozen a b = (a % 12).CompareTo(b % 12) let input1 = [1; 2] let input2 = [1] (input1, input2) > Seq.compareWith closerToNextDozenEvaluates to 1
Example
let closerToNextDozen a b = (a % 12).CompareTo(b % 12) let input1 = [1] let input2 = [1; 2] (input1, input2) > Seq.compareWith closerToNextDozenEvaluates to 1



The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
let inputs = [[1; 2]; [3]; [4; 5]] inputs > Seq.concatEvaluates to a sequence yielding the same results as seq { 1; 2; 3; 4; 5 }



Example
[1; 2] > Seq.contains 2 // evaluates to true [1; 2] > Seq.contains 5 // evaluates to false 


Applies a keygenerating function to each element of a sequence and returns a sequence yielding unique keys and their number of occurrences in the original sequence. Note that this function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences. The function makes no assumption on the ordering of the original sequence.
Example
type Foo = { Bar: string } let inputs = [{Bar = "a"}; {Bar = "b"}; {Bar = "a"}] inputs > Seq.countBy (fun foo > foo.Bar)Evaluates to a sequence yielding the same results as seq { ("a", 2); ("b", 1) }



The input function is evaluated each time an IEnumerator for the sequence is requested.
Example
Seq.delay (fun () > Seq.ofList [1; 2; 3])Evaluates to a sequence yielding the same results as seq { 1; 2; 3 } , executing
the generator function every time is consumed.



Returns a sequence that contains no duplicate entries according to generic hash and equality comparisons on the entries. If an element occurs multiple times in the sequence then the later occurrences are discarded.
Example
[1; 1; 2; 3] > Seq.distinctEvaluates to a sequence yielding the same results as seq { 1; 2; 3 }



Returns a sequence that contains no duplicate entries according to the generic hash and equality comparisons on the keys returned by the given keygenerating function. If an element occurs multiple times in the sequence then the later occurrences are discarded.
Example
let inputs = [{Bar = 1 };{Bar = 1}; {Bar = 2}; {Bar = 3}] inputs > Seq.distinctBy (fun foo > foo.Bar)Evaluates to a sequence yielding the same results as seq { { Bar = 1 }; { Bar = 2 }; { Bar = 3 } }


Example
Seq.empty // Evaluates to seq { } 

Full Usage:
Seq.exactlyOne source
Parameters:
seq<'T>

The input sequence.
Returns: 'T
The only element of the sequence.

Example
let inputs = ["banana"] inputs > Seq.exactlyOneEvaluates to banana
Example
let inputs = ["pear"; "banana"] inputs > Seq.exactlyOneThrows ArgumentException
Example
[] > Seq.exactlyOneThrows ArgumentException


Full Usage:
Seq.except itemsToExclude source
Parameters:
seq<'T>

A sequence whose elements that also occur in the second sequence will cause those elements to be
removed from the returned sequence.
source : seq<'T>

A sequence whose elements that are not also in first will be returned.
Returns: seq<'T>
A sequence that contains the set difference of the elements of two sequences.

Returns a new sequence with the distinct elements of the second sequence which do not appear in the first sequence, using generic hash and equality comparisons to compare values. Note that this function returns a sequence that digests the whole of the first input sequence as soon as the result sequence is iterated. As a result this function should not be used with large or infinite sequences in the first parameter. The function makes no assumption on the ordering of the first input sequence.
Example
let original = [1; 2; 3; 4; 5] let itemsToExclude = [1; 3; 5] original > Seq.except itemsToExcludeEvaluates to a sequence yielding the same results as seq { 2; 4 }



The predicate is applied to the elements of the input sequence. If any application returns true then the overall result is true and no further elements are tested. Otherwise, false is returned.
Example
let input = [1; 2; 3; 4; 5] input > Seq.exists (fun elm > elm % 4 = 0)Evaluates to true
Example
let input = [1; 2; 3; 4; 5] input > Seq.exists (fun elm > elm % 6 = 0)Evaluates to false


Full Usage:
Seq.exists2 predicate source1 source2
Parameters:
'T1 > 'T2 > bool

A function to test each pair of items from the input sequences.
source1 : seq<'T1>

The first input sequence.
source2 : seq<'T2>

The second input sequence.
Returns: bool
True if any result from the predicate is true; false otherwise.

The predicate is applied to matching elements in the two sequences up to the lesser of the two lengths of the collections. If any application returns true then the overall result is true and no further elements are tested. Otherwise, false is returned. If one sequence is shorter than the other then the remaining elements of the longer sequence are ignored.
Example
let inputs1 = [1; 2] let inputs2 = [1; 2; 0] (inputs1, inputs2) > Seq.exists2 (fun a b > a > b)Evaluates to false
Example
let inputs1 = [1; 4] let inputs2 = [1; 3; 5] (inputs1, inputs2) > Seq.exists2 (fun a b > a > b)Evaluates to true



Returns a new collection containing only the elements of the collection for which the given predicate returns "true". This is a synonym for Seq.where. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently. Remember sequence is lazy, effects are delayed until it is enumerated.
Example
let inputs = [1; 2; 3; 4] inputs > Seq.filter (fun elm > elm % 2 = 0)Evaluates to a sequence yielding the same results as seq { 2; 4 }



Example
let inputs = [1; 2; 3] inputs > Seq.find (fun elm > elm % 2 = 0)Evaluates to 2
Example
let inputs = [1; 2; 3] inputs > Seq.find (fun elm > elm % 6 = 0)Throws KeyNotFoundException



This function digests the whole initial sequence as soon as it is called. As a result this function should not be used with large or infinite sequences.
Example
let inputs = [2; 3; 4] inputs > Seq.findBack (fun elm > elm % 2 = 0)Evaluates to 4
Example
let inputs = [2; 3; 4] inputs > Seq.findBack (fun elm > elm % 6 = 0)Throws KeyNotFoundException



Example
let inputs = [1; 2; 3; 4; 5] inputs > Seq.findIndex (fun elm > elm % 2 = 0)Evaluates to 1
Example
let inputs = [1; 2; 3; 4; 5] inputs > Seq.findIndex (fun elm > elm % 6 = 0)Throws KeyNotFoundException



This function digests the whole initial sequence as soon as it is called. As a result this function should not be used with large or infinite sequences.
Example
let input = [1; 2; 3; 4; 5] input > Seq.findIndex (fun elm > elm % 2 = 0)Evaluates to 3
Example
let input = [1; 2; 3; 4; 5] input > Seq.findIndex (fun elm > elm % 6 = 0)Throws KeyNotFoundException


Full Usage:
Seq.fold folder state source
Parameters:
'State > 'T > 'State

A function that updates the state with each element from the sequence.
state : 'State

The initial state.
source : seq<'T>

The input sequence.
Returns: 'State
The state object after the folding function is applied to each element of the sequence.

Applies a function to each element of the collection, threading an accumulator argument
through the computation. If the input function is
Example
type Charge =  In of int  Out of int let inputs = [In 1; Out 2; In 3] (0, inputs) > Seq.fold (fun acc charge > match charge with  In i > acc + i  Out o > acc  o)Evaluates to 2


Full Usage:
Seq.fold2 folder state source1 source2
Parameters:
'State > 'T1 > 'T2 > 'State

The function to update the state given the input elements.
state : 'State

The initial state.
source1 : seq<'T1>

The first input sequence.
source2 : seq<'T2>

The second input sequence.
Returns: 'State
The final state value.

Applies a function to corresponding elements of two collections, threading an accumulator argument through the computation.
The two sequences need not have equal lengths:
when one sequence is exhausted any remaining elements in the other sequence are ignored.
If the input function is
Example
type CoinToss = Head  Tails let data1 = [Tails; Head; Tails] let data2 = [Tails; Head; Head] (0, data1, data2) > Seq.fold2 (fun acc a b > match (a, b) with  Head, Head > acc + 1  Tails, Tails > acc + 1  _ > acc  1)Evaluates to 1


Full Usage:
Seq.foldBack folder source state
Parameters:
'T > 'State > 'State

The function to update the state given the input elements.
source : seq<'T>

The input sequence.
state : 'State

The initial state.
Returns: 'State
The state object after the folding function is applied to each element of the sequence.

Applies a function to each element of the collection, starting from the end, threading an accumulator argument
through the computation. If the input function is This function consumes the whole input sequence before returning the result.
Example
type Count = { Positive: int Negative: int Text: string } let sequence = [1; 0; 1; 2; 3] let initialState = {Positive = 0; Negative = 0; Text = ""} (sequence, initialState) > Seq.foldBack (fun a acc > let text = acc.Text + " " + string a if a >= 0 then { acc with Positive = acc.Positive + 1 Text = text } else { acc with Negative = acc.Negative + 1 Text = text })Evaluates to { Positive = 2 Negative = 3 Text = " 3 2 1 0 1" } 

Full Usage:
Seq.foldBack2 folder source1 source2 state
Parameters:
'T1 > 'T2 > 'State > 'State

The function to update the state given the input elements.
source1 : seq<'T1>

The first input sequence.
source2 : seq<'T2>

The second input sequence.
state : 'State

The initial state.
Returns: 'State
The final state value.

Applies a function to corresponding elements of two collections, starting from the end of the shorter collection,
threading an accumulator argument through the computation. The two sequences need not have equal lengths.
If the input function is This function consumes the whole of both inputs sequences before returning the result. As a result this function should not be used with large or infinite sequences.
Example
type Count = { Positive: int Negative: int Text: string } let inputs1 = [1; 2; 3] let inputs2 = [3; 2; 1; 0] let initialState = {Positive = 0; Negative = 0; Text = ""} (inputs1, inputs2, initialState) > Seq.foldBack2 (fun a b acc > let text = acc.Text + "(" + string a + "," + string b + ") " if a + b >= 0 then { acc with Positive = acc.Positive + 1 Text = text } else { acc with Negative = acc.Negative + 1 Text = text } )Evaluates to { Positive = 2 Negative = 1 Text = " (3,1) (2,2) (1,3)" } 


The predicate is applied to the elements of the input sequence. If any application returns false then the overall result is false and no further elements are tested. Otherwise, true is returned.
Example
let isEven a = a % 2 = 0 [2; 42] > Seq.forall isEven // evaluates to true [1; 2] > Seq.forall isEven // evaluates to false 

Full Usage:
Seq.forall2 predicate source1 source2
Parameters:
'T1 > 'T2 > bool

A function to test pairs of elements from the input sequences.
source1 : seq<'T1>

The first input sequence.
source2 : seq<'T2>

The second input sequence.
Returns: bool
True if all pairs satisfy the predicate; false otherwise.

Tests the all pairs of elements drawn from the two sequences satisfy the given predicate. If one sequence is shorter than the other then the remaining elements of the longer sequence are ignored.
Example
let inputs1 = [1; 2; 3; 4; 5; 6] let inputs2 = [1; 2; 3; 4; 5] (inputs1, inputs2) > Seq.forall2 (=)Evaluates to true .
Example
let items1 = [2017; 1; 1] let items2 = [2019; 19; 8] (items1, items2) > Seq.forall2 (=)Evaluates to false .



Applies a keygenerating function to each element of a sequence and yields a sequence of unique keys. Each unique key contains a sequence of all elements that match to this key. This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences. The function makes no assumption on the ordering of the original sequence.
Example
let inputs = [1; 2; 3; 4; 5] inputs > Seq.groupBy (fun n > n % 2)Evaluates to a sequence yielding the same results as seq { (1, seq { 1; 3; 5 }); (0, seq { 2; 4 }) }


Full Usage:
Seq.head source
Parameters:
seq<'T>

The input sequence.
Returns: 'T
The first element of the sequence.

Example
let inputs = ["banana"; "pear"] inputs > Seq.headEvaluates to banana
Example
[] > Seq.headThrows ArgumentException



Builds a new collection whose elements are the corresponding elements of the input collection paired with the integer index (from 0) of each element.
Example
["a"; "b"; "c"] > Seq.indexedEvaluates to a sequence yielding the same results as seq { (0, "a"); (1, "b"); (2, "c") }



Generates a new sequence which, when iterated, will return successive elements by calling the given function, up to the given count. Each element is saved after its initialization. The function is passed the index of the item being generated. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
Seq.init 4 (fun v > v + 5)Evaluates to a sequence yielding the same results as seq { 5; 6; 7; 8 }
Example
Seq.init 5 (fun v > v + 5)Throws ArgumentException



Generates a new sequence which, when iterated, will return successive elements by calling the given function. The results of calling the function will not be saved, that is the function will be reapplied as necessary to regenerate the elements. The function is passed the index of the item being generated.
The returned sequence may be passed between threads safely. However,
individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Iteration can continue up to
Example
(+) 5 > Seq.initInfiniteEvaluates to a sequence yielding the same results as seq { 5; 6; 7; 8; ... }



Example
seq { 0; 1; 2 } > Seq.insertAt 1 9Evaluates to a sequence yielding the same results as seq { 0; 9; 1; 2 } .



Example
seq { 0; 1; 2 } > Seq.insertManyAt 1 [8; 9]Evaluates to a sequence yielding the same results as seq { 0; 8; 9; 1; 2 } .



Example
[] > Seq.isEmptyEvaluates to true
Example
["pear"; "banana"] > Seq.isEmptyEvaluates to false



Example
let inputs = ["a"; "b"; "c"] inputs > Seq.item 1Evaluates to "b"
Example
let inputs = ["a"; "b"; "c"] inputs > Seq.item 4Throws ArgumentException



Example
["a"; "b"; "c"] > Seq.iter (printfn "%s")Evaluates to unit and prints
a b cin the console. 


Applies the given function to two collections simultaneously. If one sequence is shorter than the other then the remaining elements of the longer sequence are ignored.
Example
let inputs1 = ["a"; "b"; "c"] let inputs2 = [1; 2; 3] (inputs1, inputs2) > Seq.iter2 (printfn "%s: %i")Evaluates to unit and prints
a: 1 b: 2 c: 3in the console. 


Applies the given function to each element of the collection. The integer passed to the function indicates the index of element.
Example
let inputs = ["a"; "b"; "c"] inputs > Seq.iteri (fun i v > printfn "{i}: {v}")Evaluates to unit and prints
0: a 1: b 2: cin the console. 


Applies the given function to two collections simultaneously. If one sequence is shorter than the other then the remaining elements of the longer sequence are ignored. The integer passed to the function indicates the index of element.
Example
let inputs1 = ["a"; "b"; "c"] let inputs2 = ["banana"; "pear"; "apple"] (inputs1, inputs2) > Seq.iteri2 (fun i s1 s2 > printfn "Index {i}: {s1}  {s2}")Evaluates to unit and prints
Index 0: a  banana Index 1: b  pear Index 2: c  applein the console. 

Full Usage:
Seq.last source
Parameters:
seq<'T>

The input sequence.
Returns: 'T
The last element of the sequence.

Example
["pear"; "banana"] > Seq.lastEvaluates to banana
Example
[] > Seq.lastThrows ArgumentException



Example
let inputs = ["a"; "b"; "c"] inputs > Seq.lengthEvaluates to 3



Builds a new collection whose elements are the results of applying the given function
to each of the elements of the collection. The given function will be applied
as elements are demanded using the The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
let inputs = ["a"; "bbb"; "cc"] inputs > Seq.map (fun x > x.Length)Evaluates to a sequence yielding the same results as seq { 1; 3; 2 }



Builds a new collection whose elements are the results of applying the given function to the corresponding pairs of elements from the two sequences. If one input sequence is shorter than the other then the remaining elements of the longer sequence are ignored.
Example
let inputs1 = ["a"; "bad"; "good"] let inputs2 = [0; 2; 1] (inputs1, inputs2) > Seq.map2 (fun x y > x.[y])Evaluates to a sequence yielding the same results as seq { 'a'; 'd'; 'o' }


Full Usage:
Seq.map3 mapping source1 source2 source3
Parameters:
'T1 > 'T2 > 'T3 > 'U

The function to transform triples of elements from the input sequences.
source1 : seq<'T1>

The first input sequence.
source2 : seq<'T2>

The second input sequence.
source3 : seq<'T3>

The third input sequence.
Returns: seq<'U>
The result sequence.

Builds a new collection whose elements are the results of applying the given function to the corresponding triples of elements from the three sequences. If one input sequence if shorter than the others then the remaining elements of the longer sequences are ignored.
Example
let inputs1 = [ "a"; "t"; "ti" ] let inputs2 = [ "l"; "h"; "m" ] let inputs3 = [ "l"; "e"; "e" ] (inputs1, inputs2, inputs3) > Seq.map3 (fun x y z > x + y + z)Evaluates to a sequence yielding the same results as seq { "all"; "the"; "time" }


Full Usage:
Seq.mapFold mapping state source
Parameters:
'State > 'T > 'Result * 'State

The function to transform elements from the input collection and accumulate the final value.
state : 'State

The initial state.
source : seq<'T>

The input collection.
Returns: seq<'Result> * 'State
The collection of transformed elements, and the final accumulated value.

Combines map and fold. Builds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The function is also used to accumulate a final value. This function digests the whole initial sequence as soon as it is called. As a result this function should not be used with large or infinite sequences.
Example
Accumulate the charges, and double them as well type Charge =  In of int  Out of int let inputs = seq { In 1; Out 2; In 3 } let newCharges, balance = (0, inputs) > Seq.mapFold (fun acc charge > match charge with  In i > In (i*2), acc + i  Out o > Out (o*2), acc  o)Evaluates newCharges to seq { In 2; Out 4; In 6 } and balance to 2 .


Full Usage:
Seq.mapFoldBack mapping source state
Parameters:
'T > 'State > 'Result * 'State

The function to transform elements from the input collection and accumulate the final value.
source : seq<'T>

The input collection.
state : 'State

The initial state.
Returns: seq<'Result> * 'State
The collection of transformed elements, and the final accumulated value.

Combines map and foldBack. Builds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The function is also used to accumulate a final value. This function digests the whole initial sequence as soon as it is called. As a result this function should not be used with large or infinite sequences.
ExampleAccumulate the charges from back to front, and double them as well type Charge =  In of int  Out of int let inputs = seq { In 1; Out 2; In 3 } let newCharges, balance = (inputs, 0) > Seq.mapFoldBack (fun charge acc > match charge with  In i > In (i*2), acc + i  Out o > Out (o*2), acc  o)Evaluates newCharges to seq { In 2; Out 4; In 6 } and balance to 2 .



Builds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The integer index passed to the function indicates the index (from 0) of element being transformed.
Example
let inputs = [ 10; 10; 10 ] inputs > Seq.mapi (fun i x > i + x)Evaluates to a sequence yielding the same results as seq { 10; 11; 12 }


Full Usage:
Seq.mapi2 mapping source1 source2
Parameters:
int > 'T1 > 'T2 > 'U

A function to transform pairs of items from the input sequences that also supplies the current index.
source1 : seq<'T1>

The first input sequence.
source2 : seq<'T2>

The second input sequence.
Returns: seq<'U>
The result sequence.

Builds a new collection whose elements are the results of applying the given function to the corresponding pairs of elements from the two sequences. If one input sequence is shorter than the other then the remaining elements of the longer sequence are ignored. The integer index passed to the function indicates the index (from 0) of element being transformed.
Example
let inputs1 = ["a"; "bad"; "good"] let inputs2 = [0; 2; 1] (inputs1, inputs2) > Seq.mapi2 (fun i x y > i, x[y])Evaluates to a sequence yielding the same results as seq { (0, 'a'); (1, 'd'); (2, 'o') }


Full Usage:
Seq.max source
Parameters:
seq<'T>

The input sequence.
Returns: 'T
The largest element of the sequence.
Modifiers: inline Type parameters: 'T 
Example
let inputs = [ 10; 12; 11 ] inputs > Seq.maxEvaluates to 12
Example
let inputs = [ ] inputs > Seq.maxThrows System.ArgumentException .


Full Usage:
Seq.maxBy projection source
Parameters:
'T > 'U

A function to transform items from the input sequence into comparable keys.
source : seq<'T>

The input sequence.
Returns: 'T
The largest element of the sequence.
Modifiers: inline Type parameters: 'T, 'U 
Returns the greatest of all elements of the sequence, compared via Operators.max on the function result.
Example
let inputs = ["aaa"; "b"; "cccc"] inputs > Seq.maxBy (fun s > s.Length)Evaluates to "cccc"
Example
let inputs = [ ] inputs > Seq.maxBy (fun s > s.Length)Throws System.ArgumentException .


Full Usage:
Seq.min source
Parameters:
seq<'T>

The input sequence.
Returns: 'T
The smallest element of the sequence.
Modifiers: inline Type parameters: 'T 
Example
let inputs = [10; 12; 11] inputs > Seq.minEvaluates to 10
Example
let inputs = [] inputs > Seq.minThrows System.ArgumentException .


Full Usage:
Seq.minBy projection source
Parameters:
'T > 'U

A function to transform items from the input sequence into comparable keys.
source : seq<'T>

The input sequence.
Returns: 'T
The smallest element of the sequence.
Modifiers: inline Type parameters: 'T, 'U 
Returns the lowest of all elements of the sequence, compared via Operators.min on the function result.
Example
let inputs = [ "aaa"; "b"; "cccc" ] inputs > Seq.minBy (fun s > s.Length)Evaluates to "b"
Example
let inputs = [] inputs > Seq.minBy (fun (s: string) > s.Length)Throws System.ArgumentException .


Full Usage:
Seq.ofArray source
Parameters:
'T[]

The input array.
Returns: seq<'T>
The result sequence.

Example
let inputs = [ 1; 2; 5 ] inputs > Seq.ofArrayEvaluates to a sequence yielding the same results as seq { 1; 2; 5 } .



Example
let inputs = [ 1; 2; 5 ] inputs > Seq.ofListEvaluates to a sequence yielding the same results as seq { 1; 2; 5 } .



Returns a sequence of each element in the input sequence and its predecessor, with the exception of the first element which is only returned as the predecessor of the second element.
Example
let inputs = seq { 1; 2; 3; 4 } inputs > Seq.pairwiseEvaluates to a sequence yielding the same results as seq { (1, 2); (2, 3); (3, 4) } .



This function consumes the whole input sequence before yielding the first element of the result sequence.
Example
let inputs = [1; 2; 3; 4] inputs > Seq.permute (fun x > (x + 1) % 4)Evaluates to a sequence yielding the same results as seq { 4; 1; 2; 3 } .



Applies the given function to successive elements, returning the first
Example
let input = [1; 2; 3] input > Seq.pick (fun n > if n % 2 = 0 then Some (string n) else None)Evaluates to "2" .
Example
let input = [1; 2; 3] input > Seq.pick (fun n > if n > 3 = 0 then Some (string n) else None)Throws KeyNotFoundException .



Builds a new sequence object that delegates to the given sequence object. This ensures the original sequence cannot be rediscovered and mutated by a type cast. For example, if given an array the returned sequence will return the elements of the array, but you cannot cast the returned sequence object to an array.
Example
let input = [ 1; 2; 3 ] input > Seq.readonlyEvaluates to a sequence yielding the same results as seq { 1; 2; 3 } .
Example
let input = [ 1; 2; 3 ] let readonlyView = input > Seq.readonly (readonlyView :?> int[]).[1] < 4Throws an InvalidCastException .


Full Usage:
Seq.reduce reduction source
Parameters:
'T > 'T > 'T

A function that takes in the current accumulated result and the next
element of the sequence to produce the next accumulated result.
source : seq<'T>

The input sequence.
Returns: 'T
The final result of the reduction function.

Applies a function to each element of the sequence, threading an accumulator argument through the computation. Begin by applying the function to the first two elements. Then feed this result into the function along with the third element and so on. Return the final result.
Example
let inputs = [1; 3; 4; 2] inputs > Seq.reduce (fun a b > a * 10 + b)Evaluates to 1342 , by computing ((1 * 10 + 3) * 10 + 4) * 10 + 2


Full Usage:
Seq.reduceBack reduction source
Parameters:
'T > 'T > 'T

A function that takes in the nexttolast element of the sequence and the
current accumulated result to produce the next accumulated result.
source : seq<'T>

The input sequence.
Returns: 'T
The final result of the reductions.

Applies a function to each element of the sequence, starting from the end, threading an accumulator argument
through the computation. If the input function is This function consumes the whole input sequence before returning the result.
Example
let inputs = [1; 3; 4; 2] inputs > Seq.reduceBack (fun a b > a + b * 10)Evaluates to 2431 , by computing 1 + (3 + (4 + 2 * 10) * 10) * 10



Example
seq { 0; 1; 2 } > Seq.removeAt 1Evaluates to a sequence yielding the same results as seq { 0; 2 } .



Example
seq { 0; 1; 2; 3 } > Seq.removeManyAt 1 2Evaluates to a sequence yielding the same results as seq { 0; 3 } .



Example
Seq.replicate 3 "a"Evaluates to a sequence yielding the same results as seq { "a"; "a"; "a" } .



This function consumes the whole input sequence before yielding the first element of the reversed sequence.
Example
let input = seq { 0; 1; 2 } input > Seq.revEvaluates to a sequence yielding the same results as seq { 2; 1; 0 } .



ExampleApply a list charges and collect the running balances as each is applied: type Charge =  In of int  Out of int let inputs = seq { In 1; Out 2; In 3 } (0, inputs) > Seq.scan (fun acc charge > match charge with  In i > acc + i  Out o > acc  o)Evaluates to a sequence yielding the same results as seq { 0; 1; 1; 2 } . Note 0 is the intial
state, 1 the next state, 1 the next state, and 2 the final state.


Full Usage:
Seq.scanBack folder source state
Parameters:
'T > 'State > 'State

A function that updates the state with each element from the sequence.
source : seq<'T>

The input sequence.
state : 'State

The initial state.
Returns: seq<'State>
The resulting sequence of computed states.

This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences.
ExampleApply a list charges from back to front, and collect the running balances as each is applied: type Charge =  In of int  Out of int let inputs = [ In 1; Out 2; In 3 ] (inputs, 0) > Seq.scanBack (fun charge acc > match charge with  In i > acc + i  Out o > acc  o)Evaluates to a sequence yielding the same results as seq { 2; 1; 3; 0 } by processing each input from back to front. Note 0 is the intial
state, 3 the next state, 1 the next state, and 2 the final state, and the states
are produced from back to front.


Full Usage:
Seq.singleton value
Parameters:
'T

The input item.
Returns: seq<'T>
The result sequence of one item.

Example
Seq.singleton 7Evaluates to a sequence yielding the same results as seq { 7 } .



Returns a sequence that skips N elements of the underlying sequence and then yields the remaining elements of the sequence.
Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.skip 2Evaluates a sequence yielding the same results as seq { "c"; "d" }
Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.skip 5Throws ArgumentException .
Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.skip 1Evaluates a sequence yielding the same results as seq { "a"; "b"; "c"; "d" } .



Returns a sequence that, when iterated, skips elements of the underlying sequence while the given predicate returns True, and then yields the remaining elements of the sequence.
Example
let inputs = seq { "a"; "bbb"; "cc"; "d" } inputs > Seq.skipWhile (fun x > x.Length < 3)Evaluates a sequence yielding the same results as seq { "bbb"; "cc"; "d" }



This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences. The function makes no assumption on the ordering of the original sequence and uses a stable sort, that is the original order of equal elements is preserved.
Example
let input = seq { 8; 4; 3; 1; 6; 1 } Seq.sort inputEvaluates to a sequence yielding the same results as seq { 1; 1 3; 4; 6; 8 } .



Applies a keygenerating function to each element of a sequence and yield a sequence ordered by keys. The keys are compared using generic comparison as implemented by Operators.compare. This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences. The function makes no assumption on the ordering of the original sequence and uses a stable sort, that is the original order of equal elements is preserved.
Example
let input = [ "a"; "bbb"; "cccc"; "dd" ] input > Seq.sortBy (fun s > s.Length)Evaluates to a sequence yielding the same results as seq { "a"; "dd"; "bbb"; "cccc" } .



Applies a keygenerating function to each element of a sequence and yield a sequence ordered descending by keys. The keys are compared using generic comparison as implemented by Operators.compare. This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences. The function makes no assumption on the ordering of the original sequence. This is a stable sort, that is the original order of equal elements is preserved.
Example
let input = ["a"; "bbb"; "cccc"; "dd"] input > Seq.sortByDescending (fun s > s.Length)Evaluates to a sequence yielding the same results as seq { "cccc"; "bbb"; "dd"; "a" } .



This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences. The function makes no assumption on the ordering of the original sequence. This is a stable sort, that is the original order of equal elements is preserved.
Example
let input = seq { 8; 4; 3; 1; 6; 1 } input > Seq.sortDescendingEvaluates to a sequence yielding the same results as seq { 8; 6; 4; 3; 1; 1 } .



This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences. The function makes no assumption on the ordering of the original sequence and uses a stable sort, that is the original order of equal elements is preserved.
ExampleSort a sequence of pairs using a comparison function that compares string lengths then index numbers: let compareEntries (n1: int, s1: string) (n2: int, s2: string) = let c = compare s1.Length s2.Length if c <> 0 then c else compare n1 n2 let input = [ (0,"aa"); (1,"bbb"); (2,"cc"); (3,"dd") ] input > Seq.sortWith compareEntriesEvaluates to a sequence yielding the same results as seq { (0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb") } .



This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences.This function consumes the whole input sequence before yielding the first element of the result sequence.
Example
let inputs = [1; 2; 3; 4; 5] inputs > Seq.splitInto 3Evaluates to a sequence yielding the same results as seq { [1; 2]; [3; 4]; [5] }
Example
let inputs = [1; 2; 3; 4; 5] inputs > Seq.splitInto 1Throws ArgumentException


Full Usage:
Seq.sum source
Parameters:
seq<^T>

The input sequence.
Returns: ^T
The computed sum.
Modifiers: inline Type parameters: ^T 
The elements are summed using the
Example
let input = [ 1; 5; 3; 2 ] input > Seq.sumEvaluates to 11 .


Full Usage:
Seq.sumBy projection source
Parameters:
'T > ^U

A function to transform items from the input sequence into the type that will be summed.
source : seq<'T>

The input sequence.
Returns: ^U
The computed sum.
Modifiers: inline Type parameters: 'T, ^U 
The generated elements are summed using the
Example
let input = [ "aa"; "bbb"; "cc" ] input > Seq.sumBy (fun s > s.Length)Evaluates to 7 .



Returns a sequence that skips 1 element of the underlying sequence and then yields the remaining elements of the sequence.
Example
let inputs = ["a"; "bb"; "ccc"] inputs > Seq.tailEvaluates to a sequence yielding the same results as seq { "bb"; "ccc" }



Throws
Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.take 2Evaluates to a sequence yielding the same results as ["a"; "b"]
Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.take 6Throws InvalidOperationException .
Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.take 0Evaluates to a sequence yielding no results. 


Returns a sequence that, when iterated, yields elements of the underlying sequence while the given predicate returns True, and then returns no further elements.
Example
let inputs = ["a"; "bb"; "ccc"; "d"] inputs > Seq.takeWhile (fun x > x.Length < 3)Evaluates to a sequence yielding the same results as seq { "a"; "bb" }


Full Usage:
Seq.toArray source
Parameters:
seq<'T>

The input sequence.
Returns: 'T[]
The result array.

Example
let inputs = seq { 1; 2; 5 } inputs > Seq.toArrayEvaluates to [ 1; 2; 5 ] .



Example
let inputs = seq { 1; 2; 5 } inputs > Seq.toListEvaluates to [ 1; 2; 5 ] .



This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences.
Example
let inputs = [ [ 10; 20; 30 ] [ 11; 21; 31 ] ] inputs > Seq.transposeEvaluates to a sequence of sequences yielding the same results as [ [10; 11]; [20; 21]; [30; 31] ] .



Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.truncate 2Evaluates to a sequence yielding the same results as seq { "a"; "b" }
Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.truncate 6Evaluates to a sequence yielding the same results as seq { "a"; "b"; "c"; "d" }
Example
let inputs = ["a"; "b"; "c"; "d"] inputs > Seq.truncate 0Evaluates to the empty sequence. 


Returns the only element of the sequence or
Example
let inputs = ["banana"] inputs > Seq.tryExactlyOneEvaluates to Some banana
Example
let inputs = ["pear"; "banana"] inputs > Seq.tryExactlyOneEvaluates to None
Example
[] > Seq.tryExactlyOneEvaluates to None



Returns the first element for which the given function returns True. Return None if no such element exists.
ExampleTry to find the first even number: let inputs = [1; 2; 3] inputs > Seq.tryFind (fun elm > elm % 2 = 0)Evaluates to Some 2
ExampleTry to find the first even number: let inputs = [1; 5; 3] inputs > Seq.tryFind (fun elm > elm % 2 = 0)Evaluates to None



Returns the last element for which the given function returns True. Return None if no such element exists. This function digests the whole initial sequence as soon as it is called. As a result this function should not be used with large or infinite sequences.
ExampleTry to find the first even number from the back: let inputs = [1; 2; 3; 4; 5] inputs > Seq.tryFindBack (fun elm > elm % 2 = 0)Evaluates to Some 4
ExampleTry to find the first even number from the back: let inputs = [1; 5; 3] inputs > Seq.tryFindBack (fun elm > elm % 2 = 0)Evaluates to None



Returns the index of the first element in the sequence
that satisfies the given predicate. Return
ExampleTry to find the index of the first even number: let inputs = [1; 2; 3; 4; 5] inputs > Seq.tryFindIndex (fun elm > elm % 2 = 0)Evaluates to Some 1
ExampleTry to find the index of the first even number: let inputs = [1; 3; 5; 7] inputs > Seq.tryFindIndex (fun elm > elm % 2 = 0)Evaluates to None



Returns the index of the last element in the sequence
that satisfies the given predicate. Return This function digests the whole initial sequence as soon as it is called. As a result this function should not be used with large or infinite sequences.
ExampleTry to find the index of the first even number from the back: let inputs = [1; 2; 3; 4; 5] inputs > Seq.tryFindIndexBack (fun elm > elm % 2 = 0)Evaluates to Some 3
ExampleTry to find the index of the first even number from the back: let inputs = [1; 3; 5; 7] inputs > Seq.tryFindIndexBack (fun elm > elm % 2 = 0)Evaluates to None



Example
["banana"; "pear"] > Seq.tryHeadEvaluates to Some "banana"
Example
[] > Seq.tryHeadEvaluates to None



Tries to find the nth element in the sequence.
Returns
Example
let inputs = ["a"; "b"; "c"] inputs > Seq.tryItem 1Evaluates to Some "b" .
Example
let inputs = ["a"; "b"; "c"] inputs > Seq.tryItem 4Evaluates to None .



Example
["pear"; "banana"] > Seq.tryLastEvaluates to Some "banana"
Example
[] > Seq.tryLastEvaluates to None



Applies the given function to successive elements, returning the first result where the function returns "Some(x)".
Example
let input = [1; 2; 3] input > Seq.tryPick (fun n > if n % 2 = 0 then Some (string n) else None)Evaluates to Some "2" .
Example
let input = [1; 2; 3] input > Seq.tryPick (fun n > if n > 3 = 0 then Some (string n) else None)Evaluates to None .


Full Usage:
Seq.unfold generator state
Parameters:
'State > ('T * 'State) option

A function that takes in the current state and returns an option tuple of the next
element of the sequence and the next state value.
state : 'State

The initial state value.
Returns: seq<'T>
The result sequence.

Returns a sequence that contains the elements generated by the given computation.
The given initial The stream will be recomputed each time an IEnumerator is requested and iterated for the Seq.
Example
1 > Seq.unfold (fun state > if state > 100 then None else Some (state, state * 2))Evaluates to a sequence yielding the same results as seq { 1; 2; 4; 8; 16; 32; 64 }
Example
1I > Seq.unfold (fun state > Some (state, state * 2I))Evaluates to an infinite sequence yielding the results seq { 1I; 2I; 4I; 8I; ... }



Example
seq { 0; 1; 2 } > Seq.updateAt 1 9Evaluates to a sequence yielding the same results as seq { 0; 9; 2 } .



Returns a new collection containing only the elements of the collection for which the given predicate returns "true". The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently. Remember sequence is lazy, effects are delayed until it is enumerated. A synonym for Seq.filter.
Example
[1; 2; 3; 4] > Seq.where (fun elm > elm % 2 = 0)Evaluates to a sequence yielding the same results as seq { 2; 4 }



Returns a sequence yielding sliding windows containing elements drawn from the input sequence. Each window is returned as a fresh array.
Example
let inputs = [1; 2; 3; 4; 5] inputs > Seq.windowed 3Evaluates to a sequence of arrays yielding the results seq { [ 1; 2; 3 ]; [ 2; 3; 4 ]; [ 3; 4; 5 ] }



Combines the two sequences into a sequence of pairs. The two sequences need not have equal lengths: when one sequence is exhausted any remaining elements in the other sequence are ignored.
Example
let numbers = [1; 2] let names = ["one"; "two"] Seq.zip numbers namesEvaluates to a sequence yielding the same results as seq { (1, "one"); (2, "two") } .



Combines the three sequences into a sequence of triples. The sequences need not have equal lengths: when one sequence is exhausted any remaining elements in the other sequences are ignored.
Example
let numbers = [1; 2] let names = ["one"; "two"] let roman = ["I"; "II"] Seq.zip3 numbers names romanEvaluates to a sequence yielding the same results as seq { (1, "one", "I"); (2, "two", "II") } .
