extra-iterable

  • Version 3.2.19
  • Published
  • 130 kB
  • No dependencies
  • MIT license

Install

npm i extra-iterable
yarn add extra-iterable
pnpm add extra-iterable

Overview

An iterable is a sequence of values.

Index

Variables

variable END

const END: number;
  • End of iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/END)

Functions

function accumulate

accumulate: <T, U = T>(
x: Iterable<T>,
fr: ReduceFunction<T, T | U>,
acc?: T | U
) => IterableIterator<T | U>;
  • Produce accumulating values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/accumulate)

    Parameter x

    an iterable

    Parameter fr

    reduce function (acc, v, i, x)

    Parameter acc

    initial value

    Returns

    fr(acc, vโ‚€), fr(fr(acc, vโ‚€), vโ‚), ... | fr(acc, vโ‚€) = vโ‚€ if acc not given

function callable

callable: <T>(x: Iterable<T>) => () => T;
  • Generate a function that iterates over values upon invocation. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/toInvokable)

    Parameter x

    an iterable

    Returns

    fn | fn() โ†’ x[0], fn() โ†’ x[1], ...

function cartesianProduct

cartesianProduct: <T, U = T>(
xs: Iterable<T>[],
fm?: MapFunction<T[], T[] | U> | null
) => IterableIterator<T[] | U>;
  • List cartesian product of iterables. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/cartesianProduct)

    Parameter xs

    iterables

    Parameter fm

    map function (vs, i)

    Returns

    xโ‚€ ร— xโ‚ ร— ... = {[vโ‚€, vโ‚, ...] | vโ‚€ โˆˆ xโ‚€, vโ‚ โˆˆ xโ‚, ...] }

function chunk

chunk: <T>(x: Iterable<T>, n?: number, s?: number) => IterableIterator<T[]>;
  • Break iterable into chunks of given size. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/chunk)

    Parameter x

    an iterable

    Parameter n

    chunk size [1]

    Parameter s

    chunk step [n]

    Returns

    x[0..n], x[s..s+n], x[2s..2s+n], ...

function compare

compare: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => number;
  • Compare two iterables. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/compare)

    Parameter x

    an iterable

    Parameter y

    another iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x<y: -1, x=y: 0, x>y: 1

function concat

concat: <T>(...xs: Iterable<T>[]) => IterableIterator<T>;
  • Append values from iterables. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/concat)

    Parameter xs

    iterables

    Returns

    ...xโ‚€, ...xโ‚, ... | [xโ‚€, xโ‚, ...] = xs

function copy

copy: <T>(
x: Iterable<T>,
y: Iterable<T>,
j?: number,
i?: number,
I?: number
) => IterableIterator<T>;
  • Copy part of iterable to another. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/copy)

    Parameter x

    target iterable

    Parameter y

    source iterable

    Parameter j

    write index [0]

    Parameter i

    read start index [0]

    Parameter I

    read end index [END]

    Returns

    x[0..j] โงบ y[i..I] โงบ x[j+I-i..]

function copyWithin

copyWithin: <T>(
x: Iterable<T>,
j?: number,
i?: number,
I?: number
) => IterableIterator<T>;
  • Copy part of iterable within. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/copyWithin)

    Parameter x

    an iterable

    Parameter j

    write index [0]

    Parameter i

    read start index [0]

    Parameter I

    read end index [END]

    Returns

    x[0..j] โงบ x[i..I] โงบ x[j+I-i..]

function count

count: <T>(x: Iterable<T>, ft: TestFunction<T>) => number;
  • Count values which satisfy a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/count)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    ฮฃtแตข | tแตข = 1 if ft(vแตข) else 0; vแตข โˆˆ x

function countAs

countAs: <T, U = T>(
x: Iterable<T>,
fm?: MapFunction<T, T | U> | null
) => Map<T | U, number>;
  • Count occurrences of values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/countAs)

    Parameter x

    an array

    Parameter fm

    map function (v, i, x)

    Returns

    Map {value โ‡’ count}

function cut

cut: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T[]>;
  • Break iterable when test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/cut)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    x[0..j] โงบ x[j..k] โงบ ... | ft(x[i]) = true; i = j, k, ...

function cutAt

cutAt: <T>(x: Iterable<T>, is: Iterable<number>) => IterableIterator<T[]>;
  • Break iterable at given indices. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/cutAt)

    Parameter x

    an iterable

    Parameter is

    split indices (sorted)

    Returns

    x[0..j] โงบ x[j..k] โงบ ... | ft(x[i]) = true; i = j, k, ...; i โˆˆ is

function cutAtRight

cutAtRight: <T>(x: Iterable<T>, is: Iterable<number>) => IterableIterator<T[]>;
  • Break iterable after given indices. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/cutAtRight)

    Parameter x

    an iterable

    Parameter is

    split indices (sorted)

    Returns

    x[0..j+1] โงบ x[j+1..k] โงบ ... | ft(x[i]) = true; i = j, k, ...; i โˆˆ is

function cutRight

cutRight: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T[]>;
  • Break iterable after test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/cutRight)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    x[0..j+1] โงบ x[j+1..k] โงบ ... | ft(x[i]) = true; i = j, k, ...

function cycle

cycle: <T>(x: Iterable<T>, i?: number, n?: number) => IterableIterator<T>;
  • Obtain values that cycle through an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/cycle)

    Parameter x

    an iterable

    Parameter i

    start index [0]

    Parameter n

    number of values [-1 โ‡’ Inf]

    Returns

    x[i..] โงบ x โงบ x โงบ ... with upto n values

function difference

difference: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<T>;
  • Obtain values not present in another iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/difference)

    Parameter x

    an iterable

    Parameter y

    another iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x - y = {v | v โˆˆ x, v โˆ‰ y}

function drop

drop: <T>(x: Iterable<T>, n?: number) => IterableIterator<T>;
  • Discard first n values only. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/drop)

    Parameter x

    an iterable

    Parameter n

    number of values [1]

    Returns

    x[n..]

function dropRight

dropRight: <T>(x: Iterable<T>, n?: number) => IterableIterator<T>;
  • Discard last n values only. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/dropRight)

    Parameter x

    an iterable

    Parameter n

    number of values [1]

    Returns

    x[0..-n]

function dropWhile

dropWhile: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T>;
  • Discard values from left, while a test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/dropWhile)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    x[T..] | ft(x[i]) = true โˆ€ i โˆˆ [0, T-1] & ft(x[T]) = false

function dropWhileRight

dropWhileRight: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T>;
  • Discard values from right, while a test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/dropWhileRight)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    x[0..T-1] | ft(x[i]) = true โˆ€ i โˆˆ [T, |x|-1] & ft(x[T-1]) = false

function entries

entries: <T>(x: Iterable<T>) => IterableIterator<[number, T]>;
  • List all index-value pairs. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/entries)

    Parameter x

    an iterable

    Returns

    [0, vโ‚€], [1, vโ‚], ... | vแตข = x[i]

function every

every: <T>(x: Iterable<T>, ft?: TestFunction<T> | null) => boolean;
  • Check if all values satisfy a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/every)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    true if ft(vแตข) = true for all vแตข โˆˆ x

function fill

fill: <T>(x: Iterable<T>, v: T, i?: number, I?: number) => IterableIterator<T>;
  • Fill with given value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/fill)

    Parameter x

    an iterable

    Parameter v

    value

    Parameter i

    start index [0]

    Parameter I

    end index [END]

    Returns

    x' | x' = x; x'[i..I] = v

function filter

filter: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T>;
  • Keep the values which pass a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/filter)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    vโ‚€, vโ‚, ... | ft(vแตข) = true; vแตข โˆˆ x

function filterAt

filterAt: <T>(x: Iterable<T>, is: number[]) => IterableIterator<T>;
  • Keep the values at given indices. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/filterAt)

    Parameter x

    an iterable

    Parameter is

    indices (sorted)

    Returns

    vโ‚€, vโ‚, ... | vแตข = x[i]; i โˆˆ is

function find

find: <T>(x: Iterable<T>, ft: TestFunction<T>) => T;
  • Find first value passing a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/find)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    first v | ft(v) = true; v โˆˆ x

function findAll

findAll: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T>;
  • Keep the values which pass a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/filter)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    vโ‚€, vโ‚, ... | ft(vแตข) = true; vแตข โˆˆ x

function findRight

findRight: <T>(x: Iterable<T>, ft: TestFunction<T>) => T;
  • Find last value passing a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/findRight)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    last v | ft(v) = true; v โˆˆ x

function flat

flat: (
x: Iterable<any>,
n?: number,
fm?: MapFunction<any, any> | null,
ft?: TestFunction<any> | null
) => IterableIterator<any>;
  • Flatten nested iterable to given depth. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/flat)

    Parameter x

    a nested iterable

    Parameter n

    maximum depth (-1 โ‡’ all)

    Parameter fm

    map function (v, i, x)

    Parameter ft

    flatten test (v, i, x) [isList]

    Returns

    flat iterable

function flatMap

flatMap: (
x: Iterable<any>,
fm?: MapFunction<any, any> | null,
ft?: TestFunction<any> | null
) => IterableIterator<any>;
  • Flatten nested iterable, based on map function. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/flatMap)

    Parameter x

    a nested iterable

    Parameter fm

    map function (v, i, x)

    Parameter ft

    flatten test (v, i, x) [isList]

    Returns

    flat iterable

function forEach

forEach: <T>(x: Iterable<T>, fp: ProcessFunction<T>) => void;
  • Call a function for each value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/forEach)

    Parameter x

    an iterable

    Parameter fp

    process function (v, i, x)

function from

from: <T>(x: Iterator<T> | Iterable<T>) => Iterable<T>;
  • Convert an iterable-like to iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/from)

    Parameter x

    an iterator/iterable

    Returns

    x as iterable

function fromApplication

fromApplication: <T>(fm: MapFunction<T, T>, v: T) => IterableIterator<T>;
  • Generate iterable from repeated function application. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/fromApplication)

    Parameter fm

    map function (v, i)

    Parameter v

    start value

    Returns

    v, fm(v), fm(fm(v)), ...

function fromApply

fromApply: <T>(fm: MapFunction<T, T>, v: T) => IterableIterator<T>;
  • Generate iterable from repeated function application. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/fromApplication)

    Parameter fm

    map function (v, i)

    Parameter v

    start value

    Returns

    v, fm(v), fm(fm(v)), ...

function fromCall

fromCall: <T>(fn: Function, ...args: any[]) => IterableIterator<T>;
  • Generate iterable from repeated function invocation. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/fromInvocation)

    Parameter fn

    function (impure)

    Parameter args

    arguments

    Returns

    fn(...args), fn(...args), ...

function fromInvocation

fromInvocation: <T>(fn: Function, ...args: any[]) => IterableIterator<T>;
  • Generate iterable from repeated function invocation. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/fromInvocation)

    Parameter fn

    function (impure)

    Parameter args

    arguments

    Returns

    fn(...args), fn(...args), ...

function fromIterator

fromIterator: <T>(x: Iterator<T>) => Iterable<T>;
  • Convert an iterator to iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/fromIterator)

    Parameter x

    an iterator/iterable

    Returns

    x as iterable

function fromRange

fromRange: (v?: number, V?: number, dv?: number) => IterableIterator<number>;
  • Generate iterable from given number range. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/fromRange)

    Parameter v

    start number [0]

    Parameter V

    stop number, excluding [END]

    Parameter dv

    step size [1]

    Returns

    v, v+dv, v+2dv, ...

function get

get: <T>(x: Iterable<T>, i: number) => T;
  • Get value at index. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/get)

    Parameter x

    an iterable

    Parameter i

    index

    Returns

    x[i]

function getAll

getAll: <T>(x: Iterable<T>, is: number[]) => IterableIterator<T>;
  • Get values at indices. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/getAll)

    Parameter x

    an iterable

    Parameter is

    indices (sorted)

    Returns

    x[iโ‚€], x[iโ‚], ... | [iโ‚€, iโ‚, ...] = is

function getPath

getPath: (x: Iterable<any>, p: number[]) => any;
  • Get value at path in a nested iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/getPath)

    Parameter x

    a nested iterable

    Parameter p

    path

    Returns

    x[iโ‚€][iโ‚][...] | [iโ‚€, iโ‚, ...] = p

function group

group: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<T[]>;
  • Keep similar values together and in order. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/group)

    Parameter x

    an iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x[0..k], x[k..l], ... | fc(x[i], x[j]) = 0; i, j = 0..k / k..l / ...

function hasInfix

hasInfix: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => boolean;
  • Check if iterable contains an infix. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/hasInfix)

    Parameter x

    an iterable

    Parameter y

    search infix

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x[i..I] = y for some i, I?

function hasPath

hasPath: (x: Iterable<any>, p: number[]) => boolean;
  • Check if nested iterable has a path. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/hasPath)

    Parameter x

    a nested iterable

    Parameter p

    path

    Returns

    x[iโ‚€][iโ‚][...] exists? | [iโ‚€, iโ‚, ...] = p

function hasPrefix

hasPrefix: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => boolean;
  • Check if iterable starts with a prefix. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/hasPrefix)

    Parameter x

    an iterable

    Parameter y

    search prefix

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x[0..|y|] = y?

function hasSubsequence

hasSubsequence: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => boolean;
  • Check if iterable has a subsequence. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/hasSubsequence)

    Parameter x

    an iterable

    Parameter y

    search subsequence

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x[iโ‚€] โงบ x[iโ‚] โงบ ... = y, for some iโ‚€, iโ‚, ...? | iโ‚€ < iโ‚ < ...

function hasSuffix

hasSuffix: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => boolean;
  • Check if iterable ends with a suffix. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/hasSuffix)

    Parameter x

    an iterable

    Parameter y

    seach suffix

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x[|x|-|y|..] = y?

function hasValue

hasValue: <T, U = T>(
x: Iterable<T>,
v: T,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => boolean;
  • Check if iterable has a value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/hasValue)

    Parameter x

    an iterable

    Parameter v

    search value

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    v โˆˆ x?

head: <T>(x: Iterable<T>, vd?: T) => T;
  • Get first value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/head)

    Parameter x

    an iterable

    Parameter vd

    default value

    Returns

    x[0] || vd

function includes

includes: <T>(x: Iterable<T>, v: T, i?: number) => boolean;
  • Check if iterable has a value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/includes)

    Parameter x

    an iterable

    Parameter v

    search value

    Parameter i

    start index [0]

    Returns

    v โˆˆ x[i..]?

function index

index: <T>(x: Iterable<T>, i: number) => number;
  • Get zero-based index for element in iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/index)

    Parameter x

    an iterable

    Parameter i

    index (-ve: from right)

    Returns

    i' | x[i'] = x[i]; i' โˆˆ [0, |x|]

function indexOf

indexOf: <T>(x: Iterable<T>, v: T, i?: number) => number;
  • Find first index of a value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/indexOf)

    Parameter x

    an iterable

    Parameter v

    search value

    Parameter i

    start index [0]

    Returns

    index of v in x[i..] if found else -1

function indexRange

indexRange: <T>(x: Iterable<T>, i?: number, I?: number) => [number, number];
  • Get index range for part of iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/indexRange)

    Parameter x

    an iterable

    Parameter i

    start index (-ve: from right) [0]

    Parameter I

    end index (-ve: from right) [END]

    Returns

    [i', I'] | i' โ‰ค I'; i', I' โˆˆ [0, |x|]

function init

init: <T>(x: Iterable<T>) => IterableIterator<T>;
  • Get values except last. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/init)

    Parameter x

    an iterable

    Returns

    x[0..|x|-1]

function interleave

interleave: <T>(xs: Iterable<T>[]) => IterableIterator<T>;
  • Place values from iterables alternately. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/interleave)

    Parameter xs

    iterables

    Returns

    xโ‚€[0], xโ‚[0], ..., xโ‚€[1], xโ‚[0], ... | [xโ‚€, xโ‚, ...] = xs

function intermix

intermix: <T>(
x: Iterable<T>,
y: Iterable<T>,
m?: number,
n?: number,
s?: number,
t?: number
) => IterableIterator<T>;
  • Place values of an iterable between another. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/intermix)

    Parameter x

    an iterable

    Parameter y

    another iterable

    Parameter m

    number of values from x [1]

    Parameter n

    number of values from y [1]

    Parameter s

    step size for x [m]

    Parameter t

    step size for y [n]

    Returns

    x[0..m], y[0..n], x[s..s+m], y[t..t+n], ..., x[k*s..|x|-1] | k โˆˆ W

function interpolate

interpolate: <T>(x: Iterable<T>, fc: CombineFunction<T>) => IterableIterator<T>;
  • Estimate new values between existing ones. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/interpolate)

    Parameter x

    an iterable

    Parameter fc

    combine function (a, b)

    Returns

    x[0], fc(x[0], x[1]), x[1], fc(x[1], x[2]), ..., x[|x|-1]

function intersection

intersection: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<T>;
  • Obtain values present in both iterables. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/intersection)

    Parameter x

    an iterable

    Parameter y

    another iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x โˆฉ y = {v | v โˆˆ x, v โˆˆ y}

function intersperse

intersperse: <T>(x: Iterable<T>, v: T) => IterableIterator<T>;
  • Place a separator between every value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/intersperse)

    Parameter x

    an iterable

    Parameter v

    separator

    Returns

    x[0], v, x[1], v, ..., x[|x|-1]

function is

is: (v: any) => v is Iterable<any>;
  • Check if value is an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/is)

    Parameter v

    a value

    Returns

    v is iterable?

function isDisjoint

isDisjoint: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => boolean;
  • Checks if arrays have no value in common. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/isDisjoint)

    Parameter x

    an array

    Parameter y

    another array

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x โˆฉ y = ฮฆ?

function isEmpty

isEmpty: <T>(x: Iterable<T>) => boolean;
  • Check if an iterable is empty. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/isEmpty)

    Parameter x

    an iterable

    Returns

    |x| = 0?

function isEqual

isEqual: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => boolean;
  • Check if two iterables are equal. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/isEqual)

    Parameter x

    an iterable

    Parameter y

    another iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x=y?

function isIterator

isIterator: (v: any) => v is Iterator<any, any, undefined>;
  • Check if value is an iterator. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/isIterator)

    Parameter v

    a value

    Returns

    v implements {next(), return?(), throw?()}?

function isList

isList: <T>(v: Iterable<T>) => boolean;
  • Check if value is a list (iterable & !string). [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/isList)

    Parameter v

    a value

    Returns

    v is list?

function isMany

isMany: <T>(x: Iterable<T>) => x is Iterable<T>;
  • Check if an iterable can be iterated many times. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/isMany)

    Parameter x

    an iterable

    Returns

    x[<iterator>] โ‰  x?

function isOnce

isOnce: <T>(x: Iterable<T>) => x is IterableIterator<T>;
  • Check if an iterable can iterated only once. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/isOnce)

    Parameter x

    an iterable

    Returns

    x[<iterator>] = x?

function isUnique

isUnique: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => boolean;
  • Check if there are no duplicate values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/isUnique)

    Parameter x

    an array

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    โˆ€ vแตข, vโฑผ โˆˆ x, is vแตข โ‰  vโฑผ?

function iterator

iterator: <T>(x: Iterable<T>) => Iterator<T>;
  • Get iterator of an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/iterator)

    Parameter x

    an iterable

    Returns

    x[<iterator>]()

function join

join: <T>(x: Iterable<T>, sep?: string) => string;
  • Join values together into a string. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/join)

    Parameter x

    an iterable

    Parameter sep

    separator [,]

    Returns

    "${vโ‚€}${sep}${vโ‚}..." | vแตข โˆˆ x

function keys

keys: <T>(x: Iterable<T>) => IterableIterator<number>;
  • List all indices. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/keys)

    Parameter x

    an iterable

    Returns

    0, 1, ..., |x|-1

function last

last: <T>(x: Iterable<T>, vd?: T) => T;
  • Get last value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/last)

    Parameter x

    an iterable

    Parameter vd

    default value

    Returns

    x[|x|-1]

function lastIndexOf

lastIndexOf: <T>(x: Iterable<T>, v: T, i?: number) => number;
  • Find last index of a value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/lastIndexOf)

    Parameter x

    an iterable

    Parameter v

    search value

    Parameter i

    start index [END-1]

    Returns

    last index of v in x[0..i] if found else -1

function left

left: <T>(x: Iterable<T>, n: number) => IterableIterator<T>;
  • Get values from left. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/left)

    Parameter x

    an iterable

    Parameter n

    number of values

    Returns

    x[0..n]

function length

length: <T>(x: Iterable<T>, i?: number, I?: number) => number;
  • Find the length of an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/length)

    Parameter x

    an iterable

    Parameter i

    start index [0]

    Parameter I

    end index [END]

    Returns

    |x[i..I]|

function many

many: <T>(x: Iterable<T>, now?: boolean) => Iterable<T>;
  • Convert a once-like iterable to many. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/toMany)

    Parameter x

    an iterable

    Parameter now

    consume immediately? [false]

    Returns

    x' | x' = x; x' can be iterated multiple times

function map

map: <T, U>(x: Iterable<T>, fm: MapFunction<T, U>) => IterableIterator<U>;
  • Transform values of an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/map)

    Parameter x

    an iterable

    Parameter fm

    map function (v, i, x)

    Returns

    fm(vโ‚€), fm(vโ‚), ... | vแตข โˆˆ x

function max

max: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => T;
  • Find largest value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/max)

    Parameter x

    an iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    v | v โ‰ฅ vแตข; vแตข โˆˆ x

function maxEntry

maxEntry: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => [number, T];
  • Find largest entry. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/maxEntry)

    Parameter x

    an iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    [max_index, max_value]

function merge

merge: <T, U = T>(
xs: Iterable<T>[],
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<T>;
  • Merge values from sorted iterables. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/merge)

    Parameter xs

    iterables

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    sort(concat(...xs))

function middle

middle: <T>(x: Iterable<T>, i: number, n?: number) => IterableIterator<T>;
  • Get values from middle. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/middle)

    Parameter x

    an iterable

    Parameter i

    start index

    Parameter n

    number of values [1]

    Returns

    x[i..i+n]

function min

min: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => T;
  • Find smallest value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/min)

    Parameter x

    an iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    v | v โ‰ค vแตข; vแตข โˆˆ x

function minEntry

minEntry: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => [number, T];
  • Find smallest entry. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/minEntry)

    Parameter x

    an iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    [min_index, min_value]

function moveWithin

moveWithin: <T>(
x: Iterable<T>,
j?: number,
i?: number,
I?: number
) => IterableIterator<T>;
  • Move part of iterable within. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/moveWithin)

    Parameter x

    an iterable

    Parameter j

    write index [0]

    Parameter i

    read start index [0]

    Parameter I

    read end index [END]

    Returns

    x[0..j] โงบ x[i..I] โงบ x[j..i] โงบ x[I..]

function partition

partition: <T>(x: Iterable<T>, ft: TestFunction<T>) => [T[], T[]];
  • Segregate values by test result. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/partition)

    Parameter x

    an array

    Parameter ft

    test function (v, i, x)

    Returns

    [satisfies, doesnt]

function partitionAs

partitionAs: <T, U = T>(
x: Iterable<T>,
fm?: MapFunction<T, T | U> | null
) => Map<T | U, T[]>;
  • Segregate values by similarity. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/partitionAs)

    Parameter x

    an array

    Parameter fm

    map function (v, i, x)

    Returns

    Map {key โ‡’ values}

function pop

pop: <T>(x: Iterable<T>) => IterableIterator<T>;
  • Get values except last. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/init)

    Parameter x

    an iterable

    Returns

    x[0..|x|-1]

function push

push: <T>(x: Iterable<T>, ...vs: T[]) => IterableIterator<T>;
  • Add values to the end. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/push)

    Parameter x

    an iterable

    Parameter vs

    values to add

    Returns

    ...x, ...vs

function range

range: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => [T, T];
  • Find smallest and largest values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/range)

    Parameter x

    an iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    [min_value, max_value]

function rangeEntries

rangeEntries: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => [[number, T], [number, T]];
  • Find smallest and largest entries. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/rangeEntries)

    Parameter x

    an iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    [min_entry, max_entry]

function reduce

reduce: <T, U>(x: Iterable<T>, fr: ReduceFunction<T, U>, acc?: U) => U;
  • Reduce values of iterable to a single value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/reduce)

    Parameter x

    an iterable

    Parameter fr

    reduce function (acc, v, i, x)

    Parameter acc

    initial value

    Returns

    fr(fr(acc, vโ‚€), vโ‚)... | fr(acc, vโ‚€) = vโ‚€ if acc not given

function reject

reject: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T>;
  • Discard the values which pass a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/reject)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    vโ‚€, vโ‚, ... | ft(vแตข) = false; vแตข โˆˆ x

function rejectAt

rejectAt: <T>(x: Iterable<T>, is: number[]) => IterableIterator<T>;
  • Discard the values at given indices. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/rejectAt)

    Parameter x

    an iterable

    Parameter is

    indices (sorted)

    Returns

    vโ‚€, vโ‚, ... | vแตข = x[i]; i โˆ‰ is

function remove

remove: <T>(x: Iterable<T>, i: number) => IterableIterator<T>;
  • Remove value at index. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/remove)

    Parameter x

    an iterable

    Parameter i

    index

    Returns

    x[0..i] โงบ x[i+1..]

function repeat

repeat: <T>(x: Iterable<T>, n?: number) => IterableIterator<T>;
  • Repeat an iterable given times. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/repeat)

    Parameter x

    an iterable

    Parameter n

    times [-1 โ‡’ Inf]

    Returns

    ...x, ...x, ...(n times)

function reverse

reverse: <T>(x: Iterable<T>) => IterableIterator<T>;
  • Reverse the values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/reverse)

    Parameter x

    an iterable

    Returns

    x[|x|-1], x[|x|-2], ..., x[1], x[0]

right: <T>(x: Iterable<T>, n: number) => IterableIterator<T>;
  • Get values from right. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/right)

    Parameter x

    an iterable

    Parameter n

    number of values

    Returns

    x[-n..]

function rotate

rotate: <T>(x: Iterable<T>, n?: number) => IterableIterator<T>;
  • Rotate values in iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/rotate)

    Parameter x

    an iterable

    Parameter n

    rotate amount (+ve: left, -ve: right) [0]

    Returns

    x[n..] โงบ x[0..n]

function scanUntil

scanUntil: <T>(x: Iterable<T>, ft: TestFunction<T>) => number;
  • Scan from left, until a test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/scanUntil)

    Parameter x

    an array

    Parameter ft

    test function (v, i, x)

    Returns

    first index where test passes

function scanUntilRight

scanUntilRight: <T>(x: Iterable<T>, ft: TestFunction<T>) => number;
  • Scan from right, until a test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/scanUntilRight)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    first index where test fails till end

function scanWhile

scanWhile: <T>(x: Iterable<T>, ft: TestFunction<T>) => number;
  • Scan from left, while a test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/scanWhile)

    Parameter x

    an array

    Parameter ft

    test function (v, i, x)

    Returns

    first index where test fails

function scanWhileRight

scanWhileRight: <T>(x: Iterable<T>, ft: TestFunction<T>) => number;
  • Scan from right, while a test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/scanWhileRight)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    first index where test passes till end

search: <T>(x: Iterable<T>, ft: TestFunction<T>) => number;
  • Find index of first value passing a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/search)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    first index of value, -1 if not found

function searchAll

searchAll: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<number>;
  • Find indices of values passing a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchAll)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    indices of value

function searchInfix

searchInfix: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => number;
  • Find first index of an infix. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchInfix)

    Parameter x

    an iterable

    Parameter y

    search infix

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    first i | x[i..i+|y|] = y else -1

function searchInfixAll

searchInfixAll: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<number>;
  • Find indices of an infix. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchInfixAll)

    Parameter x

    an iterable

    Parameter y

    search infix

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    iโ‚€, iโ‚, ... | x[j..j+|y|] = y; j โˆˆ [iโ‚€, iโ‚, ...]

function searchInfixRight

searchInfixRight: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => number;
  • Find last index of an infix. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchInfixRight)

    Parameter x

    an iterable

    Parameter y

    search infix

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    first i | x[i..i+|y|] = y else -1

function searchRight

searchRight: <T>(x: Iterable<T>, ft: TestFunction<T>) => number;
  • Find index of last value passing a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchRight)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    last index of value, -1 if not found

function searchSubsequence

searchSubsequence: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => number;
  • Find first index of a subsequence. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchSubsequence)

    Parameter x

    an iterable

    Parameter y

    search subsequence

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    start index of subsequence, -1 if not found

function searchValue

searchValue: <T, U = T>(
x: Iterable<T>,
v: T,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => number;
  • Find first index of a value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchValue)

    Parameter x

    an iterable

    Parameter v

    search value

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    first index of value, -1 if not found

function searchValueAll

searchValueAll: <T, U = T>(
x: Iterable<T>,
v: T,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<number>;
  • Find indices of a value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchValueAll)

    Parameter x

    an iterable

    Parameter v

    search value

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    indices of value

function searchValueRight

searchValueRight: <T, U = T>(
x: Iterable<T>,
v: T,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => number;
  • Find last index of a value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/searchValueRight)

    Parameter x

    an iterable

    Parameter v

    search value

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    last index of value, -1 if not found

function set

set: <T>(x: Iterable<T>, i: number, v: T) => IterableIterator<T>;
  • Set value at index. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/set)

    Parameter x

    an iterable

    Parameter i

    index

    Parameter v

    value

    Returns

    x' | x' = x; x'[i] = v

function shift

shift: <T>(x: Iterable<T>) => IterableIterator<T>;
  • Get values except first. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/tail)

    Parameter x

    an iterable

    Returns

    x[1..|x|]

function size

size: <T>(x: Iterable<T>, i?: number, I?: number) => number;
  • Find the length of an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/length)

    Parameter x

    an iterable

    Parameter i

    start index [0]

    Parameter I

    end index [END]

    Returns

    |x[i..I]|

function slice

slice: <T>(x: Iterable<T>, i?: number, I?: number) => IterableIterator<T>;
  • Get part of an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/slice)

    Parameter x

    an iterable

    Parameter i

    start index (-ve: from right) [0]

    Parameter I

    end index (-ve: from right) [END]

    Returns

    x[i..I]

function some

some: <T>(x: Iterable<T>, ft?: TestFunction<T> | null) => boolean;
  • Check if any value satisfies a test. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/some)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    true if ft(vแตข) = true for some vแตข โˆˆ x

function splice

splice: <T>(
x: Iterable<T>,
i?: number,
n?: number,
...vs: T[]
) => IterableIterator<T>;
  • Remove or replaces existing values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/splice)

    Parameter x

    an iterable

    Parameter i

    remove index [0]

    Parameter n

    number of values to remove [rest]

    Parameter vs

    values to insert

    Returns

    x[0..i] โงบ vs โงบ x[i+n..]

function split

split: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T[]>;
  • Break iterable considering test as separator. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/split)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    x[j..k] โงบ x[l..m] โงบ ... | ft(x[i]) = true; i = 0..j / k..l / ...

function splitAt

splitAt: <T>(x: Iterable<T>, is: number[]) => IterableIterator<T[]>;
  • Break iterable considering indices as separator. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/splitAt)

    Parameter x

    an iterable

    Parameter is

    indices (sorted)

    Returns

    x[j..k] โงบ x[l..m] โงบ ... | ft(x[i]) = true; i = 0..j / k..l / ...; i โˆˆ is

function swap

swap: <T>(x: Iterable<T>, i: number, j: number) => IterableIterator<T>;
  • Exchange two values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/swap)

    Parameter x

    an iterable

    Parameter i

    an index

    Parameter j

    another index

    Returns

    x' | x' = x; x'[i] = x[j]; x'[j] = x[i]

function symmetricDifference

symmetricDifference: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<T>;
  • Obtain values not present in both iterables. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/symmetricDifference)

    Parameter x

    an iterable

    Parameter y

    another iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x-y โˆช y-x

function tail

tail: <T>(x: Iterable<T>) => IterableIterator<T>;
  • Get values except first. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/tail)

    Parameter x

    an iterable

    Returns

    x[1..|x|]

function take

take: <T>(x: Iterable<T>, n?: number) => IterableIterator<T>;
  • Keep first n values only. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/take)

    Parameter x

    an iterable

    Parameter n

    number of values [1]

    Returns

    x[0..n]

function takeRight

takeRight: <T>(x: Iterable<T>, n?: number) => IterableIterator<T>;
  • Keep last n values only. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/takeRight)

    Parameter x

    an iterable

    Parameter n

    number of values [1]

    Returns

    x[-n..]

function takeWhile

takeWhile: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T>;
  • Keep values from left, while a test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/takeWhile)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    x[0..T-1] | ft(x[i]) = true โˆ€ i โˆˆ [0, T-1] & ft(x[T]) = false

function takeWhileRight

takeWhileRight: <T>(x: Iterable<T>, ft: TestFunction<T>) => IterableIterator<T>;
  • Keep values from right, while a test passes. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/takeWhileRight)

    Parameter x

    an iterable

    Parameter ft

    test function (v, i, x)

    Returns

    x[T..] | ft(x[i]) = true โˆ€ i โˆˆ [T, |x|-1] & ft(x[T-1]) = false

function toCallable

toCallable: <T>(x: Iterable<T>) => () => T;
  • Generate a function that iterates over values upon invocation. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/toInvokable)

    Parameter x

    an iterable

    Returns

    fn | fn() โ†’ x[0], fn() โ†’ x[1], ...

function toInvokable

toInvokable: <T>(x: Iterable<T>) => () => T;
  • Generate a function that iterates over values upon invocation. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/toInvokable)

    Parameter x

    an iterable

    Returns

    fn | fn() โ†’ x[0], fn() โ†’ x[1], ...

function toMany

toMany: <T>(x: Iterable<T>, now?: boolean) => Iterable<T>;
  • Convert a once-like iterable to many. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/toMany)

    Parameter x

    an iterable

    Parameter now

    consume immediately? [false]

    Returns

    x' | x' = x; x' can be iterated multiple times

function toOnce

toOnce: <T>(x: Iterable<T>) => IterableIterator<T>;
  • List all values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/values)

    Parameter x

    an iterable

    Returns

    vโ‚€, vโ‚, ... | vแตข = x[i]

function union

union: <T, U = T>(
x: Iterable<T>,
y: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<T>;
  • Obtain values present in any iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/union)

    Parameter x

    an iterable

    Parameter y

    another iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    x โˆช y = {v | v โˆˆ x or v โˆˆ y}

function unique

unique: <T, U = T>(
x: Iterable<T>,
fc?: CompareFunction<T | U> | null,
fm?: MapFunction<T, T | U> | null
) => IterableIterator<T>;
  • Remove duplicate values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/unique)

    Parameter x

    an iterable

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, i, x)

    Returns

    vโ‚€, vโ‚, ... | vแตข โˆˆ x; vแตข โ‰  vโฑผ โˆ€ i, j

function unshift

unshift: <T>(x: Iterable<T>, ...vs: T[]) => IterableIterator<T>;
  • Add values to the start. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/unshift)

    Parameter x

    an iterable

    Parameter vs

    values to add

    Returns

    ...vs, ...x

function values

values: <T>(x: Iterable<T>) => IterableIterator<T>;
  • List all values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/values)

    Parameter x

    an iterable

    Returns

    vโ‚€, vโ‚, ... | vแตข = x[i]

function zip

zip: <T, U = T[]>(
xs: Iterable<T>[],
fm?: MapFunction<T[], T[] | U> | null,
fe?: EndFunction | null,
vd?: T
) => IterableIterator<T[] | U>;
  • Combine values from iterables. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/zip)

    Parameter xs

    iterables

    Parameter fm

    map function (vs, i, xs)

    Parameter fe

    end function (dones) [some]

    Parameter vd

    default value

    Returns

    fm([xโ‚€[0], xโ‚[0], ...]), fm([xโ‚€[1], xโ‚[1], ...]), ...

Type Aliases

type CombineFunction

type CombineFunction<T> = (a: T, b: T) => T;
  • Handle combining of two values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/CombineFunction)

    Parameter a

    a value

    Parameter b

    another value

    Returns

    combined value

type CompareFunction

type CompareFunction<T> = (a: T, b: T) => number;
  • Handle comparison of two values. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/CompareFunction)

    Parameter a

    a value

    Parameter b

    another value

    Returns

    a<b: -ve, a=b: 0, a>b: +ve

type EndFunction

type EndFunction = (dones: boolean[]) => boolean;
  • Handle ending of a combined iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/EndFunction)

    Parameter dones

    iแต—สฐ iterable done?

    Returns

    combined iterable done?

type MapFunction

type MapFunction<T, U> = (v: T, i: number, x: Iterable<T>) => U;
  • Handle transformation of a value to another. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/MapFunction)

    Parameter v

    value in iterable

    Parameter i

    index of value in iterable

    Parameter x

    iterable containing the value

    Returns

    transformed value

type ProcessFunction

type ProcessFunction<T> = (v: T, i: number, x: Iterable<T>) => void;
  • Handle processing of values in an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/ProcessFunction)

    Parameter v

    value in iterable

    Parameter i

    index of value in iterable

    Parameter x

    iterable containing the value

type ReadFunction

type ReadFunction<T> = () => T;
  • Handle reading of a single value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/ReadFunction)

    Returns

    value

type ReduceFunction

type ReduceFunction<T, U> = (acc: U, v: T, i: number, x: Iterable<T>) => U;
  • Handle reduction of multiple values into a single value. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/ReduceFunction)

    Parameter acc

    accumulator (temporary result)

    Parameter v

    value in iterable

    Parameter i

    index of value in iterable

    Parameter x

    iterable containing the value

    Returns

    reduced value

type TestFunction

type TestFunction<T> = (v: T, i: number, x: Iterable<T>) => boolean;
  • Handle selection of values in an iterable. [๐Ÿ“˜](https://github.com/nodef/extra-iterable/wiki/TestFunction)

    Parameter v

    value in iterable

    Parameter i

    index of value in iterable

    Parameter x

    iterable containing the value

    Returns

    selected?

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (12)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/extra-iterable.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/extra-iterable)
  • HTML
    <a href="https://www.jsdocs.io/package/extra-iterable"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>