import snoflow, { reduces, uniqs } from "."; it("tees", async () => { let flow1 = snoflow([1, 2, 3]); const flow2 = flow1.tees((x) => (flow1 = x)); expect(flow1.locked).toEqual(false); const flow3 = flow1.tees((b) => (flow1 = b)); expect(flow1.locked).toEqual(false); const flow4 = flow1.tees(); expect(flow1.locked).toEqual(true); expect(await flow2.toArray()).toEqual([1, 2, 3]); expect(await flow3.toArray()).toEqual([1, 2, 3]); expect(await flow4.toArray()).toEqual([1, 2, 3]); }); it("uniqs", async () => { let flow0 = snoflow([1, 4, 2, 2, 3, 3, {}, {}]); expect(await flow0.through(uniqs()).toArray()).toEqual([1, 4, 2, 3, {}, {}]); }); it("latests", async () => { let flow0 = snoflow([1, 2, 3, 3]); // reduces(new Set(), (s, x) => s.add(s)) // .through((function() { // new // })()) }); function lasts(): TransformStream { let last: T; const ready = Promise.withResolvers(); const writable = new WritableStream({ write: (chunk) => { last = chunk; ready.resolve(); }, }); const readable = new ReadableStream({ pull: async (ctrl) => { await ready.promise; ctrl.enqueue(last); }, }); return { writable, readable }; } // it("using", async () => { // let p: snoflow; // await (async function () { // await using f = snoflow([1, 2, 3]); // p = f; // expect(f.locked).toBe(false); // })(); // expect(await p!.toArray()).toEqual([1, 2, 3]); // expect(p!.locked).toBe(true); // // expect(f.locked).toBe(true); // });