@jasmith79/sequable
Version:
Library functions for working with generators
26 lines (25 loc) • 740 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.zip = void 0;
const sequable_js_1 = require("./sequable.js");
/**
* Yields tuples of the results of the two given Iterables, Iterators, or
* generator functions.
*
* @param a The first sequence to combine.
* @param b The second sequence to combine.
*/
function* zip(a, b) {
const xs = (0, sequable_js_1.toIterator)(a);
const ys = (0, sequable_js_1.toIterator)(b);
let x = xs.next();
let y = ys.next();
while (!x.done && !y.done) {
yield [x.value, y.value];
x = xs.next();
y = ys.next();
}
if (x.value !== undefined && y.value !== undefined)
return [x.value, y.value];
}
exports.zip = zip;