import type { Awaitable } from "./Awaitable"; export const filters: { (): TransformStream>; (fn: (x: T, i: number) => Awaitable): TransformStream; } = (fn?: (...args: any[]) => any) => { let i = 0; return new TransformStream({ transform: async (chunk, ctrl) => { if (fn) { const shouldEnqueue = await fn(chunk, i++); if (shouldEnqueue) ctrl.enqueue(chunk); } else { const isNull = undefined === chunk || null === chunk; if (!isNull) ctrl.enqueue(chunk); } }, }); };