import { IEnumerable } from "../../types" ; import { BasicEnumerable } from "../BasicEnumerable" ; type ZipFunc = { param first param second returns < TFirst , TSecond > ( first , second ) : IEnumerable < [ TFirst , TSecond ] > ; param first param second param resultSelector returns < TFirst , TSecond , TResult > ( first , second , resultSelector ) : IEnumerable < TResult > ; } ; export const zip = < TFirst , TSecond , TResult > ( source , second , resultSelector ? ) : IEnumerable < TResult > | IEnumerable < [ TFirst , TSecond ] > => { if ( resultSelector ) { return zip2 ( source , second , resultSelector ) ; } else { return zip1 ( source , second ) ; } } ; const zip1 = < TFirst , TSecond > ( source , second ) : IEnumerable < [ TFirst , TSecond ] > => { function * iterator ( ) { const firstIterator = source [ Symbol . iterator ] ( ) ; const secondIterator = second [ Symbol . iterator ] ( ) ; while ( true ) { const a = firstIterator . next ( ) ; const b = secondIterator . next ( ) ; if ( a . done && b . done ) { break ; } else { yield [ a . value , b . value ] ; } } } return new BasicEnumerable ( iterator ) ; } ; const zip2 = < TFirst , TSecond , TResult > ( source , second , resultSelector ) => { function * iterator ( ) { const firstIterator = source [ Symbol . iterator ] ( ) ; const secondIterator = second [ Symbol . iterator ] ( ) ; while ( true ) { const a = firstIterator . next ( ) ; const b = secondIterator . next ( ) ; if ( a . done && b . done ) { break ; } else { yield resultSelector ( a . value , b . value ) ; } } } return new BasicEnumerable ( iterator ) ; } ;