Returns a new sequence that contains all pairings of elements from the first and second sequences.
'T1 seq
The first sequence.
'T2 seq
The second sequence.
('T1 * 'T2) seq
The result sequence.
([1; 2], [3; 4]) ||> Seq.allPairs
module Seq from Microsoft.FSharp.Collections
val allPairs: source1: 'T1 seq -> source2: 'T2 seq -> ('T1 * 'T2) seq
Evaluates to a sequence yielding the same results as seq { (1, 3); (1, 4); (2, 3); (2, 4) }
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
Wraps the two given enumerations as a single concatenated enumeration.
'T seq
The first sequence.
'T seq
The second sequence.
'T seq
The result sequence.
Seq.append [1; 2] [3; 4]
module Seq from Microsoft.FSharp.Collections
val append: source1: 'T seq -> source2: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 1; 2; 3; 4 }
Returns the average of the elements in the sequence.
^T seq
The input sequence.
^T
The average.
[1.0; 2.0; 3.0] |> Seq.average
module Seq from Microsoft.FSharp.Collections
val average: source: 'T seq -> 'T (requires member (+) and member DivideByInt and member Zero)
Evaluates to2.0
[] |> Seq.average
module Seq from Microsoft.FSharp.Collections
val average: source: 'T seq -> 'T (requires member (+) and member DivideByInt and member Zero)
ThrowsArgumentException
Returns the average of the results generated by applying the function to each element of the sequence.
'T -> ^U
A function applied to transform each element of the sequence.
'T seq
The input sequence.
^U
The average.
type Foo = { Bar: float }
let input = seq { {Bar = 2.0}; {Bar = 4.0} }
input |> Seq.averageBy (fun foo -> foo.Bar)
type Foo = { Bar: float }
Multiple items
val float: value: 'T -> float (requires member op_Explicit)
--------------------
type float = System.Double
--------------------
type float<'Measure> = float
val input: Foo seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val averageBy: projection: ('T -> 'U) -> source: 'T seq -> 'U (requires member (+) and member DivideByInt and member Zero)
val foo: Foo
Foo.Bar: float
Evaluates to3.0
type Foo = { Bar: float }
Seq.empty |> Seq.averageBy (fun (foo: Foo) -> foo.Bar)
type Foo = { Bar: float }
Multiple items
val float: value: 'T -> float (requires member op_Explicit)
--------------------
type float = System.Double
--------------------
type float<'Measure> = float
module Seq from Microsoft.FSharp.Collections
val empty<'T> : 'T seq
val averageBy: projection: ('T -> 'U) -> source: 'T seq -> 'U (requires member (+) and member DivideByInt and member Zero)
val foo: Foo
Foo.Bar: float
ThrowsArgumentException
Returns a sequence that corresponds to a cached version of the input sequence.
'T seq
The input sequence.
'T seq
The result sequence.
let fibSeq =(0, 1) |> Seq.unfold (fun (a,b) -> Some(a + b, (b, a + b)))
let fibSeq3 = fibSeq |> Seq.take 3 |> Seq.cache
fibSeq3
val fibSeq: int seq
module Seq from Microsoft.FSharp.Collections
val unfold: generator: ('State -> ('T * 'State) option) -> state: 'State -> 'T seq
val a: int
val b: int
union case Option.Some: Value: 'T -> Option<'T>
val fibSeq3: int seq
val take: count: int -> source: 'T seq -> 'T seq
val cache: source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 1; 2; 3 }
, and it will not do the calculation again when called.
Wraps a loosely-typed System.Collections sequence as a typed sequence.
IEnumerable
The input sequence.
'T seq
The result sequence.
[box 1; box 2; box 3] |> Seq.cast<int>
val box: value: 'T -> obj
module Seq from Microsoft.FSharp.Collections
val cast: source: System.Collections.IEnumerable -> 'T seq
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
Evaluates to a sequence yielding the same results asseq { 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).
'T -> 'U option
A function to transform items of type T into options of type U.
'T seq
The input sequence of type T.
'U seq
The result sequence.
[Some 1; None; Some 2] |> Seq.choose id
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
module Seq from Microsoft.FSharp.Collections
val choose: chooser: ('T -> 'U option) -> source: 'T seq -> 'U seq
val id: x: 'T -> 'T
Evaluates to a sequence yielding the same results asseq { 1; 2 }
[1; 2; 3] |> Seq.choose (fun n -> if n % 2 = 0 then Some n else None)
module Seq from Microsoft.FSharp.Collections
val choose: chooser: ('T -> 'U option) -> source: 'T seq -> 'U seq
val n: int
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
Evaluates to a sequence yielding the same results asseq { 2 }
Divides the input sequence into chunks of size at most chunkSize
.
int
The maximum size of each chunk.
'T seq
The input sequence.
'T array seq
The sequence divided into chunks.
[1; 2; 3] |> Seq.chunkBySize 2
module Seq from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> source: 'T seq -> 'T array seq
Evaluates to a sequence yielding the same results asseq { [|1; 2|]; [|3|] }
[1; 2; 3] |> Seq.chunkBySize -2
module Seq from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> source: 'T seq -> 'T array seq
ThrowsArgumentException
Applies the given function to each element of the sequence and concatenates all the results.
'T -> 'Collection
A function to transform elements of the input sequence into the sequences that will then be concatenated.
'T seq
The input sequence.
'U seq
The result sequence.
type Foo = { Bar: int seq }
let input = seq { {Bar = [1; 2]}; {Bar = [3; 4]} }
input |> Seq.collect (fun foo -> foo.Bar)
type Foo = { Bar: int seq }
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
val input: Foo seq
module Seq from Microsoft.FSharp.Collections
val collect: mapping: ('T -> #('U seq)) -> source: 'T seq -> 'U seq
val foo: Foo
Foo.Bar: int seq
Evaluates to a sequence yielding the same results asseq { 1; 2; 3; 4 }
let input = [[1; 2]; [3; 4]]
input |> Seq.collect id
val input: int list list
module Seq from Microsoft.FSharp.Collections
val collect: mapping: ('T -> #('U seq)) -> source: 'T seq -> 'U seq
val id: x: 'T -> 'T
Evaluates to a sequence yielding the same results asseq { 1; 2; 3; 4 }
Compares two sequences using the given comparison function, element by element.
'T -> 'T -> int
A function that takes an element from each sequence and returns an int. If it evaluates to a non-zero value iteration is stopped and that value is returned.
'T seq
The first input sequence.
'T seq
The second input sequence.
int
Returns the first non-zero 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.
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [1; 10]
let input2 = [1; 10]
(input1, input2) ||> Seq.compareWith closerToNextDozen
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
module Seq from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> source1: 'T seq -> source2: 'T seq -> int
Evaluates to0
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [1; 5]
let input2 = [1; 8]
(input1, input2) ||> Seq.compareWith closerToNextDozen
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
module Seq from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> source1: 'T seq -> source2: 'T seq -> int
Evaluates to-1
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [1; 11]
let input2 = [1; 13]
(input1, input2) ||> Seq.compareWith closerToNextDozen
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
module Seq from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> source1: 'T seq -> source2: 'T seq -> int
Evaluates to1
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [1; 2]
let input2 = [1]
(input1, input2) ||> Seq.compareWith closerToNextDozen
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
module Seq from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> source1: 'T seq -> source2: 'T seq -> int
Evaluates to1
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [1]
let input2 = [1; 2]
(input1, input2) ||> Seq.compareWith closerToNextDozen
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
module Seq from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> source1: 'T seq -> source2: 'T seq -> int
Evaluates to-1
Combines the given enumeration-of-enumerations as a single concatenated enumeration.
'Collection seq
The input enumeration-of-enumerations.
'T seq
The result sequence.
let inputs = [[1; 2]; [3]; [4; 5]]
inputs |> Seq.concat
val inputs: int list list
module Seq from Microsoft.FSharp.Collections
val concat: sources: #('T seq) seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 1; 2; 3; 4; 5 }
Tests if the sequence contains the specified element.
'T
The value to locate in the input sequence.
'T seq
The input sequence.
bool
True if the input sequence contains the specified element; false otherwise.
[1; 2] |> Seq.contains 2 // evaluates to true
[1; 2] |> Seq.contains 5 // evaluates to false
module Seq from Microsoft.FSharp.Collections
val contains: value: 'T -> source: 'T seq -> bool (requires equality)
Applies a key-generating function to each element of a sequence and returns a sequence yielding unique keys and their number of occurrences in the original sequence.
'T -> 'Key
A function transforming each item of the input sequence into a key to be compared against the others.
'T seq
The input sequence.
('Key * int) seq
The result sequence.
type Foo = { Bar: string }
let inputs = [{Bar = "a"}; {Bar = "b"}; {Bar = "a"}]
inputs |> Seq.countBy (fun foo -> foo.Bar)
type Foo = { Bar: string }
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
val inputs: Foo list
module Seq from Microsoft.FSharp.Collections
val countBy: projection: ('T -> 'Key) -> source: 'T seq -> ('Key * int) seq (requires equality)
val foo: Foo
Foo.Bar: string
Evaluates to a sequence yielding the same results asseq { ("a", 2); ("b", 1) }
Returns a sequence that is built from the given delayed specification of a sequence.
unit -> 'T seq
The generating function for the sequence.
'T seq
The result sequence.
Seq.delay (fun () -> Seq.ofList [1; 2; 3])
module Seq from Microsoft.FSharp.Collections
val delay: generator: (unit -> 'T seq) -> 'T seq
val ofList: source: 'T list -> 'T seq
Evaluates to a sequence yielding the same results asseq { 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.
'T seq
The input sequence.
'T seq
The result sequence.
[1; 1; 2; 3] |> Seq.distinct
module Seq from Microsoft.FSharp.Collections
val distinct: source: 'T seq -> 'T seq (requires equality)
Evaluates to a sequence yielding the same results asseq { 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 key-generating function. If an element occurs multiple times in the sequence then the later occurrences are discarded.
'T -> 'Key
A function transforming the sequence items into comparable keys.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = [{Bar = 1 };{Bar = 1}; {Bar = 2}; {Bar = 3}]
inputs |> Seq.distinctBy (fun foo -> foo.Bar)
val inputs: 'a list
module Seq from Microsoft.FSharp.Collections
val distinctBy: projection: ('T -> 'Key) -> source: 'T seq -> 'T seq (requires equality)
val foo: obj
Evaluates to a sequence yielding the same results asseq { { Bar = 1 }; { Bar = 2 }; { Bar = 3 } }
Creates an empty sequence.
'T seq
An empty sequence.
Seq.empty // Evaluates to seq { }
module Seq from Microsoft.FSharp.Collections
val empty<'T> : 'T seq
Returns the only element of the sequence.
'T seq
The input sequence.
'T
The only element of the sequence.
let inputs = ["banana"]
inputs |> Seq.exactlyOne
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val exactlyOne: source: 'T seq -> 'T
Evaluates tobanana
let inputs = ["pear"; "banana"]
inputs |> Seq.exactlyOne
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val exactlyOne: source: 'T seq -> 'T
ThrowsArgumentException
[] |> Seq.exactlyOne
module Seq from Microsoft.FSharp.Collections
val exactlyOne: source: 'T seq -> 'T
ThrowsArgumentException
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.
'T seq
A sequence whose elements that also occur in the second sequence will cause those elements to be removed from the returned sequence.
'T seq
A sequence whose elements that are not also in first will be returned.
'T seq
A sequence that contains the set difference of the elements of two sequences.
let original = [1; 2; 3; 4; 5]
let itemsToExclude = [1; 3; 5]
original |> Seq.except itemsToExclude
val original: int list
val itemsToExclude: int list
module Seq from Microsoft.FSharp.Collections
val except: itemsToExclude: 'T seq -> source: 'T seq -> 'T seq (requires equality)
Evaluates to a sequence yielding the same results asseq { 2; 4 }
Tests if any element of the sequence satisfies the given predicate.
'T -> bool
A function to test each item of the input sequence.
'T seq
The input sequence.
bool
True if any result from the predicate is true; false otherwise.
let input = [1; 2; 3; 4; 5]
input |> Seq.exists (fun elm -> elm % 4 = 0)
val input: int list
module Seq from Microsoft.FSharp.Collections
val exists: predicate: ('T -> bool) -> source: 'T seq -> bool
val elm: int
Evaluates totrue
let input = [1; 2; 3; 4; 5]
input |> Seq.exists (fun elm -> elm % 6 = 0)
val input: int list
module Seq from Microsoft.FSharp.Collections
val exists: predicate: ('T -> bool) -> source: 'T seq -> bool
val elm: int
Evaluates tofalse
Tests if any pair of corresponding elements of the input sequences satisfies the given predicate.
'T1 -> 'T2 -> bool
A function to test each pair of items from the input sequences.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
bool
True if any result from the predicate is true; false otherwise.
let inputs1 = [1; 2]
let inputs2 = [1; 2; 0]
(inputs1, inputs2) ||> Seq.exists2 (fun a b -> a > b)
val inputs1: int list
val inputs2: int list
module Seq from Microsoft.FSharp.Collections
val exists2: predicate: ('T1 -> 'T2 -> bool) -> source1: 'T1 seq -> source2: 'T2 seq -> bool
val a: int
val b: int
Evaluates tofalse
let inputs1 = [1; 4]
let inputs2 = [1; 3; 5]
(inputs1, inputs2) ||> Seq.exists2 (fun a b -> a > b)
val inputs1: int list
val inputs2: int list
module Seq from Microsoft.FSharp.Collections
val exists2: predicate: ('T1 -> 'T2 -> bool) -> source1: 'T1 seq -> source2: 'T2 seq -> bool
val a: int
val b: int
Evaluates totrue
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.
'T -> bool
A function to test whether each item in the input sequence should be included in the output.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = [1; 2; 3; 4]
inputs |> Seq.filter (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val filter: predicate: ('T -> bool) -> source: 'T seq -> 'T seq
val elm: int
Evaluates to a sequence yielding the same results asseq { 2; 4 }
Returns the first element for which the given function returns True.
'T -> bool
A function to test whether an item in the sequence should be returned.
'T seq
The input sequence.
'T
The first element for which the predicate returns True.
let inputs = [1; 2; 3]
inputs |> Seq.find (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> source: 'T seq -> 'T
val elm: int
Evaluates to2
let inputs = [1; 2; 3]
inputs |> Seq.find (fun elm -> elm % 6 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> source: 'T seq -> 'T
val elm: int
ThrowsKeyNotFoundException
Returns the last element for which the given function returns True.
'T -> bool
A function to test whether an item in the sequence should be returned.
'T seq
The input sequence.
'T
The last element for which the predicate returns True.
let inputs = [2; 3; 4]
inputs |> Seq.findBack (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> source: 'T seq -> 'T
val elm: int
Evaluates to4
let inputs = [2; 3; 4]
inputs |> Seq.findBack (fun elm -> elm % 6 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> source: 'T seq -> 'T
val elm: int
ThrowsKeyNotFoundException
Returns the index of the first element for which the given function returns True.
'T -> bool
A function to test whether the index of a particular element should be returned.
'T seq
The input sequence.
int
The index of the first element for which the predicate returns True.
let inputs = [1; 2; 3; 4; 5]
inputs |> Seq.findIndex (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> source: 'T seq -> int
val elm: int
Evaluates to1
let inputs = [1; 2; 3; 4; 5]
inputs |> Seq.findIndex (fun elm -> elm % 6 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> source: 'T seq -> int
val elm: int
ThrowsKeyNotFoundException
Returns the index of the last element for which the given function returns True.
'T -> bool
A function to test whether the index of a particular element should be returned.
'T seq
The input sequence.
int
The index of the last element for which the predicate returns True.
let input = [1; 2; 3; 4; 5]
input |> Seq.findIndex (fun elm -> elm % 2 = 0)
val input: int list
module Seq from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> source: 'T seq -> int
val elm: int
Evaluates to3
let input = [1; 2; 3; 4; 5]
input |> Seq.findIndex (fun elm -> elm % 6 = 0)
val input: int list
module Seq from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> source: 'T seq -> int
val elm: int
ThrowsKeyNotFoundException
Applies a function to each element of the collection, threading an accumulator argument through the computation. If the input function is f
and the elements are i0...iN
then computes f (... (f s i0)...) iN
'State -> 'T -> 'State
A function that updates the state with each element from the sequence.
'State
The initial state.
'T seq
The input sequence.
'State
The state object after the folding function is applied to each element of the sequence.
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)
type Charge = | In of int | Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
val inputs: Charge list
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
module Seq from Microsoft.FSharp.Collections
val fold<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> source: 'T seq -> 'State
val acc: int
val charge: Charge
val i: int
val o: int
Evaluates to2
Applies a function to corresponding elements of two collections, threading an accumulator argument through the computation.
'State -> 'T1 -> 'T2 -> 'State
The function to update the state given the input elements.
'State
The initial state.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
'State
The final state value.
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)
type CoinToss = | Head | Tails
val data1: CoinToss list
union case CoinToss.Tails: CoinToss
union case CoinToss.Head: CoinToss
val data2: CoinToss list
module Seq from Microsoft.FSharp.Collections
val fold2<'T1,'T2,'State> : folder: ('State -> 'T1 -> 'T2 -> 'State) -> state: 'State -> source1: 'T1 seq -> source2: 'T2 seq -> 'State
val acc: int
val a: CoinToss
val b: CoinToss
Evaluates to1
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 f
and the elements are i0...iN
then computes f i0 (... (f iN s)...)
'T -> 'State -> 'State
The function to update the state given the input elements.
'T seq
The input sequence.
'State
The initial state.
'State
The state object after the folding function is applied to each element of the sequence.
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 })
type Count = { Positive: int Negative: int Text: string }
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
val sequence: int list
val initialState: Count
module Seq from Microsoft.FSharp.Collections
val foldBack: folder: ('T -> 'State -> 'State) -> source: 'T seq -> state: 'State -> 'State
val a: int
val acc: Count
val text: string
Count.Text: string
Count.Positive: int
Count.Negative: int
Evaluates to { Positive = 2
Negative = 3
Text = " 3 -2 -1 0 1" }
namespace Microsoft.FSharp.Text
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 f
and the elements are i0...iN
and j0...jM
, N < M then computes f i0 j0 (... (f iN jN s)...)
.
'T1 -> 'T2 -> 'State -> 'State
The function to update the state given the input elements.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
'State
The initial state.
'State
The final state value.
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 }
)
type Count = { Positive: int Negative: int Text: string }
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
val inputs1: int list
val inputs2: int list
val initialState: Count
module Seq from Microsoft.FSharp.Collections
val foldBack2: folder: ('T1 -> 'T2 -> 'State -> 'State) -> source1: 'T1 seq -> source2: 'T2 seq -> state: 'State -> 'State
val a: int
val b: int
val acc: Count
val text: string
Count.Text: string
Count.Positive: int
Count.Negative: int
Evaluates to { Positive = 2
Negative = 1
Text = " (-3,1) (-2,2) (-1,3)" }
namespace Microsoft.FSharp.Text
Tests if all elements of the sequence satisfy the given predicate.
'T -> bool
A function to test an element of the input sequence.
'T seq
The input sequence.
bool
True if every element of the sequence satisfies the predicate; false otherwise.
let isEven a = a % 2 = 0
[2; 42] |> Seq.forall isEven // evaluates to true
[1; 2] |> Seq.forall isEven // evaluates to false
val isEven: a: int -> bool
val a: int
module Seq from Microsoft.FSharp.Collections
val forall: predicate: ('T -> bool) -> source: 'T seq -> bool
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.
'T1 -> 'T2 -> bool
A function to test pairs of elements from the input sequences.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
bool
True if all pairs satisfy the predicate; false otherwise.
let inputs1 = [1; 2; 3; 4; 5; 6]
let inputs2 = [1; 2; 3; 4; 5]
(inputs1, inputs2) ||> Seq.forall2 (=)
val inputs1: int list
val inputs2: int list
module Seq from Microsoft.FSharp.Collections
val forall2: predicate: ('T1 -> 'T2 -> bool) -> source1: 'T1 seq -> source2: 'T2 seq -> bool
Evaluates totrue
.
let items1 = [2017; 1; 1]
let items2 = [2019; 19; 8]
(items1, items2) ||> Seq.forall2 (=)
val items1: int list
val items2: int list
module Seq from Microsoft.FSharp.Collections
val forall2: predicate: ('T1 -> 'T2 -> bool) -> source1: 'T1 seq -> source2: 'T2 seq -> bool
Evaluates tofalse
.
Applies a key-generating 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.
'T -> 'Key
A function that transforms an element of the sequence into a comparable key.
'T seq
The input sequence.
('Key * 'T seq) seq
The result sequence.
let inputs = [1; 2; 3; 4; 5]
inputs |> Seq.groupBy (fun n -> n % 2)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val groupBy: projection: ('T -> 'Key) -> source: 'T seq -> ('Key * 'T seq) seq (requires equality)
val n: int
Evaluates to a sequence yielding the same results asseq { (1, seq { 1; 3; 5 }); (0, seq { 2; 4 }) }
Returns the first element of the sequence.
'T seq
The input sequence.
'T
The first element of the sequence.
let inputs = ["banana"; "pear"]
inputs |> Seq.head
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val head: source: 'T seq -> 'T
Evaluates tobanana
[] |> Seq.head
module Seq from Microsoft.FSharp.Collections
val head: source: 'T seq -> 'T
ThrowsArgumentException
Builds a new collection whose elements are the corresponding elements of the input collection paired with the integer index (from 0) of each element.
'T seq
The input sequence.
(int * 'T) seq
The result sequence.
["a"; "b"; "c"] |> Seq.indexed
module Seq from Microsoft.FSharp.Collections
val indexed: source: 'T seq -> (int * 'T) seq
Evaluates to a sequence yielding the same results asseq { (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.
int
The maximum number of items to generate for the sequence.
int -> 'T
A function that generates an item in the sequence from a given index.
'T seq
The result sequence.
Seq.init 4 (fun v -> v + 5)
module Seq from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T seq
val v: int
Evaluates to a sequence yielding the same results asseq { 5; 6; 7; 8 }
Seq.init -5 (fun v -> v + 5)
module Seq from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T seq
val v: int
ThrowsArgumentException
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.
int -> 'T
A function that generates an item in the sequence from a given index.
'T seq
The result sequence.
(+) 5 |> Seq.initInfinite
module Seq from Microsoft.FSharp.Collections
val initInfinite: initializer: (int -> 'T) -> 'T seq
Evaluates to a sequence yielding the same results asseq { 5; 6; 7; 8; ... }
Return a new sequence with a new item inserted before the given index.
int
The index where the item should be inserted.
'T
The value to insert.
'T seq
The input sequence.
'T seq
The result sequence.
seq { 0; 1; 2 } |> Seq.insertAt 1 9
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val insertAt: index: int -> value: 'T -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 0; 9; 1; 2 }
.
Return a new sequence with new items inserted before the given index.
int
The index where the items should be inserted.
'T seq
The values to insert.
'T seq
The input sequence.
'T seq
The result sequence.
seq { 0; 1; 2 } |> Seq.insertManyAt 1 [8; 9]
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val insertManyAt: index: int -> values: 'T seq -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 0; 8; 9; 1; 2 }
.
Returns true if the sequence contains no elements, false otherwise.
'T seq
The input sequence.
bool
True if the sequence is empty; false otherwise.
[] |> Seq.isEmpty
module Seq from Microsoft.FSharp.Collections
val isEmpty: source: 'T seq -> bool
Evaluates totrue
["pear"; "banana"] |> Seq.isEmpty
module Seq from Microsoft.FSharp.Collections
val isEmpty: source: 'T seq -> bool
Evaluates tofalse
Computes the element at the specified index in the collection.
int
The index of the element to retrieve.
'T seq
The input sequence.
'T
The element at the specified index of the sequence.
let inputs = ["a"; "b"; "c"]
inputs |> Seq.item 1
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val item: index: int -> source: 'T seq -> 'T
Evaluates to"b"
let inputs = ["a"; "b"; "c"]
inputs |> Seq.item 4
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val item: index: int -> source: 'T seq -> 'T
ThrowsArgumentException
Applies the given function to each element of the collection.
'T -> unit
A function to apply to each element of the sequence.
'T seq
The input sequence.
["a"; "b"; "c"] |> Seq.iter (printfn "%s")
module Seq from Microsoft.FSharp.Collections
val iter: action: ('T -> unit) -> source: 'T seq -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates tounit
and prints
a
b
c
in 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.
'T1 -> 'T2 -> unit
A function to apply to each pair of elements from the input sequences.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
let inputs1 = ["a"; "b"; "c"]
let inputs2 = [1; 2; 3]
(inputs1, inputs2) ||> Seq.iter2 (printfn "%s: %i")
val inputs1: string list
val inputs2: int list
module Seq from Microsoft.FSharp.Collections
val iter2: action: ('T1 -> 'T2 -> unit) -> source1: 'T1 seq -> source2: 'T2 seq -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates tounit
and prints
a: 1
b: 2
c: 3
in the console.
Applies the given function to each element of the collection. The integer passed to the function indicates the index of element.
int -> 'T -> unit
A function to apply to each element of the sequence that can also access the current index.
'T seq
The input sequence.
let inputs = ["a"; "b"; "c"]
inputs |> Seq.iteri (fun i v -> printfn "{i}: {v}")
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val iteri: action: (int -> 'T -> unit) -> source: 'T seq -> unit
val i: int
val v: string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates tounit
and prints
0: a
1: b
2: c
in 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.
int -> 'T1 -> 'T2 -> unit
A function to apply to each pair of elements from the input sequences along with their index.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
let inputs1 = ["a"; "b"; "c"]
let inputs2 = ["banana"; "pear"; "apple"]
(inputs1, inputs2) ||> Seq.iteri2 (fun i s1 s2 -> printfn "Index {i}: {s1} - {s2}")
val inputs1: string list
val inputs2: string list
module Seq from Microsoft.FSharp.Collections
val iteri2: action: (int -> 'T1 -> 'T2 -> unit) -> source1: 'T1 seq -> source2: 'T2 seq -> unit
val i: int
val s1: string
val s2: string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates tounit
and prints
Index 0: a - banana
Index 1: b - pear
Index 2: c - apple
in the console.
Returns the last element of the sequence.
'T seq
The input sequence.
'T
The last element of the sequence.
["pear"; "banana"] |> Seq.last
module Seq from Microsoft.FSharp.Collections
val last: source: 'T seq -> 'T
Evaluates tobanana
[] |> Seq.last
module Seq from Microsoft.FSharp.Collections
val last: source: 'T seq -> 'T
ThrowsArgumentException
Returns the length of the sequence
'T seq
The input sequence.
int
The length of the sequence.
let inputs = ["a"; "b"; "c"]
inputs |> Seq.length
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val length: source: 'T seq -> int
Evaluates to3
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 MoveNext
method on enumerators retrieved from the object.
'T -> 'U
A function to transform items from the input sequence.
'T seq
The input sequence.
'U seq
The result sequence.
let inputs = ["a"; "bbb"; "cc"]
inputs |> Seq.map (fun x -> x.Length)
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> source: 'T seq -> 'U seq
val x: string
property System.String.Length: int with get
Evaluates to a sequence yielding the same results asseq { 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.
'T1 -> 'T2 -> 'U
A function to transform pairs of items from the input sequences.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
'U seq
The result sequence.
let inputs1 = ["a"; "bad"; "good"]
let inputs2 = [0; 2; 1]
(inputs1, inputs2) ||> Seq.map2 (fun x y -> x.[y])
val inputs1: string list
val inputs2: int list
module Seq from Microsoft.FSharp.Collections
val map2: mapping: ('T1 -> 'T2 -> 'U) -> source1: 'T1 seq -> source2: 'T2 seq -> 'U seq
val x: string
val y: int
Evaluates to a sequence yielding the same results asseq { 'a'; 'd'; 'o' }
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.
'T1 -> 'T2 -> 'T3 -> 'U
The function to transform triples of elements from the input sequences.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
'T3 seq
The third input sequence.
'U seq
The result sequence.
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)
val inputs1: string list
val inputs2: string list
val inputs3: string list
module Seq from Microsoft.FSharp.Collections
val map3: mapping: ('T1 -> 'T2 -> 'T3 -> 'U) -> source1: 'T1 seq -> source2: 'T2 seq -> source3: 'T3 seq -> 'U seq
val x: string
val y: string
val z: string
Evaluates to a sequence yielding the same results asseq { "all"; "the"; "time" }
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.
'State -> 'T -> 'Result * 'State
The function to transform elements from the input collection and accumulate the final value.
'State
The initial state.
'T seq
The input collection.
'Result seq * 'State
The collection of transformed elements, and the final accumulated value.
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)
Multiple items
val double: value: 'T -> double (requires member op_Explicit)
--------------------
type double = System.Double
--------------------
type double<'Measure> = float<'Measure>
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val mapFold<'T,'State,'Result> : mapping: ('State -> 'T -> 'Result * 'State) -> state: 'State -> source: 'T seq -> 'Result seq * 'State
EvaluatesnewCharges
to seq { In 2; Out 4; In 6 }
and balance
to 2
.
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.
'T -> 'State -> 'Result * 'State
The function to transform elements from the input collection and accumulate the final value.
'T seq
The input collection.
'State
The initial state.
'Result seq * 'State
The collection of transformed elements, and the final accumulated value.
Accumulate 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)
type Charge = | In of int | Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
val inputs: Charge seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
val newCharges: Charge seq
val balance: int
module Seq from Microsoft.FSharp.Collections
val mapFoldBack: mapping: ('T -> 'State -> 'Result * 'State) -> source: 'T seq -> state: 'State -> 'Result seq * 'State
val charge: Charge
val acc: int
val i: int
val o: int
EvaluatesnewCharges
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.
int -> 'T -> 'U
A function to transform items from the input sequence that also supplies the current index.
'T seq
The input sequence.
'U seq
The result sequence.
let inputs = [ 10; 10; 10 ]
inputs |> Seq.mapi (fun i x -> i + x)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val mapi: mapping: (int -> 'T -> 'U) -> source: 'T seq -> 'U seq
val i: int
val x: int
Evaluates to a sequence yielding the same results asseq { 10; 11; 12 }
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.
int -> 'T1 -> 'T2 -> 'U
A function to transform pairs of items from the input sequences that also supplies the current index.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
'U seq
The result sequence.
let inputs1 = ["a"; "bad"; "good"]
let inputs2 = [0; 2; 1]
(inputs1, inputs2) ||> Seq.mapi2 (fun i x y -> i, x[y])
val inputs1: string list
val inputs2: int list
module Seq from Microsoft.FSharp.Collections
val mapi2: mapping: (int -> 'T1 -> 'T2 -> 'U) -> source1: 'T1 seq -> source2: 'T2 seq -> 'U seq
val i: int
val x: string
val y: int
Evaluates to a sequence yielding the same results asseq { (0, 'a'); (1, 'd'); (2, 'o') }
Returns the greatest of all elements of the sequence, compared via Operators.max
'T seq
The input sequence.
'T
The largest element of the sequence.
let inputs = [ 10; 12; 11 ]
inputs |> Seq.max
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val max: source: 'T seq -> 'T (requires comparison)
Evaluates to12
let inputs = [ ]
inputs |> Seq.max
val inputs: 'a list
module Seq from Microsoft.FSharp.Collections
val max: source: 'T seq -> 'T (requires comparison)
ThrowsSystem.ArgumentException
.
Returns the greatest of all elements of the sequence, compared via Operators.max on the function result.
'T -> 'U
A function to transform items from the input sequence into comparable keys.
'T seq
The input sequence.
'T
The largest element of the sequence.
let inputs = ["aaa"; "b"; "cccc"]
inputs |> Seq.maxBy (fun s -> s.Length)
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val maxBy: projection: ('T -> 'U) -> source: 'T seq -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to"cccc"
let inputs = [ ]
inputs |> Seq.maxBy (fun s -> s.Length)
val inputs: 'a list
module Seq from Microsoft.FSharp.Collections
val maxBy: projection: ('T -> 'U) -> source: 'T seq -> 'T (requires comparison)
val s: obj
ThrowsSystem.ArgumentException
.
Returns the lowest of all elements of the sequence, compared via Operators.min
.
'T seq
The input sequence.
'T
The smallest element of the sequence.
let inputs = [10; 12; 11]
inputs |> Seq.min
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val min: source: 'T seq -> 'T (requires comparison)
Evaluates to10
let inputs = []
inputs |> Seq.min
val inputs: 'a list
module Seq from Microsoft.FSharp.Collections
val min: source: 'T seq -> 'T (requires comparison)
ThrowsSystem.ArgumentException
.
Returns the lowest of all elements of the sequence, compared via Operators.min on the function result.
'T -> 'U
A function to transform items from the input sequence into comparable keys.
'T seq
The input sequence.
'T
The smallest element of the sequence.
let inputs = [ "aaa"; "b"; "cccc" ]
inputs |> Seq.minBy (fun s -> s.Length)
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val minBy: projection: ('T -> 'U) -> source: 'T seq -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to"b"
let inputs = []
inputs |> Seq.minBy (fun (s: string) -> s.Length)
val inputs: 'a list
module Seq from Microsoft.FSharp.Collections
val minBy: projection: ('T -> 'U) -> source: 'T seq -> 'T (requires comparison)
val s: string
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
property System.String.Length: int with get
ThrowsSystem.ArgumentException
.
Views the given array as a sequence.
'T array
The input array.
'T seq
The result sequence.
let inputs = [| 1; 2; 5 |]
inputs |> Seq.ofArray
val inputs: int array
module Seq from Microsoft.FSharp.Collections
val ofArray: source: 'T array -> 'T seq
Evaluates to a sequence yielding the same results asseq { 1; 2; 5 }
.
Views the given list as a sequence.
'T list
The input list.
'T seq
The result sequence.
let inputs = [ 1; 2; 5 ]
inputs |> Seq.ofList
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val ofList: source: 'T list -> 'T seq
Evaluates to a sequence yielding the same results asseq { 1; 2; 5 }
.
Returns a sequence of each element in the input sequence paired with its predecessor, with the exception of the first element which is only returned as the predecessor of the second element. The predecessor comes first in the returned pairs.
'T seq
The input sequence.
('T * 'T) seq
The result sequence.
let inputs = seq { 1; 2; 3; 4 }
inputs |> Seq.pairwise
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val pairwise: source: 'T seq -> ('T * 'T) seq
Evaluates to a sequence yielding the same results asseq { (1, 2); (2, 3); (3, 4) }
.
Returns a sequence with all elements permuted according to the specified permutation.
int -> int
The function that maps input indices to output indices.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = [1; 2; 3; 4]
inputs |> Seq.permute (fun x -> (x + 1) % 4)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val permute: indexMap: (int -> int) -> source: 'T seq -> 'T seq
val x: int
Evaluates to a sequence yielding the same results asseq { 4; 1; 2; 3 }
.
Applies the given function to successive elements, returning the first x
where the function returns "Some(x)".
'T -> 'U option
A function to transform each item of the input sequence into an option of the output type.
'T seq
The input sequence.
'U
The selected element.
let input = [1; 2; 3]
input |> Seq.pick (fun n -> if n % 2 = 0 then Some (string n) else None)
val input: int list
module Seq from Microsoft.FSharp.Collections
val pick: chooser: ('T -> 'U option) -> source: 'T seq -> 'U
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
union case Option.None: Option<'T>
Evaluates to"2"
.
let input = [1; 2; 3]
input |> Seq.pick (fun n -> if n > 3 = 0 then Some (string n) else None)
val input: int list
module Seq from Microsoft.FSharp.Collections
val pick: chooser: ('T -> 'U option) -> source: 'T seq -> 'U
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
union case Option.None: Option<'T>
ThrowsKeyNotFoundException
.
Returns a random element from the given sequence.
'T seq
The input sequence.
'T
A randomly selected element from the input sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomChoice
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate to3
.
Returns a random element from the given sequence with the specified randomizer
function.
unit -> float
The randomizer function, must return a float number from [0.0..1.0) range.
'T seq
The input sequence.
'T
A randomly selected element from the input sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
let randomizer = Random.Shared.NextDouble
inputs |> Seq.randomChoiceBy randomizer
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
val randomizer: obj
module Seq from Microsoft.FSharp.Collections
Can evaluate to3
.
Returns a random element from the given sequence with the specified Random
instance.
Random
The Random
instance.
'T seq
The input sequence.
'T
A randomly selected element from the input array.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomChoiceWith Random.Shared
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate to3
.
Returns an sequence of random elements from the given sequence, each element can be selected multiple times.
int
The number of elements to return.
'T seq
The input sequence.
'T seq
A sequence of randomly selected elements from the input sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomChoices 3
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 3; 1; 3 }
.
Returns a sequence of random elements from the given sequence with the specified randomizer
function, each element can be selected multiple times.
unit -> float
The randomizer function, must return a float number from [0.0..1.0) range.
int
The number of elements to return.
'T seq
The input sequence.
'T seq
A sequence of randomly selected elements from the input sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomChoicesBy Random.Shared.NextDouble 3
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 3; 1; 3 }
.
Returns a sequence of random elements from the given sequence with the specified Random
instance, each element can be selected multiple times.
Random
The Random
instance.
int
The number of elements to return.
'T seq
The input sequence.
'T seq
A sequence of randomly selected elements from the input sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomChoicesWith Random.Shared 3
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 3; 1; 3 }
.
Returns a random sample of elements from the given sequence, each element can be selected only once.
int
The number of elements to return.
'T seq
The input sequence.
'T seq
A sequence of randomly selected elements from the input sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomSample 3
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 3; 1; 2 }
.
Returns a random sample of elements from the given sequence with the specified randomizer
function, each element can be selected only once.
unit -> float
The randomizer function, must return a float number from [0.0..1.0) range.
int
The number of elements to return.
'T seq
The input sequence.
'T seq
A sequence of randomly selected elements from the input sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomSampleBy Random.Shared.NextDouble 3
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 3; 1; 2 }
.
Returns a random sample of elements from the given sequence with the specified Random
instance, each element can be selected only once.
Random
The Random
instance.
int
The number of elements to return.
'T seq
The input sequence.
'T seq
A sequence of randomly selected elements from the input sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomSampleWith Random.Shared 3
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 3; 1; 2 }
.
Return a new sequence shuffled in a random order.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomShuffle
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 0; 2; 4; 3; 1 }
.
Return a new sequence shuffled in a random order with the specified randomizer
function.
unit -> float
The randomizer function, must return a float number from [0.0..1.0) range.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomShuffleBy Random.Shared.NextDouble
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 0; 2; 4; 3; 1 }
.
Return a new sequence shuffled in a random order with the specified Random
instance.
Random
The Random
instance.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = seq { 0; 1; 2; 3; 4 }
inputs |> Seq.randomShuffleWith Random.Shared
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
Can evaluate toseq { 0; 2; 4; 3; 1 }
.
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.
'T seq
The input sequence.
'T seq
The result sequence.
let input = [| 1; 2; 3 |]
input |> Seq.readonly
val input: int array
module Seq from Microsoft.FSharp.Collections
val readonly: source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 1; 2; 3 }
.
let input = [| 1; 2; 3 |]
let readonlyView = input |> Seq.readonly
(readonlyView :?> int array).[1] <- 4
val input: int array
val readonlyView: int seq
module Seq from Microsoft.FSharp.Collections
val readonly: source: 'T seq -> 'T seq
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
type 'T array = 'T array
Throws anInvalidCastException
.
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.
'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.
'T seq
The input sequence.
'T
The final result of the reduction function.
let inputs = [1; 3; 4; 2]
inputs |> Seq.reduce (fun a b -> a * 10 + b)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val reduce: reduction: ('T -> 'T -> 'T) -> source: 'T seq -> 'T
val a: int
val b: int
Evaluates to1342
, by computing ((1 * 10 + 3) * 10 + 4) * 10 + 2
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 f
and the elements are i0...iN
then computes f i0 (...(f iN-1 iN))
.
'T -> 'T -> 'T
A function that takes in the next-to-last element of the sequence and the current accumulated result to produce the next accumulated result.
'T seq
The input sequence.
'T
The final result of the reductions.
let inputs = [1; 3; 4; 2]
inputs |> Seq.reduceBack (fun a b -> a + b * 10)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val reduceBack: reduction: ('T -> 'T -> 'T) -> source: 'T seq -> 'T
val a: int
val b: int
Evaluates to2431
, by computing 1 + (3 + (4 + 2 * 10) * 10) * 10
Return a new sequence with the item at a given index removed.
int
The index of the item to be removed.
'T seq
The input sequence.
'T seq
The result sequence.
seq { 0; 1; 2 } |> Seq.removeAt 1
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val removeAt: index: int -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 0; 2 }
.
Return a new sequence with the number of items starting at a given index removed.
int
The index of the item to be removed.
int
The number of items to remove.
'T seq
The input sequence.
'T seq
The result sequence.
seq { 0; 1; 2; 3 } |> Seq.removeManyAt 1 2
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val removeManyAt: index: int -> count: int -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 0; 3 }
.
Creates a sequence by replicating the given initial value.
int
The number of elements to replicate.
'T
The value to replicate
'T seq
The generated sequence.
Seq.replicate 3 "a"
module Seq from Microsoft.FSharp.Collections
val replicate: count: int -> initial: 'T -> 'T seq
Evaluates to a sequence yielding the same results asseq { "a"; "a"; "a" }
.
Returns a new sequence with the elements in reverse order.
'T seq
The input sequence.
'T seq
The reversed sequence.
let input = seq { 0; 1; 2 }
input |> Seq.rev
val input: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val rev: source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 2; 1; 0 }
.
Like fold, but computes on-demand and returns the sequence of intermediary and final results.
'State -> 'T -> 'State
A function that updates the state with each element from the sequence.
'State
The initial state.
'T seq
The input sequence.
'State seq
The resulting sequence of computed states.
Apply 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)
type Charge = | In of int | Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
val inputs: Charge seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
module Seq from Microsoft.FSharp.Collections
val scan<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> source: 'T seq -> 'State seq
val acc: int
val charge: Charge
val i: int
val o: int
Evaluates to a sequence yielding the same results asseq { 0; 1; -1; 2 }
. Note 0
is the initial state, 1
the next state, -1
the next state, and 2
the final state.
Like foldBack
, but returns the sequence of intermediary and final results.
'T -> 'State -> 'State
A function that updates the state with each element from the sequence.
'T seq
The input sequence.
'State
The initial state.
'State seq
The resulting sequence of computed states.
Apply 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)
type Charge = | In of int | Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
val inputs: Charge list
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
module Seq from Microsoft.FSharp.Collections
val scanBack: folder: ('T -> 'State -> 'State) -> source: 'T seq -> state: 'State -> 'State seq
val charge: Charge
val acc: int
val i: int
val o: int
Evaluates to a sequence yielding the same results asseq { 2; 1; 3; 0 }
by processing each input from back to front. Note 0
is the initial state, 3
the next state, 1
the next state, and 2
the final state, and the states are produced from back to front.
Returns a sequence yielding one item only.
'T
The input item.
'T seq
The result sequence of one item.
Seq.singleton 7
module Seq from Microsoft.FSharp.Collections
val singleton: value: 'T -> 'T seq
Evaluates to a sequence yielding the same results asseq { 7 }
.
Returns a sequence that skips N elements of the underlying sequence and then yields the remaining elements of the sequence.
int
The number of items to skip.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.skip 2
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val skip: count: int -> source: 'T seq -> 'T seq
Evaluates a sequence yielding the same results asseq { "c"; "d" }
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.skip 5
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val skip: count: int -> source: 'T seq -> 'T seq
ThrowsArgumentException
.
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.skip -1
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val skip: count: int -> source: 'T seq -> 'T seq
Evaluates a sequence yielding the same results asseq { "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.
'T -> bool
A function that evaluates an element of the sequence to a boolean value.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = seq { "a"; "bbb"; "cc"; "d" }
inputs |> Seq.skipWhile (fun x -> x.Length < 3)
val inputs: string seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val skipWhile: predicate: ('T -> bool) -> source: 'T seq -> 'T seq
val x: string
property System.String.Length: int with get
Evaluates a sequence yielding the same results asseq { "bbb"; "cc"; "d" }
Yields a sequence ordered by keys.
'T seq
The input sequence.
'T seq
The result sequence.
let input = seq { 8; 4; 3; 1; 6; 1 }
Seq.sort input
val input: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val sort: source: 'T seq -> 'T seq (requires comparison)
Evaluates to a sequence yielding the same results asseq { 1; 1 3; 4; 6; 8 }
.
Applies a key-generating 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.
'T -> 'Key
A function to transform items of the input sequence into comparable keys.
'T seq
The input sequence.
'T seq
The result sequence.
let input = [ "a"; "bbb"; "cccc"; "dd" ]
input |> Seq.sortBy (fun s -> s.Length)
val input: string list
module Seq from Microsoft.FSharp.Collections
val sortBy: projection: ('T -> 'Key) -> source: 'T seq -> 'T seq (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to a sequence yielding the same results asseq { "a"; "dd"; "bbb"; "cccc" }
.
Applies a key-generating 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.
'T -> 'Key
A function to transform items of the input sequence into comparable keys.
'T seq
The input sequence.
'T seq
The result sequence.
let input = ["a"; "bbb"; "cccc"; "dd"]
input |> Seq.sortByDescending (fun s -> s.Length)
val input: string list
module Seq from Microsoft.FSharp.Collections
val sortByDescending: projection: ('T -> 'Key) -> source: 'T seq -> 'T seq (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to a sequence yielding the same results asseq { "cccc"; "bbb"; "dd"; "a" }
.
Yields a sequence ordered descending by keys.
'T seq
The input sequence.
'T seq
The result sequence.
let input = seq { 8; 4; 3; 1; 6; 1 }
input |> Seq.sortDescending
val input: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val sortDescending: source: 'T seq -> 'T seq (requires comparison)
Evaluates to a sequence yielding the same results asseq { 8; 6; 4; 3; 1; 1 }
.
Yields a sequence ordered using the given comparison function.
'T -> 'T -> int
The function to compare the collection elements.
'T seq
The input sequence.
'T seq
The result sequence.
Sort 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 compareEntries
val compareEntries: n1: int * s1: string -> n2: int * s2: string -> int
val n1: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
val s1: string
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
val n2: int
val s2: string
val c: int
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
property System.String.Length: int with get
val input: (int * string) list
module Seq from Microsoft.FSharp.Collections
val sortWith: comparer: ('T -> 'T -> int) -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { (0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb") }
.
Splits the input sequence into at most count
chunks.
int
The maximum number of chunks.
'T seq
The input sequence.
'T array seq
The sequence split into chunks.
let inputs = [1; 2; 3; 4; 5]
inputs |> Seq.splitInto 3
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val splitInto: count: int -> source: 'T seq -> 'T array seq
Evaluates to a sequence yielding the same results asseq { [|1; 2|]; [|3; 4|]; [|5|] }
let inputs = [1; 2; 3; 4; 5]
inputs |> Seq.splitInto -1
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val splitInto: count: int -> source: 'T seq -> 'T array seq
ThrowsArgumentException
Returns the sum of the elements in the sequence.
^T seq
The input sequence.
^T
The computed sum.
let input = [ 1; 5; 3; 2 ]
input |> Seq.sum
val input: int list
module Seq from Microsoft.FSharp.Collections
val sum: source: 'T seq -> 'T (requires member (+) and member Zero)
Evaluates to11
.
Returns the sum of the results generated by applying the function to each element of the sequence.
'T -> ^U
A function to transform items from the input sequence into the type that will be summed.
'T seq
The input sequence.
^U
The computed sum.
let input = [ "aa"; "bbb"; "cc" ]
input |> Seq.sumBy (fun s -> s.Length)
val input: string list
module Seq from Microsoft.FSharp.Collections
val sumBy: projection: ('T -> 'U) -> source: 'T seq -> 'U (requires member (+) and member Zero)
val s: string
property System.String.Length: int with get
Evaluates to7
.
Returns a sequence that skips 1 element of the underlying sequence and then yields the remaining elements of the sequence.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = ["a"; "bb"; "ccc"]
inputs |> Seq.tail
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val tail: source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { "bb"; "ccc" }
Returns the first N elements of the sequence.
int
The number of items to take.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.take 2
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val take: count: int -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results as["a"; "b"]
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.take 6
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val take: count: int -> source: 'T seq -> 'T seq
ThrowsInvalidOperationException
.
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.take 0
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val take: count: int -> source: 'T seq -> 'T seq
Evaluates 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.
'T -> bool
A function that evaluates to false when no more items should be returned.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = ["a"; "bb"; "ccc"; "d"]
inputs |> Seq.takeWhile (fun x -> x.Length < 3)
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val takeWhile: predicate: ('T -> bool) -> source: 'T seq -> 'T seq
val x: string
property System.String.Length: int with get
Evaluates to a sequence yielding the same results asseq { "a"; "bb" }
Builds an array from the given collection.
'T seq
The input sequence.
'T array
The result array.
let inputs = seq { 1; 2; 5 }
inputs |> Seq.toArray
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val toArray: source: 'T seq -> 'T array
Evaluates to[| 1; 2; 5 |]
.
Builds a list from the given collection.
'T seq
The input sequence.
'T list
The result list.
let inputs = seq { 1; 2; 5 }
inputs |> Seq.toList
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val toList: source: 'T seq -> 'T list
Evaluates to[ 1; 2; 5 ]
.
Returns the transpose of the given sequence of sequences.
'Collection seq
The input sequence.
'T seq seq
The transposed sequence.
let inputs =
[ [ 10; 20; 30 ]
[ 11; 21; 31 ] ]
inputs |> Seq.transpose
val inputs: int list list
module Seq from Microsoft.FSharp.Collections
val transpose: source: #('T seq) seq -> 'T seq seq
Evaluates to a sequence of sequences yielding the same results as[ [10; 11]; [20; 21]; [30; 31] ]
.
Returns a sequence that when enumerated returns at most N elements.
int
The maximum number of items to enumerate.
'T seq
The input sequence.
'T seq
The result sequence.
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.truncate 2
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val truncate: count: int -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { "a"; "b" }
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.truncate 6
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val truncate: count: int -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { "a"; "b"; "c"; "d" }
let inputs = ["a"; "b"; "c"; "d"]
inputs |> Seq.truncate 0
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val truncate: count: int -> source: 'T seq -> 'T seq
Evaluates to the empty sequence.Returns the only element of the sequence or None
if sequence is empty or contains more than one element.
'T seq
The input sequence.
'T option
The only element of the sequence or None.
let inputs = ["banana"]
inputs |> Seq.tryExactlyOne
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val tryExactlyOne: source: 'T seq -> 'T option
Evaluates toSome banana
let inputs = ["pear"; "banana"]
inputs |> Seq.tryExactlyOne
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val tryExactlyOne: source: 'T seq -> 'T option
Evaluates toNone
[] |> Seq.tryExactlyOne
module Seq from Microsoft.FSharp.Collections
val tryExactlyOne: source: 'T seq -> 'T option
Evaluates toNone
Returns the first element for which the given function returns True. Return None if no such element exists.
'T -> bool
A function that evaluates to a Boolean when given an item in the sequence.
'T seq
The input sequence.
'T option
The found element or None.
Try to find the first even number:
let inputs = [1; 2; 3]
inputs |> Seq.tryFind (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val tryFind: predicate: ('T -> bool) -> source: 'T seq -> 'T option
val elm: int
Evaluates toSome 2
Try to find the first even number:
let inputs = [1; 5; 3]
inputs |> Seq.tryFind (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val tryFind: predicate: ('T -> bool) -> source: 'T seq -> 'T option
val elm: int
Evaluates toNone
Returns the last element for which the given function returns True. Return None if no such element exists.
'T -> bool
A function that evaluates to a Boolean when given an item in the sequence.
'T seq
The input sequence.
'T option
The found element or None.
Try to find the first even number from the back:
let inputs = [1; 2; 3; 4; 5]
inputs |> Seq.tryFindBack (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val tryFindBack: predicate: ('T -> bool) -> source: 'T seq -> 'T option
val elm: int
Evaluates toSome 4
Try to find the first even number from the back:
let inputs = [1; 5; 3]
inputs |> Seq.tryFindBack (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val tryFindBack: predicate: ('T -> bool) -> source: 'T seq -> 'T option
val elm: int
Evaluates toNone
Returns the index of the first element in the sequence that satisfies the given predicate. Return None
if no such element exists.
'T -> bool
A function that evaluates to a Boolean when given an item in the sequence.
'T seq
The input sequence.
int option
The found index or None.
Try to find the index of the first even number:
let inputs = [1; 2; 3; 4; 5]
inputs |> Seq.tryFindIndex (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val tryFindIndex: predicate: ('T -> bool) -> source: 'T seq -> int option
val elm: int
Evaluates toSome 1
Try to find the index of the first even number:
let inputs = [1; 3; 5; 7]
inputs |> Seq.tryFindIndex (fun elm -> elm % 2 = 0)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val tryFindIndex: predicate: ('T -> bool) -> source: 'T seq -> int option
val elm: int
Evaluates toNone
Returns the index of the last element in the sequence that satisfies the given predicate. Return None
if no such element exists.
'T -> bool
A function that evaluates to a Boolean when given an item in the sequence.
'T seq
The input sequence.
int option
The found index or None
.
Try 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)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val tryFindIndexBack: predicate: ('T -> bool) -> source: 'T seq -> int option
val elm: int
Evaluates toSome 3
Try 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)
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val tryFindIndexBack: predicate: ('T -> bool) -> source: 'T seq -> int option
val elm: int
Evaluates toNone
Returns the first element of the sequence, or None if the sequence is empty.
'T seq
The input sequence.
'T option
The first element of the sequence or None.
["banana"; "pear"] |> Seq.tryHead
module Seq from Microsoft.FSharp.Collections
val tryHead: source: 'T seq -> 'T option
Evaluates toSome "banana"
[] |> Seq.tryHead
module Seq from Microsoft.FSharp.Collections
val tryHead: source: 'T seq -> 'T option
Evaluates toNone
Tries to find the nth element in the sequence. Returns None
if index is negative or the input sequence does not contain enough elements.
int
The index of element to retrieve.
'T seq
The input sequence.
'T option
The nth element of the sequence or None
.
let inputs = ["a"; "b"; "c"]
inputs |> Seq.tryItem 1
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val tryItem: index: int -> source: 'T seq -> 'T option
Evaluates toSome "b"
.
let inputs = ["a"; "b"; "c"]
inputs |> Seq.tryItem 4
val inputs: string list
module Seq from Microsoft.FSharp.Collections
val tryItem: index: int -> source: 'T seq -> 'T option
Evaluates toNone
.
Returns the last element of the sequence. Return None
if no such element exists.
'T seq
The input sequence.
'T option
The last element of the sequence or None.
["pear"; "banana"] |> Seq.tryLast
module Seq from Microsoft.FSharp.Collections
val tryLast: source: 'T seq -> 'T option
Evaluates toSome "banana"
[] |> Seq.tryLast
module Seq from Microsoft.FSharp.Collections
val tryLast: source: 'T seq -> 'T option
Evaluates toNone
Applies the given function to successive elements, returning the first result where the function returns "Some(x)".
'T -> 'U option
A function that transforms items from the input sequence into options.
'T seq
The input sequence.
'U option
The chosen element or None
.
let input = [1; 2; 3]
input |> Seq.tryPick (fun n -> if n % 2 = 0 then Some (string n) else None)
val input: int list
module Seq from Microsoft.FSharp.Collections
val tryPick: chooser: ('T -> 'U option) -> source: 'T seq -> 'U option
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
union case Option.None: Option<'T>
Evaluates toSome "2"
.
let input = [1; 2; 3]
input |> Seq.tryPick (fun n -> if n > 3 = 0 then Some (string n) else None)
val input: int list
module Seq from Microsoft.FSharp.Collections
val tryPick: chooser: ('T -> 'U option) -> source: 'T seq -> 'U option
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
union case Option.None: Option<'T>
Evaluates toNone
.
Returns a sequence that contains the elements generated by the given computation. The given initial state
argument is passed to the element generator. For each IEnumerator elements in the stream are generated on-demand by applying the element generator, until a None value is returned by the element generator. Each call to the element generator returns a new residual state
.
'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
The initial state value.
'T seq
The result sequence.
1 |> Seq.unfold (fun state -> if state > 100 then None else Some (state, state * 2))
module Seq from Microsoft.FSharp.Collections
val unfold: generator: ('State -> ('T * 'State) option) -> state: 'State -> 'T seq
val state: int
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
Evaluates to a sequence yielding the same results asseq { 1; 2; 4; 8; 16; 32; 64 }
1I |> Seq.unfold (fun state -> Some (state, state * 2I))
module Seq from Microsoft.FSharp.Collections
val unfold: generator: ('State -> ('T * 'State) option) -> state: 'State -> 'T seq
val state: System.Numerics.BigInteger
union case Option.Some: Value: 'T -> Option<'T>
Evaluates to an infinite sequence yielding the resultsseq { 1I; 2I; 4I; 8I; ... }
Return a new sequence with the item at a given index set to the new value.
int
The index of the item to be replaced.
'T
The new value.
'T seq
The input sequence.
'T seq
The result sequence.
seq { 0; 1; 2 } |> Seq.updateAt 1 9
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq from Microsoft.FSharp.Collections
val updateAt: index: int -> value: 'T -> source: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results asseq { 0; 9; 2 }
.
Returns a new collection containing only the elements of the collection for which the given predicate returns "true".
'T -> bool
A function to test whether each item in the input sequence should be included in the output.
'T seq
The input sequence.
'T seq
The result sequence.
[1; 2; 3; 4] |> Seq.where (fun elm -> elm % 2 = 0)
module Seq from Microsoft.FSharp.Collections
val where: predicate: ('T -> bool) -> source: 'T seq -> 'T seq
val elm: int
Evaluates to a sequence yielding the same results asseq { 2; 4 }
Returns a sequence yielding sliding windows containing elements drawn from the input sequence. Each window is returned as a fresh array.
int
The number of elements in each window.
'T seq
The input sequence.
'T array seq
The result sequence.
let inputs = [1; 2; 3; 4; 5]
inputs |> Seq.windowed 3
val inputs: int list
module Seq from Microsoft.FSharp.Collections
val windowed: windowSize: int -> source: 'T seq -> 'T array seq
Evaluates to a sequence of arrays yielding the resultsseq { [| 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.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
('T1 * 'T2) seq
The result sequence.
let numbers = [1; 2]
let names = ["one"; "two"]
Seq.zip numbers names
val numbers: int list
val names: string list
module Seq from Microsoft.FSharp.Collections
val zip: source1: 'T1 seq -> source2: 'T2 seq -> ('T1 * 'T2) seq
Evaluates to a sequence yielding the same results asseq { (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.
'T1 seq
The first input sequence.
'T2 seq
The second input sequence.
'T3 seq
The third input sequence.
('T1 * 'T2 * 'T3) seq
The result sequence.
let numbers = [1; 2]
let names = ["one"; "two"]
let roman = ["I"; "II"]
Seq.zip3 numbers names roman
val numbers: int list
val names: string list
val roman: string list
module Seq from Microsoft.FSharp.Collections
val zip3: source1: 'T1 seq -> source2: 'T2 seq -> source3: 'T3 seq -> ('T1 * 'T2 * 'T3) seq
Evaluates to a sequence yielding the same results asseq { (1, "one", "I"); (2, "two", "II") }
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4