import { Pipe } from "../pipe.js"; import { assertSync } from "../util/index.js"; export function difference(source: Iterable): Pipe { assertSync(source); return () => { let sourceSet: Set = source instanceof Set ? source : new Set(source); return (result: IteratorResult): IteratorResult => { if (result?.done) { return result; } if (!sourceSet.has(result.value)) { sourceSet.add(result.value); return result; } }; } }