[Home] Module Microsoft.FSharp.Collections.Seq


Basic operations on IEnumerables.

Values

ValueDescription
val append : seq<'T> -> seq<'T> -> seq<'T>
Wrap the two 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.
val average : overloaded
Return the average of the elements in the sequence The elements are averaged using the '+' operator, 'DivideByInt' method and 'Zero' property associated with the element type.
val averageBy : overloaded
Return the average of the results generated by applying the function to each element of the sequence. The elements are averaged using the '+' operator, 'DivideByInt' method and 'Zero' property associated with the generated type.
val cache : seq<'T> -> seq<'T>
Return a sequence that corresponds to a cached version of the input sequence. This 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. 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. Note, 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.
val cast : IEnumerable -> seq<'T>
Wrap 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.
val choose : ('T -> 'U option) -> seq<'T> -> seq<'U>
Apply the given function to each element of the list. Return the list 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. Remember sequence is lazy, effects are delayed until it is enumerated.
val collect : ('T -> #seq<'U>) -> seq<'T> -> seq<'U>
For each element of the enumeration apply the given function and concatenate all the results. Remember sequence is lazy, effects are delayed until it is enumerated.
val compare : ('T -> 'T -> int) -> seq<'T> -> seq<'T> -> int
Compare two sequence's using generic comparison, element by element.
val compareWith : ('T -> 'T -> int) -> seq<'T> -> seq<'T> -> int
Compare two sequence's using the given comparison function, element by element.
val concat : seq<#seq<'T>> -> seq<'T>
Wrap 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.
val countBy : ('T -> 'Key) -> seq<'T> -> seq<'Key * int>
Apply a key-generating function to each element of a sequence and return a sequence yielding unique keys and their number of occurences 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.
val delay : (unit -> seq<'T>) -> seq<'T>
Return a sequence that is built from the given delayed specification of an Seq. The input function is evaluated each time an IEnumerator for the sequence is requested.
val distinct : seq<'T> -> seq<'T>
Return 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.
val distinctBy : ('T -> 'Key) -> seq<'T> -> seq<'T>
Return 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.
[<GeneralizableValueAttribute ()>]
val empty<'T> : seq<'T>
Create an empty sequence
val exists : ('T -> bool) -> seq<'T> -> bool
Test 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.
val exists2 : ('T1 -> 'T2 -> bool) -> seq<'T1> -> seq<'T2> -> bool
Test 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.
val filter : ('T -> bool) -> seq<'T> -> seq<'T>
Return 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.
val find : ('T -> bool) -> seq<'T> -> 'T
Return the first element for which the given function returns true. Raise KeyNotFoundException if no such element exists.
val findIndex : ('T -> bool) -> seq<'T> -> int
Return the index of the first element in the sequence of pairs that satisfies the given predicate. Raise KeyNotFoundException if no such element exists.
val fold : ('State -> 'T -> 'State) -> 'State -> seq<'T> -> 'State
Apply 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
val forall : ('T -> bool) -> seq<'T> -> bool
Test 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.
val forall2 : ('T1 -> 'T2 -> bool) -> seq<'T1> -> seq<'T2> -> bool
Test the all pairs of elements drawn from the two sequences satisfies the given predicate. If one sequence is shorter than the other then the remaining elements of the longer sequence are ignored
val groupBy : ('T -> 'Key) -> seq<'T> -> seq<'Key * seq<'T>>
Apply a key-generating function to each element of a sequence and yields a sequence of unique keys. Each unique key has also contains a sequence of all elements that match to this key. 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.
val hd : seq<'T> -> 'T
Return the first element of the sequence.
val init : int -> (int -> 'T) -> seq<'T>
Generate a new sequence which, when iterated, will return successive elements by calling the given function, up to the given count. The results of calling the function will not be saved, i.e. 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.
val initInfinite : (int -> 'T) -> seq<'T>
Generate 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, i.e. 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.
val isEmpty : seq<'T> -> bool
Return true if the sequence contains no elements, false otherwise
val iter : ('T -> unit) -> seq<'T> -> unit
Apply the given function to each element of the collection.
val iter2 : ('T1 -> 'T2 -> unit) -> seq<'T1> -> seq<'T2> -> unit
Apply 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.
val iteri : (int -> 'T -> unit) -> seq<'T> -> unit
Apply the given function to each element of the collection. The integer passed to the function indicates the index of element.
val length : seq<'T> -> int
Return the length of the sequence
val map : ('T -> 'U) -> seq<'T> -> seq<'U>
Build 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. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
val map2 :
  ('T1 -> 'T2 -> 'U) -> seq<'T1> -> seq<'T2> -> seq<'U>
Build 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.
val mapi : (int -> 'T -> 'U) -> seq<'T> -> seq<'U>
Build 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.
val max : seq<'T> -> 'T
Return the greatest of all elements of the sequence, compared via Operators.max
val maxBy : ('T -> 'Key) -> seq<'T> -> 'T
Return the greatest of all elements of the array, compared via Operators.max on the function result
val min : seq<'T> -> 'T
Return the lowest of all elements of the sequence, compared via Operators.min
val minBy : ('T -> 'Key) -> seq<'T> -> 'T
Return the lowest of all elements of the array, compared via Operators.min on the function result
val nth : int -> seq<'T> -> 'T
Compute the nth element in the collection.
val of_array : 'T array -> seq<'T>
Build a collection from the given array
val of_list : 'T list -> seq<'T>
Build a collection from the given array
val pairwise : seq<'T> -> seq<'T * 'T>
Return 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.
val pick : ('T -> 'U option) -> seq<'T> -> 'U
Apply the given function to successive elements, returning the first 'x' where the function returns "Some(x)".
val readonly : seq<'T> -> seq<'T>
Build a new sequence object that delegates to the given sequence object. This ensures the original sequence can't 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 can't cast the returned sequence object to an array.
val reduce : ('T -> 'T -> 'T) -> seq<'T> -> 'T
Apply 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. Raises ArgumentException if the sequence has no elements.
val scan :
  ('State -> 'T -> 'State) -> 'State -> seq<'T> -> seq<'State>
Like fold, but compute on-demand and return the sequence of intermediary and final results
val singleton : 'T -> seq<'T>
Return a sequence that yields one item only.
val skip : int -> seq<'T> -> seq<'T>
Return a sequence that skips N elements of the underlying sequence and then yields the remaining elements of the sequence
val skipWhile : ('T -> bool) -> seq<'T> -> seq<'T>
Return 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
val sort : seq<'T> -> seq<'T>
Yield a sequence ordered by keys. 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.
val sortBy : ('T -> 'Key) -> seq<'T> -> seq<'T>
Apply 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. 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.
val sum : overloaded
Return the sum of the elements in the sequence. The elements are summed using the '+' operator and 'Zero' property associated with the generated type.
val sumBy : overloaded
Return the sum of the results generated by applying the function to each element of the sequence. The generated elements are summed using the '+' operator and 'Zero' property associated with the generated type.
val take : int -> seq<'T> -> seq<'T>
Return the first N elements of the sequence.
val takeWhile : ('T -> bool) -> seq<'T> -> seq<'T>
Return a sequence that, when iterated, yields elements of the underlying sequence while the given predicate returns 'true', and returns no further elements
val to_array : seq<'T> -> 'T array
Build an array from the given collection
val to_list : seq<'T> -> 'T list
Build a list from the given collection
val truncate : int -> seq<'T> -> seq<'T>
Return a sequence that when enumerated returns at most N elements.
val tryFind : ('T -> bool) -> seq<'T> -> 'T option
Return the first element for which the given function returns true. Return None if no such element exists.
val tryFindIndex : ('T -> bool) -> seq<'T> -> int option
Return the index of the first element in the sequence that satisfies the given predicate. Return 'None' if no such element exists.
val tryPick : ('T -> 'U option) -> seq<'T> -> 'U option
Apply the given function to successive elements, returning the first result where the function returns "Some(x)".
val unfold : ('State -> ('T * 'State) option) -> 'State -> seq<'T>
Return 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'. Note the stream will be recomputed each time an IEnumerator is requested and iterated for the Seq. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
val windowed : int -> seq<'T> -> seq<'T []>
Return a sequence that yields 'sliding windows' of containing elements drawn from the input sequence. Each window is returned as a fresh array.
val zip : seq<'T1> -> seq<'T2> -> seq<'T1 * 'T2>
Combine the two sequences into a list of pairs. The two sequences need not have equal lengths: when one sequence is exhausted any remaining elements in the other sequence are ignored.
val zip3 :
  seq<'T1> ->
    seq<'T2> -> seq<'T3> -> seq<'T1 * 'T2 * 'T3>
Combine the three sequences into a list of triples. The two sequences need not have equal lengths: when one sequence is exhausted any remaining elements in the other sequence are ignored.

See Also

Microsoft.FSharp.Collections


Documentation for assembly FSharp.Core, version 1.9.6.16, generated using F# Programming Language version 1.9.6.16