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
40 lines (35 loc) • 1.05 kB
text/typescript
import sflow from "./index";
import { mergeStream } from "./mergeStream";
import { sleep } from "./utils";
it("merge different type", async () => {
expect(
await sflow(mergeStream(["1", "2", "3", "4"], [5, 6, 7, 8])).toArray(),
).toEqual(["1", 5, "2", 6, "3", 7, "4", 8]);
});
it("zips when same speed", async () => {
expect(
await sflow(mergeStream([1, 2, 3, 4], [5, 6, 7, 8])).toArray(),
).toEqual([1, 5, 2, 6, 3, 7, 4, 8]);
});
it("works when a stream slower", async () => {
expect(
await sflow(
mergeStream(
sflow([1, 2, 3, 4]).forEach(async () => {
await sleep(30);
}),
[],
),
).toArray(),
).toEqual([5, 6, 7, 8, 1, 2, 3, 4]);
});
it("zips in timing order", async () => {
expect(
await sflow(
mergeStream(
sflow([30, 20, 40, 80]).asyncMap(async (ms) => (await sleep(ms), ms)),
sflow([70, 60, 50, 10]).asyncMap(async (ms) => (await sleep(ms), ms)),
),
).toArray(),
).toEqual([10, 20, 30, 40, 50, 60, 70, 80]);
});