@push-stream-std/push-concat-map-eager (0.0.5)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-concat-map-eager@0.0.5"@push-stream-std/push-concat-map-eager": "0.0.5"About this package
push-concat-map-eager
Like flatMap but with eager inner stream execution.
Published as @push-stream-std/push-concat-map-eager.
Synopsis
import concatMapEager from '@push-stream-std/push-concat-map-eager';
const eager = concatMapEager(x => [x * 2, x * 2 + 1], { concurrency: 4 });
source.pipe(eager).pipe(sink);
// Input: 1, 2, 3
// Output: 2, 3, 4, 5, 6, 7
Install
npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-concat-map-eager
Description
A through stream that maps each input value via a mapper function and flattens the result. Inner push-stream results are started eagerly up to a configurable concurrency limit, but emitted results maintain the original input order via indexed buffering. Static values (arrays or scalars) are emitted inline. More efficient than sequential concatMap for I/O-bound work. Uses a head pointer pattern for amortized O(1) queue operations.
API
concatMapEager(mapper, options)
Creates an eager concat-map through stream.
- mapper
(value) => result– Function called for each input value. May return a push-stream source (haspipe()), an array, or a scalar value. - options
object(optional):- concurrency
number(defaultInfinity) – Maximum number of inner streams to run concurrently. Additional inputs are queued until an inner stream completes.
- concurrency
- Returns A through stream with
pipe(),write(),end(),abort(),resume(),paused, andended.
Tests
npm test
Tests cover mapping and flattening arrays, concurrency limit enforcement (max active streams), order preservation with array-returning mappers, empty source producing no output, and mapper returning simple scalar values (non-array, non-stream).
Requirements
Node.js 18 or later. ESM only.
License
MIT