push-stream-std

@push-stream-std/push-concat-map-eager (0.0.4)

Published 2026-07-19 23:31:25 +00:00 by Dvorak

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.4
"@push-stream-std/push-concat-map-eager": "0.0.4"

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 (has pipe()), an array, or a scalar value.
  • options object (optional):
    • concurrency number (default Infinity) – Maximum number of inner streams to run concurrently. Additional inputs are queued until an inner stream completes.
  • Returns A through stream with pipe(), write(), end(), abort(), resume(), paused, and ended.

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

Keywords

push-stream stream concatMap flatMap map parallel
Details
npm
2026-07-19 23:31:25 +00:00
0
MIT
4.0 KiB
Assets (1)
Versions (5) View all
0.0.7 2026-07-21
0.0.6 2026-07-20
0.0.5 2026-07-20
0.0.4 2026-07-19
0.0.3 2026-07-19