@push-stream-std/push-flatmap (0.0.6)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-flatmap@0.0.6"@push-stream-std/push-flatmap": "0.0.6"About this package
push-flatmap
Map each value to a stream and flatten.
Published as @push-stream-std/push-flatmap.
Synopsis
import { flatMap } from '@push-stream-std/push-flatmap';
import { values } from '@push-stream-std/push-values';
import { collect } from '@push-stream-std/push-collect';
const expand = flatMap(value => values([value, value]));
values([1, 2, 3])
.pipe(expand)
.pipe(collect((err, results) => {
console.log(results); // [1, 1, 2, 2, 3, 3]
}));
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-flatmap
Description
For each incoming value, calls the mapper function to produce a push-stream source. Each inner stream is fully drained in sequence before the next input value is processed (sequential flattening). The mapper can also return a plain object (treated as a single-value source) or null/undefined (skipped). Aborting the flatmap propagates to the current inner stream.
API
flatMap(mapper)
mapper-function(value)- Called for each incoming value. Returns a push-stream source, a plain object (wrapped as single-value source), ornull/undefined(skipped).
Returns a push-stream through stream. Pipe a source into it, pipe it to a sink. Each value from the source is passed to the mapper; the resulting inner stream is drained completely before processing the next value. Uses O(1) amortized queue operations via head pointer pattern.
Tests
npm test
Tests cover basic stream mapping, immediate value wrapping, null/undefined skipping, error propagation from mapper, end propagation, abort propagation to inner streams, and backpressure handling.
Requirements
Node.js 18 or later. ESM only.
License
MIT