This library provides a well-tested collection of small utility functions dealing with async iterables. You can think of it as .NET LINQ or Python aitertools for Deno & Node.js.
For the complete list of functions, see the complete API reference.
concat(...sources)
: Concatenate multiple async iterables into one.take(source, count)
: Take the firstcount
items from thesource
.drop(source, count)
: Drop the firstcount
items from thesource
.takeWhile(source, predicate)
: Take items from thesource
while thepredicate
returnstrue
.dropWhile(source, predicate)
: Drop items from thesource
while thepredicate
returnstrue
.takeEnd(source, count)
: Take the lastcount
items from thesource
.dropEnd(source, count)
: Drop the lastcount
items from thesource
.map(mapper, ...sources)
: Apply themapper
to each item in thesources
.filter(predicate, ...sources)
: Filter items in thesources
by thepredicate
.reduce(reducer, source, initial?)
: Reduce thesource
to a single value by thereducer
, optionally with theinitial
value.tee(source, number)
: Effectively duplicate thesource
intonumber
of async iterables.groupBy(source, keySelector)
: Group items in thesource
by thekeySelector
.unique(source, keySelector?)
: Eliminate duplicate items in thesource
, optionally by thekeySelector
.range(start?, stop, step?)
: Generate a sequence of numbers fromstart
tostop
bystep
.count(start?, step?)
: Generate a sequence of numbers fromstart
bystep
infinitely.cycle(source)
: Cycle thesource
infinitely.repeat(value, times?)
: Repeat thevalue
fortimes
times, or infinitely iftimes
is not specified.fromIterable(source)
: Convert an iterable to an async iterable.toArray(source)
: Convert an async iterable to an array.toSet(source)
: Convert an async iterable to aSet
.toMap(source, keySelector, valueSelector?)
: Convert an async iterable to aMap
.assertStreams(actual, expected, msg?)
: Asset that an async iterableactual
is equal to an arrayexpected
.assertStreamStartsWith(actual, expected, msg?)
: Asset that an async iterableactual
(which is possibly infinite) starts with an arrayexpected
.
In Deno:
$ deno add @hongminhee/aitertools
import * as aitertools from "@hongminhee/aitertools";
In Node.js:
$ npm add aitertools
import * as aitertools from "aitertools";
See CHANGES.md file. Note that unreleased versions are also available on JSR for Deno:
deno add @hongminhee/aitertools@0.6.0-dev.36+9aa783c
… and on npm with dev
tag for Node.js:
$ npm add aitertools@dev