All files zip.ts

100% Statements 14/14
100% Branches 2/2
100% Functions 2/2
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 225x 5x     12x 12x   12x 3x 3x 3x 3x 3x 16x 8x 8x         5x  
import { Collection, asIterable } from './utils'
import Sequence from './Sequence'
 
function zip<T, U>(a: Collection<T>, b: Collection<U>) {
  const aIterable = asIterable(a)
  const bIterable = asIterable(b)
 
  return new Sequence(function* (): Iterator<[T, U]> {
    const aIterator = aIterable[Symbol.iterator]()
    const bIterator = bIterable[Symbol.iterator]()
    let aValue = aIterator.next()
    let bValue = bIterator.next()
    while(!aValue.done && !bValue.done) {
      yield [aValue.value, bValue.value]
      aValue = aIterator.next()
      bValue = bIterator.next()
    }
  })
}
 
export default zip