Seq Module
Contains operations for working with values of type seq.
Functions and values
Function or value |
Description
|
||||||||||
|
Returns a new sequence that contains all pairings of elements from the first and second sequences.
Example
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
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. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
module Seq
from Microsoft.FSharp.Collections
val append: source1: 'T seq -> source2: 'T seq -> 'T seq
Evaluates to a sequence yielding the same results as seq { 1; 2; 3; 4 }
|
||||||||||
Full Usage:
Seq.average source
Parameters:
^T seq
-
The input sequence.
Returns: ^T
The average.
Modifiers: inline Type parameters: ^T |
Returns the average of the elements in the sequence.
The elements are averaged using the
Example
module Seq
from Microsoft.FSharp.Collections
val average: source: 'T seq -> 'T (requires member (+) and member DivideByInt and member Zero)
Evaluates to 2.0
Example
module Seq
from Microsoft.FSharp.Collections
val average: source: 'T seq -> 'T (requires member (+) and member DivideByInt and member Zero)
Throws ArgumentException
|
||||||||||
Full Usage:
Seq.averageBy projection source
Parameters:
'T -> ^U
-
A function applied to transform each element of the sequence.
source : 'T seq
-
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 }
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 to 3.0
Example
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
Throws ArgumentException
|
||||||||||
|
Returns a sequence that corresponds to a cached version of the input sequence. 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 side-effects 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 re-enumerated and a fresh enumerator will be used.
Example
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 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: 'T seq
The result sequence.
|
Wraps a loosely-typed System.Collections sequence as a typed 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
val box: value: 'T -> obj
module Seq
from Microsoft.FSharp.Collections
val cast: source: System.Collections.IEnumerable -> 'T seq
Multiple items
Evaluates to a sequence yielding the same results as val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int 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
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 as seq { 1; 2 }
Example
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 as seq { 2 }
|
||||||||||
|
Divides the input sequence into chunks of size at most
Example
module Seq
from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> source: 'T seq -> 'T array seq
Evaluates to a sequence yielding the same results as seq { [|1; 2|]; [|3|] }
Example
module Seq
from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> source: 'T seq -> 'T array seq
Throws ArgumentException
|
||||||||||
|
Applies the given function to each element of the sequence and concatenates all the results. Remember sequence is lazy, effects are delayed until it is enumerated.
Example
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 as seq { 1; 2; 3; 4 }
Example
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 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 non-zero value iteration is stopped and that value is returned.
source1 : 'T seq
-
The first input sequence.
source2 : 'T seq
-
The second input sequence.
Returns: 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.
|
Compares two sequences using the given comparison function, element by element.
Example
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 0
Example
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
Example
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
Example
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
Example
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. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
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 as seq { 1; 2; 3; 4; 5 }
|
||||||||||
|
Tests if the sequence contains the specified element.
Example
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. 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 }
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 as seq { ("a", 2); ("b", 1) }
|
||||||||||
|
Returns a sequence that is built from the given delayed specification of a sequence. The input function is evaluated each time an IEnumerator for the sequence is requested.
Example
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 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
module Seq
from Microsoft.FSharp.Collections
val distinct: source: 'T seq -> 'T seq (requires equality)
Evaluates 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 key-generating function. If an element occurs multiple times in the sequence then the later occurrences are discarded.
Example
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 as seq { { Bar = 1 }; { Bar = 2 }; { Bar = 3 } }
|
||||||||||
Creates an empty sequence.
Example
module Seq
from Microsoft.FSharp.Collections
val empty<'T> : 'T seq
|
|||||||||||
Full Usage:
Seq.exactlyOne source
Parameters:
'T seq
-
The input sequence.
Returns: 'T
The only element of the sequence.
|
Returns the only element of the sequence.
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val exactlyOne: source: 'T seq -> 'T
Evaluates to banana
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val exactlyOne: source: 'T seq -> 'T
Throws ArgumentException
Example
module Seq
from Microsoft.FSharp.Collections
val exactlyOne: source: 'T seq -> 'T
Throws ArgumentException
|
||||||||||
Full Usage:
Seq.except itemsToExclude source
Parameters:
'T seq
-
A sequence whose elements that also occur in the second sequence will cause those elements to be
removed from the returned sequence.
source : 'T seq
-
A sequence whose elements that are not also in first will be returned.
Returns: 'T seq
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
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 as seq { 2; 4 }
|
||||||||||
|
Tests if any element of the sequence satisfies the given predicate. 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
val input: int list
module Seq
from Microsoft.FSharp.Collections
val exists: predicate: ('T -> bool) -> source: 'T seq -> bool
val elm: int
Evaluates to true
Example
val input: int list
module Seq
from Microsoft.FSharp.Collections
val exists: predicate: ('T -> bool) -> source: 'T seq -> bool
val elm: int
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 : 'T1 seq
-
The first input sequence.
source2 : 'T2 seq
-
The second input sequence.
Returns: bool
True if any result from the predicate is true; false otherwise.
|
Tests if any pair of corresponding elements of the input sequences satisfies the given predicate. 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
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 to false
Example
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 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
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 as seq { 2; 4 }
|
||||||||||
|
Returns the first element for which the given function returns True.
Example
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> source: 'T seq -> 'T
val elm: int
Evaluates to 2
Example
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> source: 'T seq -> 'T
val elm: int
Throws KeyNotFoundException
|
||||||||||
|
Returns the last element for which the given function returns True. 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
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> source: 'T seq -> 'T
val elm: int
Evaluates to 4
Example
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> source: 'T seq -> 'T
val elm: int
Throws KeyNotFoundException
|
||||||||||
|
Returns the index of the first element for which the given function returns True.
Example
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> source: 'T seq -> int
val elm: int
Evaluates to 1
Example
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> source: 'T seq -> int
val elm: int
Throws KeyNotFoundException
|
||||||||||
|
Returns the index of the last element for which the given function returns True. 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
val input: int list
module Seq
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> source: 'T seq -> int
val elm: int
Evaluates to 3
Example
val input: int list
module Seq
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> source: 'T seq -> int
val elm: int
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 : 'T seq
-
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
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 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 : 'T1 seq
-
The first input sequence.
source2 : 'T2 seq
-
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
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 to 1
|
||||||||||
Full Usage:
Seq.foldBack folder source state
Parameters:
'T -> 'State -> 'State
-
The function to update the state given the input elements.
source : 'T seq
-
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
}
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
namespace Microsoft.FSharp.Text
|
||||||||||
Full Usage:
Seq.foldBack2 folder source1 source2 state
Parameters:
'T1 -> 'T2 -> 'State -> 'State
-
The function to update the state given the input elements.
source1 : 'T1 seq
-
The first input sequence.
source2 : 'T2 seq
-
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
}
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
namespace Microsoft.FSharp.Text
|
||||||||||
|
Tests if all elements of the sequence satisfy the given predicate. 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
val isEven: a: int -> bool
val a: int
module Seq
from Microsoft.FSharp.Collections
val forall: predicate: ('T -> bool) -> source: 'T seq -> bool
|
||||||||||
Full Usage:
Seq.forall2 predicate source1 source2
Parameters:
'T1 -> 'T2 -> bool
-
A function to test pairs of elements from the input sequences.
source1 : 'T1 seq
-
The first input sequence.
source2 : 'T2 seq
-
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
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 to true .
Example
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 to false .
|
||||||||||
|
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. 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
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 as seq { (1, seq { 1; 3; 5 }); (0, seq { 2; 4 }) }
|
||||||||||
Full Usage:
Seq.head source
Parameters:
'T seq
-
The input sequence.
Returns: 'T
The first element of the sequence.
|
Returns the first element of the sequence.
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val head: source: 'T seq -> 'T
Evaluates to banana
Example
module Seq
from Microsoft.FSharp.Collections
val head: source: 'T seq -> 'T
Throws 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
module Seq
from Microsoft.FSharp.Collections
val indexed: source: 'T seq -> (int * 'T) seq
Evaluates 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
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 as seq { 5; 6; 7; 8 }
Example
module Seq
from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T seq
val v: int
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
module Seq
from Microsoft.FSharp.Collections
val initInfinite: initializer: (int -> 'T) -> 'T seq
Evaluates to a sequence yielding the same results as seq { 5; 6; 7; 8; ... }
|
||||||||||
|
Return a new sequence with a new item inserted before the given index.
Example
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 as seq { 0; 9; 1; 2 } .
|
||||||||||
|
Return a new sequence with new items inserted before the given index.
Example
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 as seq { 0; 8; 9; 1; 2 } .
|
||||||||||
|
Returns true if the sequence contains no elements, false otherwise.
Example
module Seq
from Microsoft.FSharp.Collections
val isEmpty: source: 'T seq -> bool
Evaluates to true
Example
module Seq
from Microsoft.FSharp.Collections
val isEmpty: source: 'T seq -> bool
Evaluates to false
|
||||||||||
|
Computes the element at the specified index in the collection.
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val item: index: int -> source: 'T seq -> 'T
Evaluates to "b"
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val item: index: int -> source: 'T seq -> 'T
Throws ArgumentException
|
||||||||||
|
Applies the given function to each element of the collection.
Example
module Seq
from Microsoft.FSharp.Collections
val iter: action: ('T -> unit) -> source: 'T seq -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
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.
Example
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 to unit and prints
in the console.
|
||||||||||
|
Applies the given function to each element of the collection. The integer passed to the function indicates the index of element.
Example
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 to unit and prints
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.
Example
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 to unit and prints
in the console.
|
||||||||||
Full Usage:
Seq.last source
Parameters:
'T seq
-
The input sequence.
Returns: 'T
The last element of the sequence.
|
Returns the last element of the sequence.
Example
module Seq
from Microsoft.FSharp.Collections
val last: source: 'T seq -> 'T
Evaluates to banana
Example
module Seq
from Microsoft.FSharp.Collections
val last: source: 'T seq -> 'T
Throws ArgumentException
|
||||||||||
|
Returns the length of the sequence
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val length: source: 'T seq -> int
Evaluates 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
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 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
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 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 : 'T1 seq
-
The first input sequence.
source2 : 'T2 seq
-
The second input sequence.
source3 : 'T3 seq
-
The third input sequence.
Returns: 'U seq
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
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 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 : 'T seq
-
The input collection.
Returns: 'Result seq * '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
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
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 : 'T seq
-
The input collection.
state : 'State
-
The initial state.
Returns: 'Result seq * '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
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
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
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 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 : 'T1 seq
-
The first input sequence.
source2 : 'T2 seq
-
The second input sequence.
Returns: 'U seq
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
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 as seq { (0, 'a'); (1, 'd'); (2, 'o') }
|
||||||||||
Full Usage:
Seq.max source
Parameters:
'T seq
-
The input sequence.
Returns: 'T
The largest element of the sequence.
Modifiers: inline Type parameters: 'T |
Returns the greatest of all elements of the sequence, compared via Operators.max
Example
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val max: source: 'T seq -> 'T (requires comparison)
Evaluates to 12
Example
val inputs: 'a list
module Seq
from Microsoft.FSharp.Collections
val max: source: 'T seq -> 'T (requires comparison)
Throws System.ArgumentException .
|
||||||||||
Full Usage:
Seq.maxBy projection source
Parameters:
'T -> 'U
-
A function to transform items from the input sequence into comparable keys.
source : 'T seq
-
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
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"
Example
val inputs: 'a list
module Seq
from Microsoft.FSharp.Collections
val maxBy: projection: ('T -> 'U) -> source: 'T seq -> 'T (requires comparison)
val s: obj
Throws System.ArgumentException .
|
||||||||||
Full Usage:
Seq.min source
Parameters:
'T seq
-
The input sequence.
Returns: 'T
The smallest element of the sequence.
Modifiers: inline Type parameters: 'T |
Returns the lowest of all elements of the sequence, compared via
Example
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val min: source: 'T seq -> 'T (requires comparison)
Evaluates to 10
Example
val inputs: 'a list
module Seq
from Microsoft.FSharp.Collections
val min: source: 'T seq -> 'T (requires comparison)
Throws System.ArgumentException .
|
||||||||||
Full Usage:
Seq.minBy projection source
Parameters:
'T -> 'U
-
A function to transform items from the input sequence into comparable keys.
source : 'T seq
-
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
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"
Example
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
Throws System.ArgumentException .
|
||||||||||
|
Views the given array as a sequence.
Example
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 as seq { 1; 2; 5 } .
|
||||||||||
|
Views the given list as a sequence.
Example
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 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
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 as seq { (1, 2); (2, 3); (3, 4) } .
|
||||||||||
|
Returns a sequence with all elements permuted according to the specified permutation. This function consumes the whole input sequence before yielding the first element of the result sequence.
Example
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 as seq { 4; 1; 2; 3 } .
|
||||||||||
|
Applies the given function to successive elements, returning the first
Example
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" .
Example
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>
Throws KeyNotFoundException .
|
||||||||||
Full Usage:
Seq.randomChoice source
Parameters:
'T seq
-
The input sequence.
Returns: 'T
A randomly selected element from the input sequence.
|
Returns a random element from the given sequence.
Example
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 to 3 .
|
||||||||||
|
Returns a random element from the given sequence with the specified
Example
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 to 3 .
|
||||||||||
|
Returns a random element from the given sequence with the specified
Example
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 to 3 .
|
||||||||||
|
Returns an sequence of random elements from the given sequence, each element can be selected multiple times.
Example
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 to seq { 3; 1; 3 } .
|
||||||||||
Full Usage:
Seq.randomChoicesBy randomizer count source
Parameters:
unit -> float
-
The randomizer function, must return a float number from [0.0..1.0) range.
count : int
-
The number of elements to return.
source : 'T seq
-
The input sequence.
Returns: 'T seq
A sequence of randomly selected elements from the input sequence.
|
Returns a sequence of random elements from the given sequence with the specified
Example
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 to seq { 3; 1; 3 } .
|
||||||||||
|
Returns a sequence of random elements from the given sequence with the specified
Example
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 to seq { 3; 1; 3 } .
|
||||||||||
|
Returns a random sample of elements from the given sequence, each element can be selected only once.
Example
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 to seq { 3; 1; 2 } .
|
||||||||||
Full Usage:
Seq.randomSampleBy randomizer count source
Parameters:
unit -> float
-
The randomizer function, must return a float number from [0.0..1.0) range.
count : int
-
The number of elements to return.
source : 'T seq
-
The input sequence.
Returns: 'T seq
A sequence of randomly selected elements from the input sequence.
|
Returns a random sample of elements from the given sequence with the specified
Example
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 to seq { 3; 1; 2 } .
|
||||||||||
|
Returns a random sample of elements from the given sequence with the specified
Example
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 to seq { 3; 1; 2 } .
|
||||||||||
|
Return a new sequence shuffled in a random order.
Example
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 to seq { 0; 2; 4; 3; 1 } .
|
||||||||||
|
Return a new sequence shuffled in a random order with the specified
Example
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 to seq { 0; 2; 4; 3; 1 } .
|
||||||||||
|
Return a new sequence shuffled in a random order with the specified
Example
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 to seq { 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.
Example
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 as seq { 1; 2; 3 } .
Example
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 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 : 'T seq
-
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
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 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 next-to-last element of the sequence and the
current accumulated result to produce the next accumulated result.
source : 'T seq
-
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
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 to 2431 , by computing 1 + (3 + (4 + 2 * 10) * 10) * 10
|
||||||||||
|
Return a new sequence with the item at a given index removed.
Example
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 as seq { 0; 2 } .
|
||||||||||
|
Return a new sequence with the number of items starting at a given index removed.
Example
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 as seq { 0; 3 } .
|
||||||||||
|
Creates a sequence by replicating the given initial value.
Example
module Seq
from Microsoft.FSharp.Collections
val replicate: count: int -> initial: 'T -> 'T seq
Evaluates to a sequence yielding the same results as seq { "a"; "a"; "a" } .
|
||||||||||
|
Returns a new sequence with the elements in reverse order. This function consumes the whole input sequence before yielding the first element of the reversed sequence.
Example
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 as seq { 2; 1; 0 } .
|
||||||||||
|
Like fold, but computes on-demand and returns the sequence of intermediary and final results.
ExampleApply a list charges and collect the running balances as each is applied:
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 as seq { 0; 1; -1; 2 } . Note 0 is the initial
state, 1 the next state, -1 the next state, and 2 the final state.
|
||||||||||
|
Like 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
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 as seq { 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.
|
||||||||||
Full Usage:
Seq.singleton value
Parameters:
'T
-
The input item.
Returns: 'T seq
The result sequence of one item.
|
Returns a sequence yielding one item only.
Example
module Seq
from Microsoft.FSharp.Collections
val singleton: value: 'T -> 'T seq
Evaluates 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
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 as seq { "c"; "d" }
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val skip: count: int -> source: 'T seq -> 'T seq
Throws ArgumentException .
Example
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 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
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 as seq { "bbb"; "cc"; "d" }
|
||||||||||
|
Yields a sequence ordered by keys. 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
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 as seq { 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. 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
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 as seq { "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. 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
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 as seq { "cccc"; "bbb"; "dd"; "a" } .
|
||||||||||
|
Yields a sequence ordered descending by keys. 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
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 as seq { 8; 6; 4; 3; 1; 1 } .
|
||||||||||
|
Yields a sequence ordered using the given comparison function. 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:
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 as seq { (0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb") } .
|
||||||||||
|
Splits the input sequence into at most 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
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 as seq { [|1; 2|]; [|3; 4|]; [|5|] }
Example
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val splitInto: count: int -> source: 'T seq -> 'T array seq
Throws ArgumentException
|
||||||||||
Full Usage:
Seq.sum source
Parameters:
^T seq
-
The input sequence.
Returns: ^T
The computed sum.
Modifiers: inline Type parameters: ^T |
Returns the sum of the elements in the sequence.
The elements are summed using the
Example
val input: int list
module Seq
from Microsoft.FSharp.Collections
val sum: source: 'T seq -> 'T (requires member (+) and member Zero)
Evaluates 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 : 'T seq
-
The input sequence.
Returns: ^U
The computed sum.
Modifiers: inline Type parameters: 'T, ^U |
Returns the sum of the results generated by applying the function to each element of the sequence.
The generated elements are summed using the
Example
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 to 7 .
|
||||||||||
|
Returns a sequence that skips 1 element of the underlying sequence and then yields the remaining elements of the sequence.
Example
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 as seq { "bb"; "ccc" }
|
||||||||||
|
Returns the first N elements of the sequence.
Throws
Example
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"]
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val take: count: int -> source: 'T seq -> 'T seq
Throws InvalidOperationException .
Example
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.
Example
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 as seq { "a"; "bb" }
|
||||||||||
|
Builds an array from the given collection.
Example
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.
Example
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. 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
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.
Example
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 as seq { "a"; "b" }
Example
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 as seq { "a"; "b"; "c"; "d" }
Example
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
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val tryExactlyOne: source: 'T seq -> 'T option
Evaluates to Some banana
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val tryExactlyOne: source: 'T seq -> 'T option
Evaluates to None
Example
module Seq
from Microsoft.FSharp.Collections
val tryExactlyOne: source: 'T seq -> 'T option
Evaluates 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:
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val tryFind: predicate: ('T -> bool) -> source: 'T seq -> 'T option
val elm: int
Evaluates to Some 2
ExampleTry to find the first even number:
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val tryFind: predicate: ('T -> bool) -> source: 'T seq -> 'T option
val elm: int
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:
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val tryFindBack: predicate: ('T -> bool) -> source: 'T seq -> 'T option
val elm: int
Evaluates to Some 4
ExampleTry to find the first even number from the back:
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val tryFindBack: predicate: ('T -> bool) -> source: 'T seq -> 'T option
val elm: int
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:
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val tryFindIndex: predicate: ('T -> bool) -> source: 'T seq -> int option
val elm: int
Evaluates to Some 1
ExampleTry to find the index of the first even number:
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val tryFindIndex: predicate: ('T -> bool) -> source: 'T seq -> int option
val elm: int
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:
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val tryFindIndexBack: predicate: ('T -> bool) -> source: 'T seq -> int option
val elm: int
Evaluates to Some 3
ExampleTry to find the index of the first even number from the back:
val inputs: int list
module Seq
from Microsoft.FSharp.Collections
val tryFindIndexBack: predicate: ('T -> bool) -> source: 'T seq -> int option
val elm: int
Evaluates to None
|
||||||||||
|
Returns the first element of the sequence, or None if the sequence is empty.
Example
module Seq
from Microsoft.FSharp.Collections
val tryHead: source: 'T seq -> 'T option
Evaluates to Some "banana"
Example
module Seq
from Microsoft.FSharp.Collections
val tryHead: source: 'T seq -> 'T option
Evaluates to None
|
||||||||||
|
Tries to find the nth element in the sequence.
Returns
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val tryItem: index: int -> source: 'T seq -> 'T option
Evaluates to Some "b" .
Example
val inputs: string list
module Seq
from Microsoft.FSharp.Collections
val tryItem: index: int -> source: 'T seq -> 'T option
Evaluates to None .
|
||||||||||
|
Returns the last element of the sequence.
Return
Example
module Seq
from Microsoft.FSharp.Collections
val tryLast: source: 'T seq -> 'T option
Evaluates to Some "banana"
Example
module Seq
from Microsoft.FSharp.Collections
val tryLast: source: 'T seq -> 'T option
Evaluates to None
|
||||||||||
|
Applies the given function to successive elements, returning the first result where the function returns "Some(x)".
Example
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 to Some "2" .
Example
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 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: 'T seq
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
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 as seq { 1; 2; 4; 8; 16; 32; 64 }
Example
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 results seq { 1I; 2I; 4I; 8I; ... }
|
||||||||||
|
Return a new sequence with the item at a given index set to the new value.
Example
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 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
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 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
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 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
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 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
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 as seq { (1, "one", "I"); (2, "two", "II") } .
|