push-stream-std

@push-stream-std/push-flatmap (0.0.5)

Published 2026-07-19 23:31:38 +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-flatmap@0.0.5
"@push-stream-std/push-flatmap": "0.0.5"

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), or null/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

Dependencies

Dependencies

ID Version
@push-stream-std/push-stream-base *

Keywords

push-stream stream flatmap map
Details
npm
2026-07-19 23:31:38 +00:00
0
MIT
3.8 KiB
Assets (1)
Versions (7) View all
0.0.9 2026-07-21
0.0.8 2026-07-20
0.0.7 2026-07-20
0.0.6 2026-07-20
0.0.5 2026-07-19