@jsq/async-seq

Lazy sequence operators for JavaScript backed by async iterators.

Stats

StarsIssuesVersionUpdatedCreatedSize
@jsq/async-seq
410.3.04 years ago4 years agoMinified + gzip package size for @jsq/async-seq in KB

Readme

Async sequence operators

npm version Apache 2 License Build Status

This package provides a number of functions for filtering, reducing, combining, and otherwise transforming asynchronous iterators. Where possible, the functions in this library mirror those found on Array.prototype. Unlike the methods on Array.prototype, all functions are evaluated lazily and will only be applied to values as they are produced.

All functions take an iterable as their last argument, which allows you to curry and compose operators with bind:

import {filter} from '@jsq/async-seq';

const evens = filter.bind(null, x => x % 2 === 0);

This library was designed with the Pipeline Operator ECMAScript proposal (currently at stage 1) in mind:

import {filter, map, sum, takeWhile} from '@jsq/async-seq';

function *fibonacci() {
    let i = 1, j = 1;
    do {
        yield i;
        [i, j] = [j, j + i];
    } while (true);
}

const sumOfAllEvenFibonacciNumbersUnderTenMillion = fibonacci()
    |> map.bind(null, x => x * x)
    |> filter.bind(null, x => x % 2 === 0)
    |> takeWhile.bind(null, x => x < 10000000)
    |> sum
    |> await;

For documentation of the functions provided by this library, please see the API documentation.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.