Skip to content

Instantly share code, notes, and snippets.

@joeltg
Created August 27, 2020 13:16
Show Gist options
  • Select an option

  • Save joeltg/5dd2df2a9a7a62e9820d24e8549d54ea to your computer and use it in GitHub Desktop.

Select an option

Save joeltg/5dd2df2a9a7a62e9820d24e8549d54ea to your computer and use it in GitHub Desktop.
Zip two iterables
export const zip = <A, B>(
a: Iterable<A>,
b: Iterable<B>
): Iterable<[A, B]> => ({
[Symbol.iterator]() {
const iterA = a[Symbol.iterator]()
const iterB = b[Symbol.iterator]()
return {
next() {
const resultA = iterA.next()
const resultB = iterB.next()
return {
value: [resultA.value, resultB.value],
done: resultA.done || resultB.done,
}
},
}
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment