import { fromAsync } from "../../async/static/fromAsync" ; import { IAsyncEnumerable , IAsyncEqualityComparer , IEnumerable } from "../../types" ; param first param second param comparer returns export const intersectAsync = < TSource > ( first , second , comparer ) : IAsyncEnumerable < TSource > => { async function * iterator ( ) { const firstResults = [ ] ; for await ( const item of first . distinctAsync ( comparer ) ) { firstResults . push ( item ) ; } if ( firstResults . length === 0 ) { return ; } const secondResults = [ ... second ] ; 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 ) { yield firstValue ; break ; } } } } return fromAsync ( iterator ) ; } ;