The Interactive Extensions for JavaScript (IxJS)

7.0.0 · active · verified Sun Apr 19

IxJS, currently stable at version 7.0.0, is a JavaScript library providing the "Interactive Extensions" for composing synchronous and asynchronous pull-based collections. It extends the familiar Array#extras style (like map, filter, reduce) to native JavaScript `Iterable` and `AsyncIterable` objects, as well as generators and async generators. Unlike push-based reactive libraries such as RxJS, IxJS focuses on consumer-driven data flow, making it particularly well-suited for I/O operations where data is pulled when ready. The library offers distinct modules for synchronous (`ix/iterable`) and asynchronous (`ix/asynciterable`) operations, supporting both pipeable operators and a prototype-extension approach for bundling flexibility. It ships with full TypeScript type definitions and maintains a steady release cadence, typically with minor versions for features and bug fixes, with major versions addressing internal changes or deeper refactorings.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a synchronous `Iterable` from a generator function and transforming it using pipeable `filter` and `map` operators, then iterating through the results.

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

// A synchronous generator function
function* numberGenerator() {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
  yield 5;
  yield 6;
}

// Create an Iterable from the generator and apply pipeable operators
const results = from(numberGenerator()).pipe(
  filter(x => x % 2 === 0), // Keep only even numbers
  map(x => x * 10)         // Multiply by 10
);

console.log('Synchronous Iterable results:');
for (const item of results) {
  console.log(`Next: ${item}`);
}

// To demonstrate AsyncIterable, imagine an async data source
// import { from as asyncFrom } from 'ix/asynciterable';
// import { filter as asyncFilter, map as asyncMap } from 'ix/asynciterable/operators';

// async function* asyncNumberGenerator() {
//   for (let i = 1; i <= 6; i++) {
//     await new Promise(resolve => setTimeout(resolve, 50));
//     yield i;
//   }
// }

// async function runAsyncExample() {
//   const asyncResults = asyncFrom(asyncNumberGenerator()).pipe(
//     asyncFilter(x => x % 2 !== 0), // Keep only odd numbers
//     asyncMap(x => x + 100)       // Add 100
//   );

//   console.log('\nAsynchronous Iterable results:');
//   for await (const item of asyncResults) {
//     console.log(`Next Async: ${item}`);
//   }
// }

// runAsyncExample();

view raw JSON →