Typed, lazy, immutable data pipelines — compose map, filter, and reduce with full TypeScript inference across sync and async transformations.
Import
import { pipe, map, filter, reduce, Pipeline } from "bytekit/pipeline";// or from the root entry:import { pipe, map, filter, reduce } from "bytekit";
What it does
The pipeline system lets you compose typed transformation operators into a reusable, lazy, immutable pipeline. Nothing executes until you call .process(data). Each .pipe() call returns a newPipeline instance — the original is never mutated.
map — transform each element. Async functions run concurrently (Promise.all).
filter — retain elements by predicate. Async predicates run concurrently.
reduce — accumulate to a scalar. Reducer steps run sequentially.
PipelineOp<TIn, TOut>
type PipelineOp<TIn, TOut> = (input: TIn) => TOut | Promise<TOut>;
The atomic unit of a pipeline — a function that transforms a value synchronously or asynchronously.
Appends an operator. Returns a newPipeline. Does not mutate this.
process(data)
Executes all operators sequentially. Always returns a Promise.
pipe(...ops)
Creates a typed Pipeline from a sequence of operators. Type inference flows left-to-right for up to 7 operators. Use the escape-hatch overload for dynamic/longer pipelines.
// 1-op — full inferenceconst p1 = pipe(filter<number>((n) => n > 0));// 3-op — Pipeline<number[], number> inferred automaticallyconst p3 = pipe( filter<number>((n) => n > 0), map<number, string>((n) => n.toFixed(2)), reduce<string, number>((acc, s) => acc + s.length, 0));// Escape hatch for dynamic / long pipelines (no type inference):const dynamic = pipe<number[]>(...ops);
map<T, U>(fn)
function map<T, U>( fn: (item: T, index: number) => U | Promise<U>): PipelineOp<T[], U[]>
Parameter
Type
Description
fn
(item: T, index: number) => U | Promise<U>
Mapping function. Receives item and its 0-based index.
Returns
PipelineOp<T[], U[]>
All items processed concurrently; order preserved.