@push-stream-std/push-partition (0.0.8)
Published 2026-07-20 21:38:23 +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-partition@0.0.8"@push-stream-std/push-partition": "0.0.8"About this package
@push-stream-std/push-partition
Split a stream into two branches based on a predicate — one for truthy, one for falsy.
Published as @push-stream-std/push-partition.
Synopsis
import partition from '@push-stream-std/push-partition';
import pushable from '@push-stream-std/push-pushable';
import concat from '@push-stream-std/push-concat';
const source = pushable();
const [evens, odds] = partition(function isEven(x) {
return x % 2 === 0;
}, source);
evens.pipe(concat((err, result) => {
console.log('evens:', result); // [2, 4]
}));
odds.pipe(concat((err, result) => {
console.log('odds:', result); // [1, 3, 5]
}));
source.push(1);
source.push(2);
source.push(3);
source.push(4);
source.push(5);
source.end();
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-partition
Why
A stream splitter that routes values through a predicate function into two output source streams. Values where predicate(value) returns truthy go to the first branch; falsy values go to the second. Each branch supports independent piping, resuming, and aborting. If the predicate throws, both branches end with that error.
API
partition(predicate, source)
Splits a source stream into two branches.
- predicate
(value) => boolean– Determines which branch receives each value. - source
source stream– The input source to partition. - Returns
[trueBranch, falseBranch]– Two source streams. Each supportspipe(),resume(), andabort(). Both receiveend()andabort()signals from the source.
Tests
npm test
Tests cover routing values to correct branch, independent branch piping, end propagation to both branches, abort handling, and predicate errors.
Requirements
Node.js 22 or later. ESM only.
Dependencies
Dependencies
| ID | Version |
|---|---|
| @push-stream-std/push-stream-base | * |
Keywords
push-stream
stream
partition
split
filter