@push-stream-std/push-find (0.0.5)
Published 2026-07-20 18:59: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-find@0.0.5"@push-stream-std/push-find": "0.0.5"About this package
push-find
Find first matching value in a stream.
Synopsis
import { find } from 'push-find';
const source = [1, 5, 15, 25];
const finder = find(x => x > 10);
finder.pipe({
write: (v) => console.log(v), // 15
end: () => {},
get paused() { return false; }
});
source.pipe(finder);
Install
npm install @push-stream-std/push-find
Description
A through stream that searches for the first value matching a predicate. When found, emits the value and ends the stream. Non-matching values are dropped.
API
find(predicate)
predicate: Function to test each value. Returntrueto emit and end.
Returns a stream with:
pipe(sink): Connect to a sink streamwrite(data): Receive a valueend(err): Signal end of streamsource: Property for source attachment
Tests
npm test
Tests cover:
- Finding matching value
- Handling no match
- Source abort on match
Benchmarks
npm run bench
Benchmark results on Node.js 23, 100 values, warmup=10, iterations=100:
| Operation | Speed |
|---|---|
| find first match at start | ~65,000 ops/s |
| find first match at middle | ~40,000 ops/s |
| find first match at end | ~21,000 ops/s |
| find no match | ~42,000 ops/s |
| find with predicate evaluation | ~50,000 ops/s |
Requirements
Node.js 18 or later. ESM only.
License
MIT
Keywords
push-stream
find
search
short-circuit