0.3.0 • Published 6 years ago

@jsq/async-seq v0.3.0

Weekly downloads
225
License
Apache-2.0
Repository
github
Last release
6 years ago

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.

0.3.0

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago