Created
August 27, 2020 13:16
-
-
Save joeltg/5dd2df2a9a7a62e9820d24e8549d54ea to your computer and use it in GitHub Desktop.
Zip two iterables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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