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 (18 loc) 735 B
import type { FlowSource } from "./FlowSource"; import { toStream } from "./froms"; import { parallels } from "./parallels"; /** * return a transform stream that merges streams from sources * don't get confused with mergeStreamw * merges : returns a TransformStream, which also merges upstream * mergeStream: returns a ReadableStream, which doesnt have upstream */ export const merges: <T>(...streams: FlowSource<T>[]) => TransformStream<T, T> = (...srcs: FlowSource<any>[]) => { if (!srcs.length) return new TransformStream(); const upstream = new TransformStream(); return { writable: upstream.writable, readable: parallels(upstream.readable, ...srcs.map(toStream)), } as TransformStream; };