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

17 lines (16 loc) 429 B
import type { Awaitable } from "./Awaitable"; export const reduceEmits: { <T, S, R>( fn: (state: S, x: T, i: number) => Awaitable<{ next: S; emit: R }>, state: S, ): TransformStream<T, R>; } = (fn, _state) => { let i = 0; return new TransformStream({ transform: async (chunk, ctrl) => { const { next, emit } = await fn(_state, chunk, i++); _state = next; ctrl.enqueue(emit); }, }); };