Skip to content

IxJS version 3.0

Choose a tag to compare

@mattpodwysocki mattpodwysocki released this 02 Feb 22:46
· 154 commits to master since this release
b2082aa

At long last, IxJS v3.0 is here! There are a lot of changes with this release to be more in line with RxJS 6+ with piped operators. We have still kept the "add to prototype" methods as well which can be used to augment operators directly onto the AsyncIterable and Iterable objects.

Importing operators

Much like RxJS, IxJS operators can now be imported using the following for AsyncIterable. The same applies to Iterable much as we are doing with AsyncIterable down below.

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

async function* getData() {
  yield 1;
  yield 2;
  yield 3;
}

const results = from(getData()).pipe(
  map(async (item, index) => item * index),
  filter(async (item, index) => index % 2 === 0)
);

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

Adding Operators to the prototype

Much like earlier versions of IxJS and RxJS, you can still add onto the prototype for chaining purposes.

import { AsyncIterableX as AsyncIterable } from 'ix/asynciterable';
import 'ix/add/asynciterable/from';
import 'ix/add/asynciterable-operators/map';
import 'ix/add/asynciterable-operators/filter';

async function* getData() {
  yield 1;
  yield 2;
  yield 3;
}

const results = Iterable.from(getData())
  .map(async (item, index) => item * index)
  .filter(async (item, index) => index % 2 === 0);

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

The forEach operator is already added just in case you wanted to use lambdas all the way through such as the following which has also as a catch method as the result from .forEach is a promise.

const results = Iterable.from(getData())
  .map(async (item, index) => item * index)
  .filter(async (item, index) => index % 2 === 0)
  .forEach(result => console.log(`Next ${result}`))
  .catch(err => console.log(`Error ${err}`));