UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

20 lines 829 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unzip = unzip; const spy_1 = require("./spy"); const tee_1 = require("./tee"); const map_1 = require("./map"); /** * The inverse of `zip` and `zipLongest`. This function disaggregates the elements of the input iterator. The nth * iterator in the returned tuple contains the nth element of each value in the input iterator. The length of the * returned tuple is determined by the length of the first value in the input iterator. */ function unzip(arg) { const [[head], it] = (0, spy_1.default)(arg); const n = Array.isArray(head) ? head.length : 1; if (n < 2) return [it]; return (0, tee_1.default)(it, n).map((it, i) => (0, map_1.default)(it, v => v[i])); } exports.default = unzip; //# sourceMappingURL=unzip.js.map