Static Methods
fromArray
Takes a normal JavaScript array and turns it into a Sequence of the same type.
const sequence: Seq<number> = fromArray([1, 2, 3])type fromArray<T> = (data: T[]) => Seq<T>iterate
The iterate method simplifies the construction of infinite sequences which are built using their previous value.
// Builds an infinite sequence that counts up from 0.
const sequence: Seq<number> = iterate(a => a + 1, 0)type iterate = <T>(fn: (current: T) => T, start: T): Seq<T>fib
The fib method generates a sequence of fibonacci numbers.
const sequence: Seq<number> = fib()type fib = () => Seq<number>random
Generates a random sequence using Math.random.
// Builds sequence of random numbers between 0 and 1.
const sequence: Seq<number> = random()type random = () => Seq<number>range
Creates a sequence that counts between a start and end value. Takes an optional step parameter.
infinite
A sequence that counts from 0 to Infinity.
of
A sequence with only a single value inside. Also known as "singleton."
cycle
Create a sequence that is the infinite repetition of a series of values.
repeat
Create a sequence which repeats the same value X number of times. The length of the sequence defaults to Infinity.
repeatedly
Creates a sequence which pulls from an impure callback to generate the sequence. The second parameter can cap the length of the sequence. By default, it will call the callback infinitely to generate values. Useful for asking about current time or cache values.
empty
A sequence with nothing in it. Useful as a "no op" for certain code-paths when joining sequences together.
zip
Takes two sequences and lazily combines them to produce a tuple with the current step in each of the two positions. Useful for zipping a sequence of keys with a sequence of values, before converting to a Map of key to value.
zipWith
Takes two sequences and lazily combines them to produce an arbitrary value by mapping the current value of the two positions through a user-supplied function. Useful for table (row/col) math.
zip3
Takes three sequences and lazily combines them to produce a 3-tuple with the current step in each of the three positions.
zip3With
Takes three sequences and lazily combines them to produce an arbitrary value by mapping the current value of the three positions through a user-supplied function.
concat
Combines 2 or more sequences into a single sequence.
interleave
Takes 2 or more sequences and creates a new sequence built by pulling the next value from each of the sequences in order.
Last updated
Was this helpful?