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

19 lines (17 loc) 397 B
import type { Awaitable } from "./Awaitable"; export function mapAddFields< K extends string, T extends Record<string, any>, R, >(key: K, fn: (x: T, i: number) => Awaitable<R>) { let i = 0; return new TransformStream< T, Omit<T, K> & { [key in K]: R; } >({ transform: async (chunk, ctrl) => ctrl.enqueue({ ...chunk, [key]: await fn(chunk, i++) }), }); }