UNPKG

lilit

Version:

[![Build status][tr-svg]][travis]

1,379 lines (1,378 loc) 57 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __asyncValues = (this && this.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } }; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("./common"); // OPERATORS function map(f) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_1, _a; try { for (var xs_1 = __asyncValues(xs), xs_1_1; xs_1_1 = yield __await(xs_1.next()), !xs_1_1.done;) { const x = xs_1_1.value; yield yield __await(f(x)); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (xs_1_1 && !xs_1_1.done && (_a = xs_1.return)) yield __await(_a.call(xs_1)); } finally { if (e_1) throw e_1.error; } } }); }; } exports.map = map; function tap(f) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_2, _a; try { for (var xs_2 = __asyncValues(xs), xs_2_1; xs_2_1 = yield __await(xs_2.next()), !xs_2_1.done;) { const x = xs_2_1.value; f(x); yield yield __await(x); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (xs_2_1 && !xs_2_1.done && (_a = xs_2.return)) yield __await(_a.call(xs_2)); } finally { if (e_2) throw e_2.error; } } }); }; } exports.tap = tap; exports.inspect = tap; function forEach(f) { return function (xs) { var xs_3, xs_3_1; return __awaiter(this, void 0, void 0, function* () { var e_3, _a; try { for (xs_3 = __asyncValues(xs); xs_3_1 = yield xs_3.next(), !xs_3_1.done;) { const x = xs_3_1.value; f(x); } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (xs_3_1 && !xs_3_1.done && (_a = xs_3.return)) yield _a.call(xs_3); } finally { if (e_3) throw e_3.error; } } }); }; } exports.forEach = forEach; exports.subscribe = forEach; function reduce(f, init) { return function (xs) { var xs_4, xs_4_1; return __awaiter(this, void 0, void 0, function* () { var e_4, _a; let res = init; try { for (xs_4 = __asyncValues(xs); xs_4_1 = yield xs_4.next(), !xs_4_1.done;) { const x = xs_4_1.value; res = f(res, x); } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (xs_4_1 && !xs_4_1.done && (_a = xs_4.return)) yield _a.call(xs_4); } finally { if (e_4) throw e_4.error; } } return res; }); }; } exports.reduce = reduce; function scan(f, init) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_5, _a; let res = init; try { for (var xs_5 = __asyncValues(xs), xs_5_1; xs_5_1 = yield __await(xs_5.next()), !xs_5_1.done;) { const x = xs_5_1.value; res = f(res, x); yield yield __await(res); } } catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (xs_5_1 && !xs_5_1.done && (_a = xs_5.return)) yield __await(_a.call(xs_5)); } finally { if (e_5) throw e_5.error; } } }); }; } exports.scan = scan; exports.reducutions = scan; function some(p) { return function (xs) { var xs_6, xs_6_1; return __awaiter(this, void 0, void 0, function* () { var e_6, _a; try { for (xs_6 = __asyncValues(xs); xs_6_1 = yield xs_6.next(), !xs_6_1.done;) { const x = xs_6_1.value; if (p(x)) return true; } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (xs_6_1 && !xs_6_1.done && (_a = xs_6.return)) yield _a.call(xs_6); } finally { if (e_6) throw e_6.error; } } return false; }); }; } exports.some = some; function every(p) { return function (xs) { var xs_7, xs_7_1; return __awaiter(this, void 0, void 0, function* () { var e_7, _a; try { for (xs_7 = __asyncValues(xs); xs_7_1 = yield xs_7.next(), !xs_7_1.done;) { const x = xs_7_1.value; if (!p(x)) return false; } } catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (xs_7_1 && !xs_7_1.done && (_a = xs_7.return)) yield _a.call(xs_7); } finally { if (e_7) throw e_7.error; } } return true; }); }; } exports.every = every; function filter(p) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_8, _a; try { for (var xs_8 = __asyncValues(xs), xs_8_1; xs_8_1 = yield __await(xs_8.next()), !xs_8_1.done;) { const x = xs_8_1.value; if (p(x)) yield yield __await(x); } } catch (e_8_1) { e_8 = { error: e_8_1 }; } finally { try { if (xs_8_1 && !xs_8_1.done && (_a = xs_8.return)) yield __await(_a.call(xs_8)); } finally { if (e_8) throw e_8.error; } } }); }; } exports.filter = filter; function partition(p) { return function (xs) { const [xs1, xs2] = common_1.asyncTee(xs); return [filter(p)(xs1), filter((x) => !p(x))(xs2)]; }; } exports.partition = partition; function skip(n) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_9, _a; let i = 0; try { for (var xs_9 = __asyncValues(xs), xs_9_1; xs_9_1 = yield __await(xs_9.next()), !xs_9_1.done;) { const x = xs_9_1.value; if (++i <= n) continue; yield yield __await(x); } } catch (e_9_1) { e_9 = { error: e_9_1 }; } finally { try { if (xs_9_1 && !xs_9_1.done && (_a = xs_9.return)) yield __await(_a.call(xs_9)); } finally { if (e_9) throw e_9.error; } } }); }; } exports.skip = skip; function take(n) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_10, _a; let i = 0; try { for (var xs_10 = __asyncValues(xs), xs_10_1; xs_10_1 = yield __await(xs_10.next()), !xs_10_1.done;) { const x = xs_10_1.value; if (++i > n) break; yield yield __await(x); } } catch (e_10_1) { e_10 = { error: e_10_1 }; } finally { try { if (xs_10_1 && !xs_10_1.done && (_a = xs_10.return)) yield __await(_a.call(xs_10)); } finally { if (e_10) throw e_10.error; } } }); }; } exports.take = take; // TODO: rename? function partitionAt(n) { return function (xs) { const [xs1, xs2] = common_1.asyncTee(xs); return [take(n)(xs1), skip(n)(xs2)]; }; } exports.partitionAt = partitionAt; exports.splitAt = partitionAt; function skipWhile(f) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_11, _a, e_12, _b; const it = common_1.forAwaitableIterator(xs); let first; try { for (var it_1 = __asyncValues(it), it_1_1; it_1_1 = yield __await(it_1.next()), !it_1_1.done;) { const x = it_1_1.value; first = x; if (!f(x)) break; } } catch (e_11_1) { e_11 = { error: e_11_1 }; } finally { try { if (it_1_1 && !it_1_1.done && (_a = it_1.return)) yield __await(_a.call(it_1)); } finally { if (e_11) throw e_11.error; } } yield yield __await(first); try { for (var it_2 = __asyncValues(it), it_2_1; it_2_1 = yield __await(it_2.next()), !it_2_1.done;) { const x = it_2_1.value; yield yield __await(x); } } catch (e_12_1) { e_12 = { error: e_12_1 }; } finally { try { if (it_2_1 && !it_2_1.done && (_b = it_2.return)) yield __await(_b.call(it_2)); } finally { if (e_12) throw e_12.error; } } }); }; } exports.skipWhile = skipWhile; function takeWhile(f) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_13, _a; try { for (var xs_11 = __asyncValues(xs), xs_11_1; xs_11_1 = yield __await(xs_11.next()), !xs_11_1.done;) { const x = xs_11_1.value; if (f(x)) yield yield __await(x); else break; } } catch (e_13_1) { e_13 = { error: e_13_1 }; } finally { try { if (xs_11_1 && !xs_11_1.done && (_a = xs_11.return)) yield __await(_a.call(xs_11)); } finally { if (e_13) throw e_13.error; } } }); }; } exports.takeWhile = takeWhile; function partitionWhile(f) { return function (xs) { const [xs1, xs2] = common_1.asyncTee(xs); return [takeWhile(f)(xs1), skipWhile(f)(xs2)]; }; } exports.partitionWhile = partitionWhile; function find(p) { return function (xs) { var xs_12, xs_12_1; return __awaiter(this, void 0, void 0, function* () { var e_14, _a; try { for (xs_12 = __asyncValues(xs); xs_12_1 = yield xs_12.next(), !xs_12_1.done;) { const x = xs_12_1.value; if (p(x)) return x; } } catch (e_14_1) { e_14 = { error: e_14_1 }; } finally { try { if (xs_12_1 && !xs_12_1.done && (_a = xs_12.return)) yield _a.call(xs_12); } finally { if (e_14) throw e_14.error; } } return null; }); }; } exports.find = find; function findIndex(p) { return function (xs) { var xs_13, xs_13_1; return __awaiter(this, void 0, void 0, function* () { var e_15, _a; let i = 0; try { for (xs_13 = __asyncValues(xs); xs_13_1 = yield xs_13.next(), !xs_13_1.done;) { const x = xs_13_1.value; if (p(x)) return i; i++; } } catch (e_15_1) { e_15 = { error: e_15_1 }; } finally { try { if (xs_13_1 && !xs_13_1.done && (_a = xs_13.return)) yield _a.call(xs_13); } finally { if (e_15) throw e_15.error; } } return -1; }); }; } exports.findIndex = findIndex; function pluck(key) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_16, _a; try { for (var xs_14 = __asyncValues(xs), xs_14_1; xs_14_1 = yield __await(xs_14.next()), !xs_14_1.done;) { const x = xs_14_1.value; yield yield __await(x[key]); } } catch (e_16_1) { e_16 = { error: e_16_1 }; } finally { try { if (xs_14_1 && !xs_14_1.done && (_a = xs_14.return)) yield __await(_a.call(xs_14)); } finally { if (e_16) throw e_16.error; } } }); }; } exports.pluck = pluck; // like pluck, but accepts an iterable of keys function select(keys) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_17, _a; try { for (var xs_15 = __asyncValues(xs), xs_15_1; xs_15_1 = yield __await(xs_15.next()), !xs_15_1.done;) { const x = xs_15_1.value; let r = x; for (const k of keys) { r = r != null ? r[k] : undefined; } yield yield __await(r); } } catch (e_17_1) { e_17 = { error: e_17_1 }; } finally { try { if (xs_15_1 && !xs_15_1.done && (_a = xs_15.return)) yield __await(_a.call(xs_15)); } finally { if (e_17) throw e_17.error; } } }); }; } exports.select = select; function unzip2() { return function (xs) { const [xs1, xs2] = common_1.asyncTee(xs); return [pluck(0)(xs1), pluck(1)(xs2)]; }; } exports.unzip2 = unzip2; function unzip3() { return function (xs) { const [xs1, xs2, xs3] = common_1.asyncTeeN(xs, 3); return [pluck(0)(xs1), pluck(1)(xs2), pluck(2)(xs3)]; }; } exports.unzip3 = unzip3; function unzip(n = 2) { return function (xs) { const xss = common_1.asyncTeeN(xs, n); return xss.map((xs, i) => pluck(i)(xs)); }; } exports.unzip = unzip; function groupBy(f) { return function (xs) { var xs_16, xs_16_1; return __awaiter(this, void 0, void 0, function* () { var e_18, _a; const res = new Map(); try { for (xs_16 = __asyncValues(xs); xs_16_1 = yield xs_16.next(), !xs_16_1.done;) { const x = xs_16_1.value; const key = f(x); if (!res.has(key)) res.set(key, []); res.get(key).push(x); } } catch (e_18_1) { e_18 = { error: e_18_1 }; } finally { try { if (xs_16_1 && !xs_16_1.done && (_a = xs_16.return)) yield _a.call(xs_16); } finally { if (e_18) throw e_18.error; } } return res; }); }; } exports.groupBy = groupBy; function groupByKey(key) { return groupBy((x) => x[key]); } exports.groupByKey = groupByKey; function mapKeys(f) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_19, _a; try { for (var xs_17 = __asyncValues(xs), xs_17_1; xs_17_1 = yield __await(xs_17.next()), !xs_17_1.done;) { const [k, v] = xs_17_1.value; yield yield __await([f(k), v]); } } catch (e_19_1) { e_19 = { error: e_19_1 }; } finally { try { if (xs_17_1 && !xs_17_1.done && (_a = xs_17.return)) yield __await(_a.call(xs_17)); } finally { if (e_19) throw e_19.error; } } }); }; } exports.mapKeys = mapKeys; function mapValues(f) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_20, _a; try { for (var xs_18 = __asyncValues(xs), xs_18_1; xs_18_1 = yield __await(xs_18.next()), !xs_18_1.done;) { const [k, v] = xs_18_1.value; yield yield __await([k, f(v)]); } } catch (e_20_1) { e_20 = { error: e_20_1 }; } finally { try { if (xs_18_1 && !xs_18_1.done && (_a = xs_18.return)) yield __await(_a.call(xs_18)); } finally { if (e_20) throw e_20.error; } } }); }; } exports.mapValues = mapValues; function pairwise() { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_21, _a; const it = common_1.forAwaitableIterator(xs); let prev = (yield __await(it.next())).value; try { for (var it_3 = __asyncValues(it), it_3_1; it_3_1 = yield __await(it_3.next()), !it_3_1.done;) { const x = it_3_1.value; yield yield __await([prev, x]); prev = x; } } catch (e_21_1) { e_21 = { error: e_21_1 }; } finally { try { if (it_3_1 && !it_3_1.done && (_a = it_3.return)) yield __await(_a.call(it_3)); } finally { if (e_21) throw e_21.error; } } }); }; } exports.pairwise = pairwise; function length() { return function (xs) { var xs_19, xs_19_1; return __awaiter(this, void 0, void 0, function* () { var e_22, _a; let c = 0; try { for (xs_19 = __asyncValues(xs); xs_19_1 = yield xs_19.next(), !xs_19_1.done;) { const _ = xs_19_1.value; c++; } } catch (e_22_1) { e_22 = { error: e_22_1 }; } finally { try { if (xs_19_1 && !xs_19_1.done && (_a = xs_19.return)) yield _a.call(xs_19); } finally { if (e_22) throw e_22.error; } } return c; }); }; } exports.length = length; function min() { return function (xs) { var xs_20, xs_20_1; return __awaiter(this, void 0, void 0, function* () { var e_23, _a; let res = Number.POSITIVE_INFINITY; try { for (xs_20 = __asyncValues(xs); xs_20_1 = yield xs_20.next(), !xs_20_1.done;) { const x = xs_20_1.value; if (x < res) res = x; } } catch (e_23_1) { e_23 = { error: e_23_1 }; } finally { try { if (xs_20_1 && !xs_20_1.done && (_a = xs_20.return)) yield _a.call(xs_20); } finally { if (e_23) throw e_23.error; } } return res; }); }; } exports.min = min; function max() { return function (xs) { var xs_21, xs_21_1; return __awaiter(this, void 0, void 0, function* () { var e_24, _a; let res = Number.NEGATIVE_INFINITY; try { for (xs_21 = __asyncValues(xs); xs_21_1 = yield xs_21.next(), !xs_21_1.done;) { const x = xs_21_1.value; if (x > res) res = x; } } catch (e_24_1) { e_24 = { error: e_24_1 }; } finally { try { if (xs_21_1 && !xs_21_1.done && (_a = xs_21.return)) yield _a.call(xs_21); } finally { if (e_24) throw e_24.error; } } return res; }); }; } exports.max = max; function minMax() { return function (xs) { var xs_22, xs_22_1; return __awaiter(this, void 0, void 0, function* () { var e_25, _a; let min = Number.POSITIVE_INFINITY; let max = Number.NEGATIVE_INFINITY; try { for (xs_22 = __asyncValues(xs); xs_22_1 = yield xs_22.next(), !xs_22_1.done;) { const x = xs_22_1.value; if (x < min) min = x; if (x > max) max = x; } } catch (e_25_1) { e_25 = { error: e_25_1 }; } finally { try { if (xs_22_1 && !xs_22_1.done && (_a = xs_22.return)) yield _a.call(xs_22); } finally { if (e_25) throw e_25.error; } } return [min, max]; }); }; } exports.minMax = minMax; function minBy(cf) { return function (xs) { return __awaiter(this, void 0, void 0, function* () { var e_26, _a; const it = common_1.forAwaitableIterator(xs); const { done, value } = yield it.next(); if (done) return null; let res = value; try { for (var it_4 = __asyncValues(it), it_4_1; it_4_1 = yield it_4.next(), !it_4_1.done;) { const x = it_4_1.value; if (cf(x, res) < 0) res = x; } } catch (e_26_1) { e_26 = { error: e_26_1 }; } finally { try { if (it_4_1 && !it_4_1.done && (_a = it_4.return)) yield _a.call(it_4); } finally { if (e_26) throw e_26.error; } } return res; }); }; } exports.minBy = minBy; function maxBy(cf) { return function (xs) { return __awaiter(this, void 0, void 0, function* () { var e_27, _a; const it = common_1.forAwaitableIterator(xs); const { done, value } = yield it.next(); if (done) return null; let res = value; try { for (var it_5 = __asyncValues(it), it_5_1; it_5_1 = yield it_5.next(), !it_5_1.done;) { const x = it_5_1.value; if (cf(x, res) > 0) res = x; } } catch (e_27_1) { e_27 = { error: e_27_1 }; } finally { try { if (it_5_1 && !it_5_1.done && (_a = it_5.return)) yield _a.call(it_5); } finally { if (e_27) throw e_27.error; } } return res; }); }; } exports.maxBy = maxBy; function minMaxBy(cf) { return function (xs) { return __awaiter(this, void 0, void 0, function* () { var e_28, _a; const it = common_1.forAwaitableIterator(xs); const { done, value } = yield it.next(); if (done) return [null, null]; let min = value; let max = value; try { for (var it_6 = __asyncValues(it), it_6_1; it_6_1 = yield it_6.next(), !it_6_1.done;) { const x = it_6_1.value; if (cf(x, min) < 0) min = x; if (cf(x, max) > 0) max = x; } } catch (e_28_1) { e_28 = { error: e_28_1 }; } finally { try { if (it_6_1 && !it_6_1.done && (_a = it_6.return)) yield _a.call(it_6); } finally { if (e_28) throw e_28.error; } } return [min, max]; }); }; } exports.minMaxBy = minMaxBy; function minByScan(cf) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_29, _a; const it = common_1.forAwaitableIterator(xs); const { done, value } = yield __await(it.next()); if (done) yield yield __await(null); let res = value; try { for (var it_7 = __asyncValues(it), it_7_1; it_7_1 = yield __await(it_7.next()), !it_7_1.done;) { const x = it_7_1.value; if (cf(x, res) < 0) res = x; yield yield __await(res); } } catch (e_29_1) { e_29 = { error: e_29_1 }; } finally { try { if (it_7_1 && !it_7_1.done && (_a = it_7.return)) yield __await(_a.call(it_7)); } finally { if (e_29) throw e_29.error; } } }); }; } exports.minByScan = minByScan; function maxByScan(cf) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_30, _a; const it = common_1.forAwaitableIterator(xs); const { done, value } = yield __await(it.next()); if (done) yield yield __await(null); let res = value; try { for (var it_8 = __asyncValues(it), it_8_1; it_8_1 = yield __await(it_8.next()), !it_8_1.done;) { const x = it_8_1.value; if (cf(x, res) > 0) res = x; yield yield __await(res); } } catch (e_30_1) { e_30 = { error: e_30_1 }; } finally { try { if (it_8_1 && !it_8_1.done && (_a = it_8.return)) yield __await(_a.call(it_8)); } finally { if (e_30) throw e_30.error; } } }); }; } exports.maxByScan = maxByScan; function sum(zero = 0) { return function (xs) { var xs_23, xs_23_1; return __awaiter(this, void 0, void 0, function* () { var e_31, _a; let res = zero; try { for (xs_23 = __asyncValues(xs); xs_23_1 = yield xs_23.next(), !xs_23_1.done;) { const x = xs_23_1.value; res += x; } } catch (e_31_1) { e_31 = { error: e_31_1 }; } finally { try { if (xs_23_1 && !xs_23_1.done && (_a = xs_23.return)) yield _a.call(xs_23); } finally { if (e_31) throw e_31.error; } } return res; }); }; } exports.sum = sum; function replaceWhen(pf, ys) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_32, _a; try { for (var _b = __asyncValues(zip2(xs, ys)), _c; _c = yield __await(_b.next()), !_c.done;) { const [x, y] = _c.value; if (!pf(x)) yield yield __await(x); else yield yield __await(y); } } catch (e_32_1) { e_32 = { error: e_32_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b)); } finally { if (e_32) throw e_32.error; } } }); }; } exports.replaceWhen = replaceWhen; function grouped(n, step = n) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_33, _a; let group = []; try { for (var xs_24 = __asyncValues(xs), xs_24_1; xs_24_1 = yield __await(xs_24.next()), !xs_24_1.done;) { const x = xs_24_1.value; group.push(x); if (group.length === n) { yield yield __await([...group]); for (let i = 0; i < step; i++) group.shift(); } } } catch (e_33_1) { e_33 = { error: e_33_1 }; } finally { try { if (xs_24_1 && !xs_24_1.done && (_a = xs_24.return)) yield __await(_a.call(xs_24)); } finally { if (e_33) throw e_33.error; } } }); }; } exports.grouped = grouped; function startWith(...as) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_34, _a, e_35, _b; try { for (var as_1 = __asyncValues(as), as_1_1; as_1_1 = yield __await(as_1.next()), !as_1_1.done;) { const a = as_1_1.value; yield yield __await(a); } } catch (e_34_1) { e_34 = { error: e_34_1 }; } finally { try { if (as_1_1 && !as_1_1.done && (_a = as_1.return)) yield __await(_a.call(as_1)); } finally { if (e_34) throw e_34.error; } } try { for (var xs_25 = __asyncValues(xs), xs_25_1; xs_25_1 = yield __await(xs_25.next()), !xs_25_1.done;) { const x = xs_25_1.value; yield yield __await(x); } } catch (e_35_1) { e_35 = { error: e_35_1 }; } finally { try { if (xs_25_1 && !xs_25_1.done && (_b = xs_25.return)) yield __await(_b.call(xs_25)); } finally { if (e_35) throw e_35.error; } } }); }; } exports.startWith = startWith; function endWith(...zs) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_36, _a, e_37, _b; try { for (var xs_26 = __asyncValues(xs), xs_26_1; xs_26_1 = yield __await(xs_26.next()), !xs_26_1.done;) { const x = xs_26_1.value; yield yield __await(x); } } catch (e_36_1) { e_36 = { error: e_36_1 }; } finally { try { if (xs_26_1 && !xs_26_1.done && (_a = xs_26.return)) yield __await(_a.call(xs_26)); } finally { if (e_36) throw e_36.error; } } try { for (var zs_1 = __asyncValues(zs), zs_1_1; zs_1_1 = yield __await(zs_1.next()), !zs_1_1.done;) { const z = zs_1_1.value; yield yield __await(z); } } catch (e_37_1) { e_37 = { error: e_37_1 }; } finally { try { if (zs_1_1 && !zs_1_1.done && (_b = zs_1.return)) yield __await(_b.call(zs_1)); } finally { if (e_37) throw e_37.error; } } }); }; } exports.endWith = endWith; function sort(cf) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_38, _a; let arr = []; try { for (var xs_27 = __asyncValues(xs), xs_27_1; xs_27_1 = yield __await(xs_27.next()), !xs_27_1.done;) { const x = xs_27_1.value; arr.push(x); } } catch (e_38_1) { e_38 = { error: e_38_1 }; } finally { try { if (xs_27_1 && !xs_27_1.done && (_a = xs_27.return)) yield __await(_a.call(xs_27)); } finally { if (e_38) throw e_38.error; } } for (const x of arr.sort(cf)) yield yield __await(x); }); }; } exports.sort = sort; function sortScan(cf) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_39, _a; let arr = []; try { for (var xs_28 = __asyncValues(xs), xs_28_1; xs_28_1 = yield __await(xs_28.next()), !xs_28_1.done;) { const x = xs_28_1.value; arr.push(x); yield yield __await([...arr.sort(cf)]); } } catch (e_39_1) { e_39 = { error: e_39_1 }; } finally { try { if (xs_28_1 && !xs_28_1.done && (_a = xs_28.return)) yield __await(_a.call(xs_28)); } finally { if (e_39) throw e_39.error; } } }); }; } exports.sortScan = sortScan; function flatMap(f) { return function (xss) { return __asyncGenerator(this, arguments, function* () { var e_40, _a, e_41, _b; try { for (var xss_1 = __asyncValues(xss), xss_1_1; xss_1_1 = yield __await(xss_1.next()), !xss_1_1.done;) { const xs = xss_1_1.value; try { for (var xs_29 = __asyncValues(xs), xs_29_1; xs_29_1 = yield __await(xs_29.next()), !xs_29_1.done;) { const x = xs_29_1.value; yield yield __await(yield __await(f(x))); } } catch (e_41_1) { e_41 = { error: e_41_1 }; } finally { try { if (xs_29_1 && !xs_29_1.done && (_b = xs_29.return)) yield __await(_b.call(xs_29)); } finally { if (e_41) throw e_41.error; } } } } catch (e_40_1) { e_40 = { error: e_40_1 }; } finally { try { if (xss_1_1 && !xss_1_1.done && (_a = xss_1.return)) yield __await(_a.call(xss_1)); } finally { if (e_40) throw e_40.error; } } }); }; } exports.flatMap = flatMap; function distinctUntilChanged(comp = (a, b) => a === b) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_42, _a; const it = common_1.forAwaitableIterator(xs); let { done, value: initial } = yield __await(it.next()); if (done) return yield __await(void 0); yield yield __await(initial); try { for (var it_9 = __asyncValues(it), it_9_1; it_9_1 = yield __await(it_9.next()), !it_9_1.done;) { const x = it_9_1.value; if (!comp(x, initial)) yield yield __await((initial = x)); } } catch (e_42_1) { e_42 = { error: e_42_1 }; } finally { try { if (it_9_1 && !it_9_1.done && (_a = it_9.return)) yield __await(_a.call(it_9)); } finally { if (e_42) throw e_42.error; } } }); }; } exports.distinctUntilChanged = distinctUntilChanged; function unique(comp = (a, b) => a === b) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_43, _a; const arr = []; try { for (var xs_30 = __asyncValues(xs), xs_30_1; xs_30_1 = yield __await(xs_30.next()), !xs_30_1.done;) { const x = xs_30_1.value; arr.push(x); } } catch (e_43_1) { e_43 = { error: e_43_1 }; } finally { try { if (xs_30_1 && !xs_30_1.done && (_a = xs_30.return)) yield __await(_a.call(xs_30)); } finally { if (e_43) throw e_43.error; } } const unq = arr.filter((x, i, self) => self.findIndex(y => comp(x, y)) === i); for (const u of unq) yield yield __await(u); }); }; } exports.unique = unique; function uniqueSorted(comp = (a, b) => a === b) { return function (xs) { return __asyncGenerator(this, arguments, function* () { var e_44, _a, e_45, _b; const arr = []; try { for (var xs_31 = __asyncValues(xs), xs_31_1; xs_31_1 = yield __await(xs_31.next()), !xs_31_1.done;) { const x = xs_31_1.value; arr.push(x); } } catch (e_44_1) { e_44 = { error: e_44_1 }; } finally { try { if (xs_31_1 && !xs_31_1.done && (_a = xs_31.return)) yield __await(_a.call(xs_31)); } finally { if (e_44) throw e_44.error; } } arr.sort(); try { for (var _c = __asyncValues(distinctUntilChanged(comp)(arr)), _d; _d = yield __await(_c.next()), !_d.done;) { const x = _d.value; yield yield __await(x); } } catch (e_45_1) { e_45 = { error: e_45_1 }; } finally { try { if (_d && !_d.done && (_b = _c.return)) yield __await(_b.call(_c)); } finally { if (e_45) throw e_45.error; } } }); }; } exports.uniqueSorted = uniqueSorted; // CONSTRUCTORS function range(start = 0, end = Number.MAX_SAFE_INTEGER, step = 1) { return __asyncGenerator(this, arguments, function* range_1() { for (let i = start; end > start ? i < end : i > end; i += step) yield yield __await(i); }); } exports.range = range; // TODO: rename to `entries`? function enumerate(xs) { return __asyncGenerator(this, arguments, function* enumerate_1() { var e_46, _a; let i = 0; try { for (var xs_32 = __asyncValues(xs), xs_32_1; xs_32_1 = yield __await(xs_32.next()), !xs_32_1.done;) { const x = xs_32_1.value; yield yield __await([i++, x]); } } catch (e_46_1) { e_46 = { error: e_46_1 }; } finally { try { if (xs_32_1 && !xs_32_1.done && (_a = xs_32.return)) yield __await(_a.call(xs_32)); } finally { if (e_46) throw e_46.error; } } }); } exports.enumerate = enumerate; function concat(...xss) { return __asyncGenerator(this, arguments, function* concat_1() { var e_47, _a; for (const xs of xss) try { for (var xs_33 = __asyncValues(xs), xs_33_1; xs_33_1 = yield __await(xs_33.next()), !xs_33_1.done;) { const x = xs_33_1.value; yield yield __await(x); } } catch (e_47_1) { e_47 = { error: e_47_1 }; } finally { try { if (xs_33_1 && !xs_33_1.done && (_a = xs_33.return)) yield __await(_a.call(xs_33)); } finally { if (e_47) throw e_47.error; } } }); } exports.concat = concat; exports.chain = concat; function zip2(xs, ys) { return __asyncGenerator(this, arguments, function* zip2_1() { const xit = common_1.forAwaitableIterator(xs); const yit = common_1.forAwaitableIterator(ys); while (true) { const [xr, yr] = yield __await(Promise.all([xit.next(), yit.next()])); if (xr.done || yr.done) break; yield yield __await([xr.value, yr.value]); } }); } exports.zip2 = zip2; function zip3(xs, ys, zs) { return __asyncGenerator(this, arguments, function* zip3_1() { const xit = common_1.forAwaitableIterator(xs); const yit = common_1.forAwaitableIterator(ys); const zit = common_1.forAwaitableIterator(zs); while (true) { const [xr, yr, zr] = yield __await(Promise.all([xit.next(), yit.next(), zit.next()])); if (xr.done || yr.done || zr.done) break; yield yield __await([xr.value, yr.value, zr.value]); } }); } exports.zip3 = zip3; function zip(...xss) { return __asyncGenerator(this, arguments, function* zip_1() { const its = xss.map(common_1.forAwaitableIterator); while (true) { const rs = yield __await(Promise.all(its.map(it => it.next()))); if (rs.some(r => r.done)) break; yield yield __await(rs.map(r => r.value)); } }); } exports.zip = zip; // TODO: rename? Is this how regular zip commonly works? function zipOuter(...xss) { return __asyncGenerator(this, arguments, function* zipOuter_1() { const its = xss.map(common_1.forAwaitableIterator); while (true) { const rs = yield __await(Promise.all(its.map(it => it.next()))); if (rs.every(r => r.done)) break; yield yield __await(rs.map(r => r.value)); } }); } exports.zipOuter = zipOuter; function product2(as, bs) { return __asyncGenerator(this, arguments, function* product2_1() { var e_48, _a, e_49, _b; // if (as === bs) [as, bs] = asyncTee(as); let bs2; try { for (var as_2 = __asyncValues(as), as_2_1; as_2_1 = yield __await(as_2.next()), !as_2_1.done;) { const a = as_2_1.value; [bs, bs2] = common_1.asyncTee(bs); try { for (var bs2_1 = __asyncValues(bs2), bs2_1_1; bs2_1_1 = yield __await(bs2_1.next()), !bs2_1_1.done;) { const b = bs2_1_1.value; yield yield __await([a, b]); } } catch (e_49_1) { e_49 = { error: e_49_1 }; } finally { try { if (bs2_1_1 && !bs2_1_1.done && (_b = bs2_1.return)) yield __await(_b.call(bs2_1)); } finally { if (e_49) throw e_49.error; } } } } catch (e_48_1) { e_48 = { error: e_48_1 }; } finally { try { if (as_2_1 && !as_2_1.done && (_a = as_2.return)) yield __await(_a.call(as_2)); } finally { if (e_48) throw e_48.error; } } }); } exports.product2 = product2; function product3(as, bs, cs) { return __asyncGenerator(this, arguments, function* product3_1() { var e_50, _a, e_51, _b, e_52, _c; // if (as === bs) [as, bs] = asyncTee(as); // if (as === cs) [as, cs] = asyncTee(as); // if (bs === cs) [bs, cs] = asyncTee(bs); let bs2; let cs2; try { for (var as_3 = __asyncValues(as), as_3_1; as_3_1 = yield __await(as_3.next()), !as_3_1.done;) { const a = as_3_1.value; [bs, bs2] = common_1.asyncTee(bs); try { for (var bs2_2 = __asyncValues(bs2), bs2_2_1; bs2_2_1 = yield __await(bs2_2.next()), !bs2_2_1.done;) { const b = bs2_2_1.value; [cs, cs2] = common_1.asyncTee(cs); try { for (var cs2_1 = __asyncValues(cs2), cs2_1_1; cs2_1_1 = yield __await(cs2_1.next()), !cs2_1_1.done;) { const c = cs2_1_1.value; yield yield __await([a, b, c]); } } catch (e_52_1) { e_52 = { error: e_52_1 }; } finally { try { if (cs2_1_1 && !cs2_1_1.done && (_c = cs2_1.return)) yield __await(_c.call(cs2_1)); } finally { if (e_52) throw e_52.error; } } } } catch (e_51_1) { e_51 = { error: e_51_1 }; } finally { try { if (bs2_2_1 && !bs2_2_1.done && (_b = bs2_2.return)) yield __await(_b.call(bs2_2)); } finally { if (e_51) throw e_51.error; } } } } catch (e_50_1) { e_50 = { error: e_50_1 }; } finally { try { if (as_3_1 && !as_3_1.done && (_a = as_3.return)) yield __await(_a.call(as_3)); } finally { if (e_50) throw e_50.error; } } }); } exports.product3 = product3; // TODO: generalize to n parameters function product(xs, ...xss) { return __asyncGenerator(this, arguments, function* product_1() { throw new Error('Not implemented'); }); } exports.product = product; // TODO: other name (look at python itertools?) // TODO: fix implementation function combinations2(xs) { return __asyncGenerator(this, arguments, function* combinations2_1() { var e_53, _a, e_54, _b; let [as, bs] = common_1.asyncTee(xs); let bs2; let i = 1; try { for (var as_4 = __asyncValues(as), as_4_1; as_4_1 = yield __await(as_4.next()), !as_4_1.done;) { const a = as_4_1.value; [bs, bs2] = common_1.asyncTee(bs); try { for (var _c = __asyncValues(skip(i++)(bs2)), _d; _d = yield __await(_c.next()), !_d.done;) { const b = _d.value; yield yield __await([a, b]); } } catch (e_54_1) { e_54 = { error: e_54_1 }; } finally { try { if (_d && !_d.done && (_b = _c.return)) yield __await(_b.call(_c)); } finally { if (e_54) throw e_54.error; } } } } catch (e_53_1) { e_53 = { error: e_53_1 }; } finally { try { if (as_4_1 && !as_4_1.done && (_a = as_4.return)) yield __await(_a.call(as_4)); } finally { if (e_53) throw e_53.error; } } }); } exports.combinations2 = combinations2; function combinations3(xs) { return __asyncGenerator(this, arguments, function* combinations3_1() { throw Error('Not implemented'); // let [as, bs, cs] = asyncTeeN(xs, 3); // let bs2: ForOfAwaitable<X>; // let cs2: ForOfAwaitable<X>; // let i = 1; // let j = 2; // for await (const a of as) { // [bs, bs2] = asyncTee(bs); // for await (const b of skip<X>(i++)(bs2)) { // [cs, cs2] = asyncTee(cs); // for await (const c of skip<X>(j++)(cs2)) { // yield [a, b, c]; // } // } // } }); } exports.combinations3 = combinations3; function combinations(xs, r = 2) { return __asyncGenerator(this, arguments, function* combinations_1() { throw Error('Not implemented'); }); } exports.combinations = combinations; function combinationsWithReplacement2(xs) {