Home

Awesome

iter-ops

Build Status

About

Basic operations on synchronous + asynchronous iterables, strictly for JavaScript native types.

image

We do not use any synthetic types / wrappers here, like Observable in RXJS, etc. It is strictly an iterable on the input, and an iterable on the output, for maximum performance, simplicity and compatibility (see Rationale).

Related repo: iter-ops-extras - addition to the main API.

Installation

$ npm i iter-ops

Usage

import {pipe, filter, map} from 'iter-ops';

const input = [1, 2, 3, 4, 5];

const i = pipe(
    input,
    filter((a) => a % 2 === 0), // find even numbers
    map((value) => ({value})) // remap into objects
);

console.log(...i); //=> {value: 2}, {value: 4}
import {pipe, toAsync, distinct, delay} from 'iter-ops';

const input = [1, 2, 2, 3, 3, 4];

const i = pipe(
    toAsync(input), // make asynchronous
    distinct(), // emit unique numbers
    delay(1000) // delay each value by 1s
);
// or you can replace `pipe` + `toAsync` with just `pipeAsync`

(async function () {
    for await (const a of i) {
        console.log(a); //=> 1, 2, 3, 4 (with 1s delay)
    }
})();

See also...

API

Function pipe takes any iterable, applies all specified operators to it, and returns an extended iterable. For strict type of iterables, there are also pipeSync and pipeAsync.

<i>Standard Operators:</i>

All standard operators implement the same logic as Array does:

<i>Extended Operators:</i>

<i>Custom Operators:</i>

See iter-ops-extras - a collection of custom operators (ones based on existing operators).

<i>Resources:</i>