Repeating sequences can be created using a seq {} computation expression

Introduction to sequences

A sequence is a series of elements that can be enumerated. It is an alias of System.Collections.Generic.IEnumerable and lazy. It stores a series of elements of the same type (can be any value or object, even another sequence). Functions from the Seq.module can be used to operate on it.

Here is a simple example of a sequence enumeration:

Output:

Seq.filter

Suppose that we have a sequence of integers and we want to create a sequence that contains only the even integers. We can obtain the latter by using the filter function of the Seq module. The filter function has the type signature ('a -> bool) -> seq<'a> -> seq<'a>; this indicates that it accepts a function that returns true or false (sometimes called a predicate) for a given input of type 'a and a sequence that comprises values of type 'a to yield a sequence that comprises values of type 'a.

Seq.map

Apply a function to every element of a sequence using Seq.map

This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0