# Instance Methods

## map

It's `map`

, the most important method in programming! Exactly the same as ES6 `map`

, but lazy.

## window

`window`

takes a sequence and groups it into "windows" of a certain length. This works well with infinite sequences where you want to process some number of values at a time.

By default, only triggers chained responses when the window fills, guaranteeing the window is the exact size expect. Set `allowPartialWindow`

to `false`

to allow the trailing edge of a sequence to not be divisible by the window size.

## pairwise

Works like `window`

, makes the window size 2. Groups a sequence as alternating pairs. Useful for processing data which alternates Map keys and values.

## isEmpty

Ask whether a sequence is empty.

## tap

`tap`

lets you run side-effect generating functions on a sequence. Allows you to "tap in to" a data flow. Very useful for logging and debugging what values are flowing through the chain at a given location.

## log

`log`

provides the most common use-case for `tap. Add this to a sequence chain to log each value that passes through it.

## flat

Given a sequence where each item in an array of items, flatten all those arrays into a single flat sequence of values.

Works just like `Array.prototype.flat`

. See more here.

## flatMap

`flatMap`

is used when mapping a list to each items related items. For example, if you wanted to map from a list of people to each persons list of friends. Despite each mapping function returning an array, the final output is a flatten array of all the results concattenated.

Works just like `Array.prototype.flatMap`

. See more here.

Similar to `[].map().flat()`

, but in `leisure`

the item mappings won't execute until enough of the resulting values have been realized to trigger each map.

## filter

Runs a predicate function on each item in a sequence to produce a new sequence where only the values which responded with `true`

remain.

Exactly the same as `Array.prototype.filter`

, but lazy. See more here.

## concat

Combines the current sequence with 1 or more additional sequences.

Exactly the same as `Array.prototype.concat`

, but lazy. See more here.

## interleave

Takes 1 or more sequences and creates a new sequence built by pulling the next value from each of the sequences in order.

## interpose

Given a sequence, place a value between each value of the original sequence. Useful for adding punctuation between strings.

## distinct

Given a sequence, only forwards the values which have no already been seen. Very similar to lodash's `uniq`

method.

## distinctBy

Same as `distinct`

, but allows a function to describe on what value the sequence should be unique.

## partitionBy

Given a sequence, splits the values into two separate sequences. One represents the values where the partition function is `true`

and the other for `false`

.

## includes

Lazily checks if the sequence includes a value.

Exactly the same as `Array.prototype.includes`

, but lazy. See more here.

## find

Lazily searches for a value that matches the predicate.

Exactly the same as `Array.prototype.find`

, but lazy. See more here.

## reduce

Exactly the same as `Array.prototype.reduce`

. See more here. This causes a full realization of the data. Not lazy.

## chain

This method is helpful for chaining. Shocking, I know. Let's you "map" the entire sequence in a chain, rather than per-each-item. Allows adding arbitrary sequence helpers and methods to chain, even if they are written in user-land and not on the `Seq`

prototype.

## some

Exactly the same as `Array.prototype.some`

, but lazy. See more here.

## every

Exactly the same as `Array.prototype.every`

, but lazy. See more here.

## take

Given a sequence of unknown length, create a sub sequence of just the first X number of items.

## takeWhile

Given a sequence of unknown length, create a sub sequence of as many items in a row that satisfy the predicate.

## skip

Given a sequence of unknown length, skips the first X number of items.

## skipWhile

Given a sequence of unknown length, skip as many items in a row that satisfy the predicate.

## nth

Returns the `nth`

item. Items are 1-indexed.

## index

Returns the `index`

item. Items are 0-indexed.

## first

Gets the first value in the sequence.

## zip

Lazily combines a second sequence with this current one 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 a second sequence and lazily combines it 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.

## zip2

Takes two sequences and lazily combines them with this one to produce a 3-tuple with the current step in each of the three positions.

## zip2With

Takes two sequences and lazily combine them with this sequence to produce an arbitrary value by mapping the current value of the three positions through a user-supplied function.

## toArray

Converts the sequence to a real JavaScript array. Realizes the entire sequence.

## forEach

Works just like `Array.prototype.forEach`

. See more here. Realizes the full sequence.

## sum

Given a sequence of numbers, adds them all together. This realizes the entire sequence.

## sumBy

Given a sequence of arbitrary data, adds together the result of the mapping function. This realizes the entire sequence.

## average

Given a sequence of numbers, averages them all together. Tise realizes the entire sequence.

## averageBy

Given a sequence of arbitrary data, averages together the result of the mapping function. This realizes the entire sequence.

## frequencies

Given a non-infinite sequence, return a `Map`

which counts the occurances of each unique value. This realizes the entire sequence.

## groupBy

Group a sequence by the return of a mapping function. This realizes the entire sequence.

Last updated