import type { Curried } from '../../compositions/curry.js'; import { type Purried, purry } from '../../compositions/purry.js'; import type { Series, StaticSeries, SyncSeries } from '../../controls/types.js'; import { filterAsync, filterSync } from '../filters/filter.js'; import { _toSet } from './_to-set.js'; const _syncIntersection = ( input: SyncSeries, other: StaticSeries, ): Generator => { const otherSet = _toSet(other); return filterSync(input, (value): value is T & U => otherSet.has(value)); }; const _asyncIntersection = ( input: Series, other: StaticSeries, ): AsyncGenerator & U> => { const otherSet = _toSet | U>(other); return filterAsync(input, (value): value is Awaited & U => otherSet.has(value)); }; export function intersectionSync( ...args: Parameters> ): ReturnType>; export function intersectionSync( ...args: Parameters>> ): ReturnType>>; export function intersectionSync( ...args: Parameters>> ): ReturnType>> { return purry(_syncIntersection)(...args); } export function intersectionAsync( ...args: Parameters> ): ReturnType>; export function intersectionAsync( ...args: Parameters>> ): ReturnType>>; export function intersectionAsync( ...args: Parameters>> ): ReturnType>> { return purry(_asyncIntersection)(...args); } export namespace intersection { export const sync = intersectionSync; export const async = intersectionAsync; }