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 firstcountitems from thesource.drop(source, count): Drop the firstcountitems from thesource.takeWhile(source, predicate): Take items from thesourcewhile thepredicatereturnstrue.dropWhile(source, predicate): Drop items from thesourcewhile thepredicatereturnstrue.takeEnd(source, count): Take the lastcountitems from thesource.dropEnd(source, count): Drop the lastcountitems from thesource.map(mapper, ...sources): Apply themapperto each item in thesources.filter(predicate, ...sources): Filter items in thesourcesby thepredicate.reduce(reducer, source, initial?): Reduce thesourceto a single value by thereducer, optionally with theinitialvalue.tee(source, number): Effectively duplicate thesourceintonumberof async iterables.groupBy(source, keySelector): Group items in thesourceby thekeySelector.unique(source, keySelector?): Eliminate duplicate items in thesource, optionally by thekeySelector.range(start?, stop, step?): Generate a sequence of numbers fromstarttostopbystep.count(start?, step?): Generate a sequence of numbers fromstartbystepinfinitely.cycle(source): Cycle thesourceinfinitely.repeat(value, times?): Repeat thevaluefortimestimes, or infinitely iftimesis 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 iterableactualis 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/aitertoolsimport * as aitertools from "@hongminhee/aitertools";In Node.js:
$ npm add aitertoolsimport * 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