import { IAsyncEqualityComparer , IAsyncParallel , IParallelEnumerable , ParallelGeneratorType } from "../../types" ; import { BasicParallelEnumerable } from "../BasicParallelEnumerable" ; param first param second param comparer returns export const intersectAsync = < TSource > ( first , second , comparer ) : IParallelEnumerable < TSource > => { const generator = async ( ) => { const firstResults = await first . distinctAsync ( comparer ) . toArray ( ) ; if ( firstResults . length === 0 ) { return [ ] ; } const secondResults = await second . toArray ( ) ; const results = new Array < TSource > ( ) ; for ( let i = 0 ; i < firstResults . length ; i ++ ) { const firstValue = firstResults [ i ] ; for ( let j = 0 ; j < secondResults . length ; j ++ ) { const secondValue = secondResults [ j ] ; if ( await comparer ( firstValue , secondValue ) === true ) { results . push ( firstValue ) ; break ; } } } return results ; } ; return new BasicParallelEnumerable ( { generator , type : ParallelGeneratorType . PromiseToArray , } ) ; } ;