sflow
Version:
sflow is a powerful and highly-extensible library designed for processing and manipulating streams of data effortlessly. Inspired by the functional programming paradigm, it provides a rich set of utilities for transforming streams, including chunking, fil
15 lines (13 loc) • 381 B
text/typescript
import type { Awaitable } from "./Awaitable";
export function mapMixins<
T extends Record<string, any>,
R extends Record<string, any>,
>(
fn: (x: T, i: number) => Awaitable<R>,
): TransformStream<T, Omit<T, keyof R> & R> {
let i = 0;
return new TransformStream({
transform: async (chunk, ctrl) =>
ctrl.enqueue({ ...chunk, ...(await fn(chunk, i++)) }),
});
}