import type { Curried } from '../../compositions/curry.js'; import { type Purried, purry } from '../../compositions/purry.js'; import type { MaybePromise, Series, StaticSeries, SyncSeries } from '../../controls/types.js'; import { filterAsync, filterSync } from '../filters/filter.js'; import { _toSet } from './_to-set.js'; const _syncIntersectionBy = ( input: SyncSeries, other: StaticSeries, key: (value: T) => U, ): Generator => { const otherSet = _toSet(other); return filterSync(input, value => otherSet.has(key(value))); }; const _asyncIntersectionBy = ( input: Series, other: StaticSeries, key: (value: Awaited) => MaybePromise, ): AsyncGenerator> => { const otherSet = _toSet | U>(other); return filterAsync(input, async value => otherSet.has(await key(value))); }; export function intersectionBySync( ...args: Parameters> ): ReturnType>; export function intersectionBySync( ...args: Parameters>> ): ReturnType>>; export function intersectionBySync( ...args: Parameters>> ): ReturnType>> { return purry(_syncIntersectionBy)(...args); } export function intersectionByAsync( ...args: Parameters> ): ReturnType>; export function intersectionByAsync( ...args: Parameters>> ): ReturnType>>; export function intersectionByAsync( ...args: Parameters>> ): ReturnType>> { return purry(_asyncIntersectionBy)(...args); } export namespace intersectionBy { export const sync = intersectionBySync; export const async = intersectionByAsync; }