import { Pipe } from "../pipe.js"; import { assertSync, push, Yields } from "../util/index.js"; export function union(source: Iterable): Pipe { assertSync(source); return () => { let exists: Set = new Set(); return (result: IteratorResult): IteratorResult | Array> => { if (result?.done) { let results: Array = new Array(); for (const item of source) { if (!exists.has(item)) { exists.add(item); results.push(item); } } return push(Yields(results), result); } if (!exists.has(result.value)) { exists.add(result.value); return result; } }; } }