Popularity
0.9
Growing
Activity
9.8
Growing
55
3
3

Description

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

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).

We also do not use ES6 generators internally, because their current implementation in V8 is relatively slow.

Programming language: TypeScript
License: MIT License
Tags: Editors     TypeScript     JavaScript     Iterable     Iterator    

#<Sawyer::Resource:0x00007fbac98da410> alternatives and similar libraries

Based on the "Editors" category.
Alternatively, view iter-ops alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of #<Sawyer::Resource:0x00007fbac98da410> or a related project?

Add another 'Editors' Library

README

iter-ops

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).

Installation

$ npm i iter-ops

Usage

Follow the usage examples below, based on your development environment.

See also...

For web usage, either bundle it properly, or see [web](./web) folder.

JavaScript

Simple filtering + mapping an iterable:

const {pipe, filter, map} = require('iter-ops');

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

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

const result = [...i]; //=> [{value: 2}, {value: 4}]

TypeScript

Calculating the sum of unique numbers:

import {pipe, distinct, reduce} from 'iter-ops';

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

const i = pipe(
    a,
    distinct(), // emit unique numbers
    reduce((p, c) => p + c) // sum up the numbers
); //=> one-value iterable

const result = i.first; //=> 10

API

Function pipe takes an iterable, applies all specified operators to it, and returns an extended iterable.

Standard operators:

All standard operators implement the same logic as Array does:

  • concat - merges current iterable with multiple values, iterators or iterables.
  • every - checks if all elements pass the predicate test.
  • filter - standard filter processor, filtering by predicate.
  • map - standard mapping processor, remapping by predicate.
  • reduce - standard reduce processor.
  • some - checks if any element passes the predicate test.

Extended operators:

  • aggregate - executes an aggregate on accumulated values - see Aggregates.
  • catchError - catches iteration errors - see Error Handling.
  • count - counts values, and produces a one-value iterable.
  • defaultEmpty - adds default to an empty iterable.
  • distinct - emits unique values, with optional key selector.
  • drain - drains the iterable, and then ends it.
  • empty - produces an empty iterable.
  • first - produces a one-value iterable, with the first emitted value.
  • indexBy - emits indexed values that pass the predicate test.
  • isEmpty - produces a one-value iterable, indicating if the source is empty.
  • last - produces a one-value iterable, with the last emitted value.
  • onEnd - notifies of the end of a successful iteration.
  • page - splits values into pages of fixed size (last page can be smaller).
  • repeat - repeats iterable values.
  • skip - starts emitting values after certain count.
  • split - splits values into separate lists - see Split.
  • spread - spreads iterable values.
  • start - starts emitting, once the predicate returns a truthy value.
  • stop - stops emitting, once the predicate returns a truthy value.
  • take - emits up to certain number of values.
  • takeLast - emits up to certain number of the last values.
  • tap - taps into each value, without changing the output.
  • timing - measures timings for each value.
  • toArray - accumulates values into an array.
  • zip - zips values together, into an array.

See also:

  • Full API - generated from code
  • [Asynchronous Operators](./src/ops/async) - specific for asynchronous iterables
  • Recipes - for more operations.