Home Reference Source

Function

Static Public Summary
public

Tests if a function holds true for all elements in an iterable.

public

Combines two iterables into one by pairing each element in the first with each element in the second.

public

Tests if a function holds true for any of the elements in an iterable.

public

Appends an object to the end of an iterable sequence.

public

Takes an iterable and returns a new iterable with all of the same elements but with a memory buffer.

public

Splits an iterable into chunks of a given size.

public

concat(ys: Object, xs: Object): Object

Concatenates two iterables into one.

public

Counts the number of elements in an iterable.

public

defaultComparison(i: *, j: *): *

public

dict(equality: *): {"get": *, "set": *}

public

distinctUntilChanged(e: Object=, xs: Object): Object

Takes an iterable and returns a new one with adjacent duplicate elements removed.

public

Takes an iterable and returns a new one including only elements that satisfy a given predicate.

public

first(f: Object=, xs: Object): Object

Returns the first element of an iterable that satisfies a given predicate.

public

Takes an iterable and returns a new one where each element is transformed using the given function.

public

Given an iterable returns a new iterable that repeats it forever.

public

Given an array, returns an iterable with equivalent elements.

public

Given a generator function, returns an iterable with equivalent elements.

public

groupBy(f: Object, equality: Object, xs: Object): Object

Returns an iterable of iterables split by the grouping function.

public

Returns the first element of an iterable.

public

includes(element: Object, equality: Object, xs: Object): boolean

Tests if a an iterable contains a given element.

public

indexed(xs: *)

public

intercalate(s: Object=, xs: Object): Object

Puts a given item between each element in a sequence.

public

Tests if a given object is an iterable

public

join(s: String=, xs: Object): String

Joins all elements in an iterable using the given seperator.

public

just(elements: ...Object): Object

Constructs an iterable from a fixed list of elements.

public

last(f: Object=, xs: Object): Object

Returns the last element of an iterable that satisfies a given predicate.

public

map(f: Object, xs: Object): Object

Takes an iterable and returns a new one where each element is transformed using the given function.

public

max(c: Object=, xs: Object): Object

Takes an iterable and returns the largest element, according to the given comparison.

public

min(c: Object=, xs: Object): Object

Takes an iterable and returns the smallest element, according to the given comparison.

public

none(f: Function=, xs: Object): boolean

Tests if a function holds true for none of the elements in an iterable.

public

nth(n: Number, xs: Object): Object

Returns the nth element of an iterable.

public

Takes an iterable and returns a new iterable that may only be iterated once.

public

Prepends an object to the start of an iterable sequence.

public

range(n: Number=): Object

Creates an iterable of numbers from zero to the given limit.

public

reduce(s: Object, f: Object, xs: Object): Object

Performs a reduction of an iterable, starting from a given state and reducer function.

public

Takes an iterable and returns a new iterable where the nth element has been skipped.

public

Repeats an iterable for the given number of times.

public

Given an iterable, returns a new iterable with the elements reversed.

public

set(n: Number, value: Object, xs: Object): Object

Takes an iterable and returns a new iterable where the nth element has been set to a given value.

public

single(f: Object=, xs: Object): Object

Returns the first element of an iterable that satisfies a given predicate.

public

skip(n: Number, xs: Object): Object

Skips the first n elements of an iterable.

public

Skips elements from an iterable for as long as the elements satisfy a given condition.

public

Deep flattens an iterable and all of its nested iterables.

public

sorted(c: Object=, xs: Object): Object

Given an iterable, returns a new iterable with the elements sorted.

public

sortedBy(f: *, c: *): *

public

sortedByDesc(f: *, c: *): *

public

sum(xs: Object): Number

Sums all elements in an iterable.

public

Returns an iterable of all elements except the first.

public

take(n: Number, xs: Object): Object

Takes the first n elements of an iterable.

public

Takes elements from an iterable for as long as the elements satisfy a given condition.

public

Takes an iterable and converts it into an array.

public

unique(e: Object=, xs: Object): Object

Takes an iterable and returns a new one with duplicate elements removed.

public

Takes an iterable and returns a new iterable where the nth element has been updated with the given function.

public

zip(ys: Object, xs: Object): Object

Combines two iterables into one by pairing elements.

Static Public

public all(f: Function, xs: Object): boolean source

import {all} from '@njlr/seq'

Tests if a function holds true for all elements in an iterable. Always returns true for an empty iterable. This function is curried.

Params:

NameTypeAttributeDescription
f Function

The condition to test for each element.

xs Object

The iterable.

Return:

boolean

public allPairs(xs: Object, ys: Object): Object source

import {allPairs} from '@njlr/seq'

Combines two iterables into one by pairing each element in the first with each element in the second. Each pair is a two element array. This function creates very long sequences for long inputs. This function is curried.

Params:

NameTypeAttributeDescription
xs Object

The iterable whose elements will be the second element of the pairs.

ys Object

The iterable whose elements will be the first element of the pairs.

Return:

Object

public any(f: Function, xs: Object): boolean source

import {any} from '@njlr/seq'

Tests if a function holds true for any of the elements in an iterable. Always returns false for an empty iterable. This function is curried.

Params:

NameTypeAttributeDescription
f Function

The condition to test for each element.

xs Object

The iterable.

Return:

boolean

public append(x: Object, xs: Object): Object source

import {append} from '@njlr/seq'

Appends an object to the end of an iterable sequence. This function is curried.

Params:

NameTypeAttributeDescription
x Object

The object to append.

xs Object

The iterable.

Return:

Object

public buffer(xs: Object): Object source

import {buffer} from '@njlr/seq'

Takes an iterable and returns a new iterable with all of the same elements but with a memory buffer. This can be used to prevent repeated computations.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

Object

public chunk(n: Number, xs: Object): Object source

import {chunk} from '@njlr/seq'

Splits an iterable into chunks of a given size. The last chunk may be less than the specified size. This function is curried.

Params:

NameTypeAttributeDescription
n Number

The chunk size.

xs Object

The iterable.

Return:

Object

public concat(ys: Object, xs: Object): Object source

import {concat} from '@njlr/seq'

Concatenates two iterables into one.
This function is curried.

Params:

NameTypeAttributeDescription
ys Object

The iterable to yield second.

xs Object

The iterable to yield first.

Return:

Object

public count(xs: Object): number source

import {count} from '@njlr/seq'

Counts the number of elements in an iterable.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

number

public defaultComparison(i: *, j: *): * source

import {defaultComparison} from '@njlr/seq'

Params:

NameTypeAttributeDescription
i *
j *

Return:

*

public dict(equality: *): {"get": *, "set": *} source

import {dict} from '@njlr/seq'

Params:

NameTypeAttributeDescription
equality *
  • optional
  • default: defaultEquality

Return:

{"get": *, "set": *}

public distinctUntilChanged(e: Object=, xs: Object): Object source

import {distinctUntilChanged} from '@njlr/seq'

Takes an iterable and returns a new one with adjacent duplicate elements removed. The order of the iterable is maintained. This function is curried.

Params:

NameTypeAttributeDescription
e Object=

The equality system to use.

xs Object

The iterable.

Return:

Object

public filter(f: Object, xs: Object): Object source

import {filter} from '@njlr/seq'

Takes an iterable and returns a new one including only elements that satisfy a given predicate.
The order of the iterable is maintained. This function is curried.

Params:

NameTypeAttributeDescription
f Object

The predicate.

xs Object

The iterable.

Return:

Object

public first(f: Object=, xs: Object): Object source

import {first} from '@njlr/seq'

Returns the first element of an iterable that satisfies a given predicate.
This function will throw an error if no satisfactory element is found.
This function is curried.

Params:

NameTypeAttributeDescription
f Object=

The predicate, defaults to always true.

xs Object

The iterable.

Return:

Object

public flatMap(f: Object, xs: Object): Object source

import {flatMap} from '@njlr/seq'

Takes an iterable and returns a new one where each element is transformed using the given function.
Unlike map, the function is expected to return an iterable for each element. These iterables are concatenated. The order of the iterable is maintained. This function is curried.

Params:

NameTypeAttributeDescription
f Object

The transformation function that returns an iterable.

xs Object

The iterable.

Return:

Object

public forever(xs: Object): Object source

import {forever} from '@njlr/seq'

Given an iterable returns a new iterable that repeats it forever. Take care, since the resulting iterable is infinite.

Params:

NameTypeAttributeDescription
xs Object

The iterable to repeat.

Return:

Object

public fromArray(xs: Object): Object source

import {fromArray} from '@njlr/seq'

Given an array, returns an iterable with equivalent elements. You should not mutate the array used to create the iterable.

Params:

NameTypeAttributeDescription
xs Object

The array.

Return:

Object

public fromGenerator(xs: Object): Object source

import {fromGenerator} from '@njlr/seq'

Given a generator function, returns an iterable with equivalent elements.

Params:

NameTypeAttributeDescription
xs Object

The generator function.

Return:

Object

public groupBy(f: Object, equality: Object, xs: Object): Object source

import {groupBy} from '@njlr/seq'

Returns an iterable of iterables split by the grouping function. If the iterable is empty then an error is thrown. This function is partially curried.

Params:

NameTypeAttributeDescription
f Object

the grouping function.

equality Object
  • optional
  • default: defaultEquality

The equality system to use.

xs Object

The iterable.

Return:

Object

public head(xs: Object): Object source

import {head} from '@njlr/seq'

Returns the first element of an iterable. If the iterable is empty then an error is thrown.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

Object

public includes(element: Object, equality: Object, xs: Object): boolean source

import {includes} from '@njlr/seq'

Tests if a an iterable contains a given element. Also takes an equality object as an optional argument. This function is partially curried.

Params:

NameTypeAttributeDescription
element Object

The element to look for.

equality Object
  • optional
  • default: defaultEquality

The equality system to use.

xs Object

The iterable to search.

Return:

boolean

public indexed(xs: *) source

import {indexed} from '@njlr/seq'

Params:

NameTypeAttributeDescription
xs *

public intercalate(s: Object=, xs: Object): Object source

import {intercalate} from '@njlr/seq'

Puts a given item between each element in a sequence.

Params:

NameTypeAttributeDescription
s Object=

The seperator item.

xs Object

The iterable to intercalate.

Return:

Object

public isIterable(xs: Object): Boolean source

import {isIterable} from '@njlr/seq'

Tests if a given object is an iterable

Params:

NameTypeAttributeDescription
xs Object

The object to test.

Return:

Boolean

public join(s: String=, xs: Object): String source

import {join} from '@njlr/seq'

Joins all elements in an iterable using the given seperator. If the iterable is empty then the empty string is returned.

Params:

NameTypeAttributeDescription
s String=

The seperator string.

xs Object

The iterable to join.

Return:

String

public just(elements: ...Object): Object source

import {just} from '@njlr/seq'

Constructs an iterable from a fixed list of elements. This function is variadic.

Params:

NameTypeAttributeDescription
elements ...Object

The elements of the iterable.

Return:

Object

public last(f: Object=, xs: Object): Object source

import {last} from '@njlr/seq'

Returns the last element of an iterable that satisfies a given predicate.
This function will throw an error if no satisfactory element is found.
This function is curried.

Params:

NameTypeAttributeDescription
f Object=

The predicate, defaults to always true.

xs Object

The iterable.

Return:

Object

public map(f: Object, xs: Object): Object source

import {map} from '@njlr/seq'

Takes an iterable and returns a new one where each element is transformed using the given function.
The order of the iterable is maintained. This function is curried.

Params:

NameTypeAttributeDescription
f Object

The transformation function.

xs Object

The iterable.

Return:

Object

public max(c: Object=, xs: Object): Object source

import {max} from '@njlr/seq'

Takes an iterable and returns the largest element, according to the given comparison. This function is curried.

Params:

NameTypeAttributeDescription
c Object=

The comparison.

xs Object

The iterable.

Return:

Object

public min(c: Object=, xs: Object): Object source

import {min} from '@njlr/seq'

Takes an iterable and returns the smallest element, according to the given comparison. This function is curried.

Params:

NameTypeAttributeDescription
c Object=

The comparison.

xs Object

The iterable.

Return:

Object

public none(f: Function=, xs: Object): boolean source

import {none} from '@njlr/seq'

Tests if a function holds true for none of the elements in an iterable. Always returns true for an empty iterable. By default, this function returns false for an iterable with any elements. This function is curried.

Params:

NameTypeAttributeDescription
f Function=

The condition to test for each element.

xs Object

The iterable.

Return:

boolean

public nth(n: Number, xs: Object): Object source

import {nth} from '@njlr/seq'

Returns the nth element of an iterable.
This function will throw an error if the iterable is not long enough.
This function is curried.

Params:

NameTypeAttributeDescription
n Number

The zero-based index of the element to return.

xs Object

The iterable.

Return:

Object

public once(xs: Object): Object source

import {once} from '@njlr/seq'

Takes an iterable and returns a new iterable that may only be iterated once. This function is useful for debugging purposes.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

Object

public prepend(x: Object, xs: Object): Object source

import {prepend} from '@njlr/seq'

Prepends an object to the start of an iterable sequence. This function is curried.

Params:

NameTypeAttributeDescription
x Object

The object to prepend.

xs Object

The iterable.

Return:

Object

public range(n: Number=): Object source

import {range} from '@njlr/seq'

Creates an iterable of numbers from zero to the given limit.

Params:

NameTypeAttributeDescription
n Number=

The number to count to.

Return:

Object

public reduce(s: Object, f: Object, xs: Object): Object source

import {reduce} from '@njlr/seq'

Performs a reduction of an iterable, starting from a given state and reducer function. Note that this function must not be called on an infinite iterable. This function is partially curried.

Params:

NameTypeAttributeDescription
s Object

The initial state.

f Object

The reducer function.

xs Object

The iterable.

Return:

Object

public remove(n: Number, xs: Object): Object source

import {remove} from '@njlr/seq'

Takes an iterable and returns a new iterable where the nth element has been skipped.
This function is curried.

Params:

NameTypeAttributeDescription
n Number

The index of the element to replace.

xs Object

The iterable.

Return:

Object

public repeat(n: Number, xs: Object): Object source

import {repeat} from '@njlr/seq'

Repeats an iterable for the given number of times. This function is curried.

Params:

NameTypeAttributeDescription
n Number

The number of repetitions.

xs Object

The iterable.

Return:

Object

public reverse(xs: Object): Object source

import {reverse} from '@njlr/seq'

Given an iterable, returns a new iterable with the elements reversed. Note that this function must not be called on an infinite iterable.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

Object

public set(n: Number, value: Object, xs: Object): Object source

import {set} from '@njlr/seq'

Takes an iterable and returns a new iterable where the nth element has been set to a given value.
This function is curried.

Params:

NameTypeAttributeDescription
n Number

The index of the element to replace.

value Object

The new value.

xs Object

The iterable.

Return:

Object

public single(f: Object=, xs: Object): Object source

import {single} from '@njlr/seq'

Returns the first element of an iterable that satisfies a given predicate.
This function will throw an error if no satisfactory element is found.
This function is curried.

Params:

NameTypeAttributeDescription
f Object=

The predicate, defaults to always true.

xs Object

The iterable.

Return:

Object

public skip(n: Number, xs: Object): Object source

import {skip} from '@njlr/seq'

Skips the first n elements of an iterable. If there are fewer than n elements in an iterable, then an empty iterable will be returned. This function is curried.

Params:

NameTypeAttributeDescription
n Number

The number of elements to skip.

xs Object

The iterable.

Return:

Object

public skipUntil(f: Object, xs: Object): Object source

import {skipUntil} from '@njlr/seq'

Skips elements from an iterable for as long as the elements satisfy a given condition. The first element that satisfies the condition will be included. This function is curried.

Params:

NameTypeAttributeDescription
f Object

The function.

xs Object

The iterable.

Return:

Object

public smoosh(xs: Object): Object source

import {smoosh} from '@njlr/seq'

Deep flattens an iterable and all of its nested iterables. Strings are not considered iterables for this function.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

Object

public sorted(c: Object=, xs: Object): Object source

import {sorted} from '@njlr/seq'

Given an iterable, returns a new iterable with the elements sorted. Note that this function must not be called on an infinite iterable.

Params:

NameTypeAttributeDescription
c Object=

The comparison function to use.

xs Object

The iterable.

Return:

Object

public sortedBy(f: *, c: *): * source

import {sortedBy} from '@njlr/seq'

Params:

NameTypeAttributeDescription
f *
c *
  • optional
  • default: defaultComparison

Return:

*

public sortedByDesc(f: *, c: *): * source

import {sortedByDesc} from '@njlr/seq'

Params:

NameTypeAttributeDescription
f *
c *
  • optional
  • default: defaultComparison

Return:

*

public sum(xs: Object): Number source

import {sum} from '@njlr/seq'

Sums all elements in an iterable. If the iterable is empty then zero is returned.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

Number

public tail(xs: Object): Object source

import {tail} from '@njlr/seq'

Returns an iterable of all elements except the first. If the iterable is empty then an error is thrown.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

Object

public take(n: Number, xs: Object): Object source

import {take} from '@njlr/seq'

Takes the first n elements of an iterable. If there are fewer than n elements in an iterable, then this has no effect. This function is curried.

Params:

NameTypeAttributeDescription
n Number

The number of elements to take.

xs Object

The iterable.

Return:

Object

public takeWhile(f: Object, xs: Object): Object source

import {takeWhile} from '@njlr/seq'

Takes elements from an iterable for as long as the elements satisfy a given condition. The first element that does satisfies the condition will not be included. This function is curried.

Params:

NameTypeAttributeDescription
f Object

The function.

xs Object

The iterable.

Return:

Object

public toArray(xs: Object): Array source

import {toArray} from '@njlr/seq'

Takes an iterable and converts it into an array. This should only be called on finite iterables.

Params:

NameTypeAttributeDescription
xs Object

The iterable.

Return:

Array

public unique(e: Object=, xs: Object): Object source

import {unique} from '@njlr/seq'

Takes an iterable and returns a new one with duplicate elements removed.
The order of the iterable is maintained. This function is curried.

Params:

NameTypeAttributeDescription
e Object=

The equality system to use.

xs Object

The iterable.

Return:

Object

public update(n: Number, f: Function, xs: Object): Object source

import {update} from '@njlr/seq'

Takes an iterable and returns a new iterable where the nth element has been updated with the given function.
This function is curried.

Params:

NameTypeAttributeDescription
n Number

The index of the element to replace.

f Function

The update function.

xs Object

The iterable.

Return:

Object

public zip(ys: Object, xs: Object): Object source

import {zip} from '@njlr/seq'

Combines two iterables into one by pairing elements. Each pair is a two element array. The longer of the two iterables will be truncated to match the length of the shorter one.
This function is curried.

Params:

NameTypeAttributeDescription
ys Object

The iterable whose elements will be the second element of the pairs.

xs Object

The iterable whose elements will be the first element of the pairs.

Return:

Object