Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@reactivex/ix-es2015-cjs

ReactiveX5.9kMIT7.0.0TypeScript support: included

The Interactive Extensions for JavaScript

Iterator, Iterable, Promise, Async, AsyncIterable, AsyncIterator

readme

The Interactive Extensions for JavaScript (IxJS)

Build Status Build status npm version Join the chat at https://gitter.im/ReactiveXIxJS/

IxJS is a set of libraries to compose synchronous and asynchronous collections and Array#extras style composition in JavaScript

The Interactive Extensions for JavaScript (IxJS) brings the Array#extras combinators to iterables, generators, async iterables and async generators. With the introduction of the Symbol.iterator and generators in ES2015, and subsequent introduction of Symbol.asyncIterator and async generators, it became obvious we need an abstraction over these data structures for composition, querying and more.

IxJS unifies both synchronous and asynchronous pull-based collections, just as RxJS unified the world of push-based collections. RxJS is great for event-based workflows where the data can be pushed at the rate of the producer, however, IxJS is great at I/O operations where you as the consumer can pull the data when you are ready.

Install IxJS from npm

npm install ix

(also read about how we package IxJS below)

Iterable

The Iterable class a way to create and compose synchronous collections much like Arrays, Maps and Sets in JavaScript using the Array#extras style using the familiar methods you are used to like map, filter, reduce and more. We can use the for ... of statements to iterate our collections.

// ES
import { from } from 'ix/iterable';
import { filter, map } from 'ix/iterable/operators';

// CommonJS
const from = require('ix/iterable').from;
const { filter, map } = require('ix/iterable/operators');

const source = function* () {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
};

const results = from(source()).pipe(
  filter(x => x % 2 === 0),
  map(x => x * x)
);

for (let item of results) {
  console.log(`Next: ${item}`);
}

// Next 4
// Next 16

In addition, we also supply a forEach so it's your choice for which to use.

// ES
import { from } from 'ix/asynciterable';
import { filter, map } from 'ix/asynciterable/operators';

// CommonJS
const from = require('ix/asynciterable').from;
const { filter, map } = require('ix/asynciterable/operators');

const source = function* () {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
};

const results = from(source()).pipe(
  filter(x => x % 2 === 0),
  map(x => x * x)
);

results
  .forEach(item => {
    console.log(`Next: ${item}`);
  });
// Next 4
// Next 16

Instead of bringing in the entire library for Iterable, we can pick and choose which operators we want, for bundling concerns and add them directly to the Iterable prototype.

// ES
import { IterableX as Iterable } from 'ix/iterable';
import 'ix/add/iterable/of';
import 'ix/add/iterable-operators/map';

// CommonJS
const { IterableX: Iterable } = require('ix/iterable');
require('ix/add/iterable/of');
require('ix/add/iterable-operators/map');

const results = Iterable.of(1,2,3)
  .map(x => x + '!!');

The Iterable object implements the iterator pattern in JavaScript by exposing the [Symbol.iterator] method which in turn exposes the Iterator class. The iterator yields values by calling the next() method which returns the IteratorResult class.

interface Iterable<T> {
  [Symbol.iterator](): Iterator<T>;
}

interface Iterator<T> {
  next(value?: any): IteratorResult<T>;
  return?(value?: any): IteratorResult<T>;
  throw?(e?: any): IteratorResult<T>;
}

interface IteratorResult<T> {
  value: T;
  done: Boolean;
}

AsyncIterable

The AsyncIterable object is based off the ECMAScript Proposal for Asynchronous Iterators. This would allow us to create asynchronous collections of Promises and be able to use such methods as the map, filter, reduce and other operators we can import. Much like with the Iterable object where we can iterate through our collections, we can use for await ... of instead which allows us to iterate over the asynchronous collection.

// ES
import { from } from 'ix/asynciterable';
import { filter, map } from 'ix/asynciterable/operators';

// CommonJS
const from = require('ix/asynciterable').from;
const { filter, map } = require('ix/asynciterable/operators');

const source = async function* () {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
};

const results = from(source()).pipe(
  filter(async x => x % 2 === 0),
  map(async x => x * x)
);

for await (let item of results) {
  console.log(`Next: ${item}`);
}

// Next 4
// Next 16

Alternatively, we can use the built-in forEach and catch should there be any errors:

// ES
import { from } from 'ix/asynciterable';
import { filter, map } from 'ix/asynciterable/operators';

// CommonJS
const from = require('ix/asynciterable').from;
const { filter, map } = require('ix/asynciterable/operators');

const source = async function* () {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
};

const results = from(source()).pipe(
  filter(async x => x % 2 === 0),
  map(async x => x * x)
);

results
  .forEach(item => {
    console.log(`Next: ${item}`);
  })
  .catch(err => {
    console.log(`Error ${err}`);
  });

for await (let item of results) {
  console.log(`Next: ${item}`);
}

// Next 4
// Next 16

Instead of bringing in the entire library for AsyncIterable, we can pick and choose which operators we want, for bundling concerns directly to the AsyncIterable prototype.

// ES
import { AsyncIterableX as AsyncIterable } from 'ix/asynciterable';
import 'ix/add/async-iterable/of';
import 'ix/add/asynciterable-operators/map';

// CommonJS
const { AsyncIterableX: AsyncIterable } = require('ix/asynciterable');
require('ix/add/asynciterable-operators/map');

const results = AsyncIterable.of(1,2,3)
  .map(x => x + '!!');

The AsyncIterable class implements the async iterator pattern in JavaScript by exposing the [Symbol.asyncIterator] method which in turn exposes the AsyncIterator class. The iterator yields values by calling the next() method which returns a Promise which resolves a IteratorResult class.

interface AsyncIterable<T> {
  [Symbol.asyncIterator](): AsyncIterator<T>;
}

interface AsyncIterator<T> {
  [Symbol.asyncIterator](): AsyncIterator<T>;
  next(value?: any): Promise<IteratorResult<T>>;
  return?(value?: any): Promise<IteratorResult<T>>;
  throw?(e?: any): Promise<IteratorResult<T>>;
}

interface IteratorResult<T> {
  value: T;
  done: Boolean;
}

Converting from Iterable to AsyncIterable

Using IxJS, you can easily go from an Iterable to an AsyncIterable using a number of methods. First, we can use the from function, either as a standalone or on the Ix.AsyncIterable object. The from method accepts a standard Iterable, Generator, and Iterator of Promises, or even another AsyncIterable.

import { from } from 'ix/asynciterable';
import { map } from 'ix/asynciterable/operators';

const xs = [1, 2, 3, 4];
const mapped = from(xs).pipe(
  map(async (item, index) => item * index)
);

for await (let item of mapped) {
  console.log(`Next: ${item}`);
}

// Next 0
// Next 2
// Next 6
// Next 12

Contributing

We are grateful for contributions to the IxJS project. The IxJS project evolves because of community involvement from people such as yourselves. Please read below on how to get involved.

Code Of Conduct

The IxJS project has a strict Code of Conduct that must be adhered at all times. This code of conduct comes from the Contributor Convenant. Please read the full text as to what is and is not permitted.

Contributing Guide

Read the Contributing Guide on how to get involved with the IxJS project. This includes our development process and how to test your code before committing.

Packaging

IxJS is written in TypeScript, but the project is compiled to multiple JS versions and common module formats. The base IxJS package includes all the compilation targets for convenience, but if you're conscientious about your node_modules footprint, don't worry -- we got you. The targets are also published under the @reactivex namespace:

npm install @reactivex/ix-ts # TypeScript target
npm install @reactivex/ix-es5-cjs # ES5 CommonJS target
npm install @reactivex/ix-es5-esm # ES5 ESModules target
npm install @reactivex/ix-es5-umd # ES5 UMD target
npm install @reactivex/ix-es2015-cjs # ES2015 CommonJS target
npm install @reactivex/ix-es2015-esm # ES2015 ESModules target
npm install @reactivex/ix-es2015-umd # ES2015 UMD target
npm install @reactivex/ix-esnext-cjs # ESNext CommonJS target
npm install @reactivex/ix-esnext-esm # ESNext ESModules target
npm install @reactivex/ix-esnext-umd # ESNext UMD target

Why we package like this

The JS community is a diverse group with a varied list of target environments and tool chains. Publishing multiple packages accommodates projects of all types. Friends targeting the latest JS runtimes can pull in the ESNext + ESM build. Friends needing wide browser support and small download size can use the UMD bundle, which has been run through Google's Closure Compiler with advanced optimizations.

If you think we missed a compilation target and it's a blocker for adoption, please open an issue. We're here for you ❤️.

License

The MIT License (MIT)

Copyright (c) ReactiveX

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

changelog

7.0.0 (2024-07-10)

Bug Fixes

  • actions: fix docs workflow (512e370)
  • changelog: include latest changelog in npm packages (f25687b)

chore

  • build: fix gulp async task completion (c68e97c)

6.0.0 (2024-05-21)

Bug Fixes

  • flatmap: flatMap shouldn't throw when the input size is smaller than concurrent (#367) (dffd344), closes #366
  • from: make from forward or check abort signal. fixes #352 (#361) (e2dd8d7)
  • merge: catch promise errors to avoid unhandled exceptions (#354) (520e096), closes #353
  • package.json: fix CDN names in ix package.json (760242e)
  • toMap: fix return type of keySelector (#365) (eab2f10), closes #364

Build System

  • deps-dev: bump json from 9.0.6 to 10.0.0 (#359) (1e4dd6f)
  • deps: bump tj-actions/changed-files in /.github/workflows (#362) (ff1cef0)

chore

Documentation

  • docs/asynciterable/converting.md: Fix fromEventPattern import (#350) (f07b7ef)
  • Fix ESM imports and tree-shaking (#363) (d31d2c5), closes #363
  • Add docs action (#360) (d6591ee), closes #360

5.0.0 (2022-08-01)

Bug Fixes

  • flatMap: default flatMap concurrent parameter to 1 (#346) (bcfab5a)

chore

Documentation

  • [FIX] Ensure return is called on AsyncIterators (#348) (72c37ec), closes #348
  • Default to flatMap concurrent (#347) (32137a7), closes #347

4.6.1 (2022-07-26)

Bug Fixes

  • flatMap: default flatMap concurrent parameter to 1 (#346) (bcfab5a)

4.6.0 (2022-07-26)

chore

Continuous Integration

  • use github actions instead of travis-ci (#344) (d357a19)

Documentation

BREAKING CHANGES

  • flatMap enumerates inner sequences in parallel
  • flat enumerates inner sequences in parallel

  • feat(concatmap.ts): add concatMap implementation

4.5.2 (2021-10-07)

Bug Fixes

  • pipethrough: fix Iterable/AsyncIterable pipeThrough signature (#338) (58dea12)

4.5.1 (2021-09-09)

Bug Fixes

  • add static Iterable.as and AsyncIterable.as (#336) (b911d1a)

4.5.0 (2021-07-29)

    • chore(readme.md): update travis-ci badge url (#334) (370ae91), closes #334
  • Update to TypeScript v4.3.5 (#332) (0637a25), closes #332 #331

Features

  • from: support AbortSignal in from(observable) (#333) (7897e85)

4.4.1 (2021-07-11)

Bug Fixes

  • package.json: use ^ for allowed tslib versions (#330) (02b1a22)

4.4.0 (2021-06-09)

Bug Fixes

  • src/asynciterable/operators/batch.ts: create rejected Promise on demand (#328) (aa40ab1), closes #320
  • src/asynciterable/operators/timeout.ts: ensure AsyncIterable timeout operator passes its values (#327) (f5a213a), closes #325

Documentation

  • docs/asynciterable/creating.md: Fix async iterable docs typo s/source/sink (#317) (084658f)

Features

  • asynciterable-operators: Add bufferCountOrTime operator (#324) (ee7c43e)

4.3.1 (2021-03-23)

Bug Fixes

  • Promise.race: Fix Promise.race memory leaks (#323) (75ef616)

chore

  • npm-release.sh: set concurrency to 1 to work around npm publish rate limits (825bdd8)
  • saferace.ts: add unlicense to safeRace.ts (c9c0a83)

4.3.0 (2021-03-15)

Bug Fixes

  • Abort: Ensure removal of event listeners from AbortSignal (#321) (d4de33b)

4.2.0 (2021-01-26)

Bug Fixes

  • umd: fix the UMD bundle export names so they don't conflict and overwrite each other (#318) (c45eaa8)

4.1.0 (2021-01-21)

Bug Fixes

  • operators: export withLatestFrom and withAbort AsyncIterable operators (#313) (19915b5)
  • operators: support Array.prototype.reduce signature in Iterable scan and reduce operators again. Fixes #311 (#312) (1d98746)
  • repeat-spec.ts: fix unhandled-rejection error in node v15 (7d84c87)
  • takeUntil: complete iterable immediately (#315) (#316) (97b2ca2)

chore

  • npm-release.sh: add prompt to enter npm OTP before release (f0c111e)
  • npm-release.sh: use npm run-script instead of npx run-s in release script (b03597d)

Documentation

  • readme: fix wrong result of samples and typo (16fe9b0)

4.0.0 (2020-09-01)

Continuous Integration

  • travis: update to the latest npm (d53de73)

Documentation

  • AsyncIterable: Add basic async-iterable docs (11c2037)
  • creation: split creation/converting (e8dfa97)
  • IxJS: Adding basic overview (10abfdc)

Features

  • Abort: Add basic abortsignal support (a66a7c8)
  • Abort: Add basic abortsignal support (07ba58c)
  • Abort: Add more aborts (b7832a6)
  • Abort: add more throws if aborted (2a489e1)
  • Abort: fix debounce (954ce58)
  • Abort: Fix most operators (08a4c08)
  • Abort: fix reduce (6e848f1)
  • Abort: Formatting (d9e75ef)
  • Abort: Update all JSDocs (313a1b4)
  • asasynciterable: add AsyncIterableTransform stream (e3d12a1)
  • min/max: Fix min and max (37e7c0a)
  • never: Adds never (64a9c31)
  • Adding converting docs and links (6c493ae)
  • Updating through withLatestFrom (79be89c)
  • Adding docs through map (cf6a509)

Bug Fixes

  • aborterror: add Symbol.hasInstance method to AbortSignal (c9d9f1e)
  • closure: fixing indexing (8692d0c)
  • debounce: fix AsyncIterable debounce and reenable tests (480996e)
  • extremaBy: fixing extrema/minBy (297d6e4)
  • maxby-spec: fix maxby test (2699e40)
  • minification: fix test failures breaking due to aggressive closure-compiler minification (a888ce8)
  • specs: fixing tests for single (2793801)
  • tests: Fix bad max test (3a853ee)
  • tests: Fixing tests (0affef1)
  • tests: Fixing tests (c0a3e68)
  • tests: Get closure working on tests (4c0705f)

Build System

  • jest: disable jest test caching (92a1978)
  • typescript: update typescript, tslib, and google-closure-compiler versions (37d66b3)

chore

Code Refactoring

  • abortsignal: remove AbortSignal interface (8ed7fca)

Styles

  • specs: reorder expected vs. actual comparisons for error-throwing tests (3cc1d8d)

Tests

  • umd: import test utils to fix missing window global when testing webpack-minified UMD bundles (111f854)

3.0.1 (2020-02-21)

chore

Documentation

2.5.3 (2019-03-27)

Bug Fixes

  • asynciterable#memoize: ensure memoize and publish source values are only pulled once (8392c50)

  • from: ensure iterable and asynciterable from methods accept iterators (8392c50)

  • observers: widen the return type of observer fns (8392c50)

  • asynciterable#tap: add selector function overload (8392c50)

Features

  • asynciterable-pipe: add tee, pipeTo, and pipeThrough to AsyncIterable prototype (873b8fe)

  • asynciterable-toDOMStream: add AsyncIterable#toDOMStream implementation (2e00c95)

  • asynciterable-fromDOMStream: add AsyncIterable.fromDOMStream implementation (2e00c95)

2.5.2 (2019-03-04)

Bug Fixes

  • asynciterable-pipe: fix asynciterable pipe typings (2e00c95)

Features

  • asynciterable-pipe: add tee, pipeTo, and pipeThrough to AsyncIterable prototype (873b8fe)

  • asynciterable-toDOMStream: add AsyncIterable#toDOMStream implementation (2e00c95)

  • asynciterable-fromDOMStream: add AsyncIterable.fromDOMStream implementation (2e00c95)

2.5.1 (2019-01-14)

Bug Fixes

  • exports: export all iterable and asynciterable operators (1f8870f)

  • asynciterable#scanProto: allow AsyncIterable#scan selector to return R | Promise<R> (1f8870f)

2.5.0 (2019-01-12)

Bug Fixes

  • scan: fix scan over single-element sources (7f6a85f)

2.4.3 (2019-01-03)

Bug Fixes

  • dependencies: add rxjs to the production dependencies list (54e5cf7)

Features

  • batch: add asynciterable batch() implementation (9c9bd7e)

  • toNodeStream: add iterable/asynciterable toNodeStream implementations (9a1c5cc)

  • fromNodeStream: AsyncIterable.fromNodeStream has been optimized for streams and AsyncIterables (9a1c5cc)

  • pipe: AsyncIterable.prototype.pipe now accepts Node.js WritableStream values in addition to operators (9a1c5cc)

2.4.0 (2019-01-03)

Bug Fixes

  • toObservable: adds symbol-observable for rxjs interop (273e697), closes #245

Features

  • add support for passing Node WritableStreams to AsyncIterableX#pipe() (#257) (9a1c5cc)

  • add AsyncIterableX#toNodeStream() (#257) (9a1c5cc)

  • add AsyncIterableX#batch() (#222) (9c9bd7e)

2.3.5 (2018-02-19)

Bug Fixes

  • compile: adding some missing exports to deal with typescript 2.7.x compat issue (0b0c837), closes #214

Features

2.3.4 (2017-11-29)

Bug Fixes

  • typings: Fix optional predicate typings for user-defined typeguard predicates (fedd563)
  • typings: workaround typescript bugs when noImplicitAny or strictNullChecks are not true (ce03239)

2.3.3 (2017-11-21)

Reverts

  • npm: revert 4493754d9fbbc061347d8ef785704b61ecb486c5 (564c600), closes #163

2.3.2 (2017-11-21)

Bug Fixes

  • fromnodestream: enable fromnodestream tests, fix minification problems (#156) (745d763)
  • fromnodestream: type fromNodeStream to accept NodeJS.ReadableStream interface (3cbf2dd)
  • FromObservableAsyncIterable: Fix handling of asynchronously emitting Observables (#150) (2c7222c)
  • readme: fix lettable syntax (0e46181)

Features

  • as: Add static as convenience methods to wrap values as Async/Iterables (#154) (79a14c5)

2.3.1 (2017-11-08)

Bug Fixes

2.3.0 (2017-11-03)

Bug Fixes

  • pipe: pipe() should always return IterableX<T> (#126) (d7c0556)
  • type-guards: fix user-defined type guards (#83) (fd45455), closes #44

Features

  • asyncify: adds asyncify and asyncifyErrback (#96) (f75dfaf)
  • exports: move abstract class definitions into subfolders (#121) (8c45138), closes #52
  • forkJoin/combineLatest: adds forkJoin and combineLatest (#132) (c0e3596)
  • fromNodeStream: adds fromNodeStream readable (#124) (952509e)
  • merge/concat: add typed overloads for merge/concat (#84) (752aa96)
  • operators: rename __modules.ts to index.ts for tree-shaking (#120) (83ab288), closes #52
  • pipe: add piped operators [WIP - DO NOT MERGE] (#75) (76a4b4f), closes #116 #117 #119

2.2.0 (2017-10-15)

Bug Fixes

  • comparer: fixes bug with comparer (4098a8c)
  • comparer: Fixes comparer (c6a67eb)
  • concatall: fix concatall file name case (#59) (1d241ca)
  • endWith: fix endWith unit tests (dffa71d)
  • operators: import all add/*-operators in Ix.ts (6ca52f5)

Features

  • endWith: adds endWith operator (f967e3b)
  • merge: adds merge operator (b81a007)
  • merge: fix indexOf issues with merge (2a542e5)
  • mergeAll: adds mergeAll operator (47f17fa)
  • operators: support user defined type guards in boolean predicates (ef8764a), closes #44
  • windows: add windows build support (0ba498e)
  • windows: add windows build support (59fe0e3)

BREAKING CHANGES

  • zip selectors now take a single "values" Array argument, instead of varargs

  • test(zip): update zip tests for variable sources

2.1.4 (2017-10-04)

2.1.3 (2017-10-03)

2.1.1 (2017-10-03)

Bug Fixes

  • fromeventpattern: use async generator here since Symbols in object literals don't survive uglif (38cdee2)
  • internals: export internal modules as default, which plays nicer with closure compiler (0bac516)
  • Ix: add a default export to fix node's --experimental-modules behavior (0698577)
  • Ix: export GroupedIterable and GroupedAsyncIterable types (e6d697e)
  • operators: rearrange implementation details that break different steps in the build pipeline (f2f2ddd)
  • OrderedIterable: export ordered iterables. Fixes #31 (7127771)

Features

  • prettier: adds prettier closes issue #41 (6464e7a)

2.1.0 (2017-08-24)

Bug Fixes

  • groupBy: fixing missing this in groupBy operator prototype signatures (ff2ee18), closes #33
  • typings: Fix IterableX#concatAll typings to accept IterableX<Iterable<T>> (#25) (a9343c0)

Features

  • docs: add async iterable docs (c75fbf0)
  • docs: add why Ix (fc0be11)
  • docs: Adding basic contribution docs (b4b93e2)
  • docs: document for/forEach (495e772)
  • from: Collapse from to include Observable (b130e9c)
  • Iterator: add iterator return to catch operators (a7898ca)
  • observable: add to/from Observable (825b3d9)
  • observable: move subscription to own file (335f694)
  • scheduler: initial scheduler implementation (4ad0468)
  • time: add time based operators (1b6732a)
  • zip: Make it parallel as possible (c505389)