@push-stream-std/push-distinct-until-changed (0.0.5)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-distinct-until-changed@0.0.5"@push-stream-std/push-distinct-until-changed": "0.0.5"About this package
push-distinct-until-changed
Emit only when value changes from previous.
Published as @push-stream-std/push-distinct-until-changed.
Synopsis
import { distinctUntilChanged } from '@push-stream-std/push-distinct-until-changed';
import { values } from '@push-stream-std/push-values';
import { collect } from '@push-stream-std/push-collect';
const source = values([1, 1, 2, 2, 2, 3, 1]);
const changed = distinctUntilChanged();
collect(source.pipe(changed), (err, result) => {
console.log(result); // [1, 2, 3, 1]
});
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-distinct-until-changed
Description
A through stream that drops consecutive duplicate values, emitting a value only when it differs from the previously emitted value. By default uses strict equality (===), with an optional custom comparator. Unlike distinct, it only compares against the immediate predecessor, so a value that repeats after a different intermediate value will be emitted again. Useful for state change detection and reducing unnecessary UI updates.
API
distinctUntilChanged(compare)
Returns a through stream that suppresses consecutive duplicate values.
- compare
(a, b) => boolean(optional) — Custom comparison function. If omitted, strict equality (===) is used. - Returns
through— A push-stream through that drops values equal to the last emitted value.
Tests
npm test
Tests cover consecutive equal values, alternating values, custom comparator, single values passthrough, and abort/end propagation.
Requirements
Node.js 18 or later. ESM only.
License
MIT