push-stream-std

@push-stream-std/push-switch-map (0.0.9)

Published 2026-07-21 04:01:07 +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-switch-map@0.0.9
"@push-stream-std/push-switch-map": "0.0.9"

About this package

@push-stream-std/push-switch-map

Map each value to an inner push-stream source, canceling the previous inner stream on each new outer value.

Published as @push-stream-std/push-switch-map.

Synopsis

import switchMap from '@push-stream-std/push-switch-map';

const innerA = values(['A1', 'A2', 'A3']);
const innerB = values(['B1', 'B2']);

const switcher = switchMap(function (streamId) {
  return streamId === 'A' ? innerA : innerB;
});

values(['A', 'B']).pipe(switcher).pipe(sink);

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-switch-map

Why

A push-stream through that applies a mapper function to each incoming value. The mapper must return a push-stream source (inner). When a new outer value arrives, the previous inner source is aborted and the new inner source is piped to the sink via an internal proxy. Values from the inner source are forwarded downstream. If the mapper throws, the stream ends with the thrown error.

API

switchMap(mapper)

Creates a switch-map through stream.

  • mapper (outerValue) => innerSource – Function that takes an outer value and returns a push-stream source. The returned source should have pipe(), abort(), and optionally resume().
  • Returns A through object with pipe(), write(), end(), abort(), resume(), source, paused, ended.

Tests

npm test

Tests cover canceling previous inner on new outer value, forwarding inner values, handling mapper errors, normal end, abort propagation to current inner, and empty/undefined inner source handling.

Requirements

Node.js 22 or later. ESM only.

Keywords

push-stream switch-map switch flatten
Details
npm
2026-07-21 04:01:07 +00:00
0
SEE LICENSE IN LICENSE
latest
3.4 KiB
Assets (1)
Versions (6) 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-19
0.0.5 2026-07-19