+20
-1
@@ -101,2 +101,20 @@ function addSymbolIterator(obj) { | ||
| function zip(iters) { | ||
| // convert input to iters just in case | ||
| iters = iters.map(getOrCreateIterator); | ||
| return wrapNextFunction(function next() { | ||
| const values = iters.map(iter => iter.next()); | ||
| // if they are all done, stop | ||
| if (values.every(({ done }) => done)) { | ||
| return { done: true }; | ||
| } else { | ||
| return { | ||
| done: false, | ||
| value: values.map(({ value }) => value) | ||
| }; | ||
| } | ||
| }); | ||
| } | ||
| if (typeof module === "object") { | ||
@@ -114,4 +132,5 @@ module.exports = { | ||
| getOrCreateIterator, | ||
| wrapNextFunction | ||
| wrapNextFunction, | ||
| zip | ||
| }; | ||
| } |
+1
-1
| { | ||
| "name": "iter-fun", | ||
| "version": "0.1.2", | ||
| "version": "0.2.0", | ||
| "description": "Fun with Iterables", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+9
-0
@@ -57,2 +57,11 @@ # iter-fun | ||
| // converts a next function into a fully functioning iterable | ||
| import { zip } from "iter-fun"; | ||
| const zeros = [0, 0, 0, ...]; | ||
| const twos = [2, 2, 2, ...]; | ||
| const sixties = [60, 60, 60, ...]; | ||
| const iters = [zeros, twos, sixties]; | ||
| const zipped = zip(iters); | ||
| zipped.next(); | ||
| // { done: false, value: [0, 2, 60] } | ||
| ``` |
12222
5.92%121
16.35%67
15.52%