UNPKG

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 (12 loc) 416 B
import type { Awaitable } from "./Awaitable"; /** For each loop on stream, you can modify the item by x.property = 123 */ export function forEachs<T>(fn: (x: T, i: number) => Awaitable<void | any>) { let i = 0; return new TransformStream<T, T>({ transform: async (chunk, ctrl) => { const ret = fn(chunk, i++); ret instanceof Promise ? await ret : ret; ctrl.enqueue(chunk); }, }); }