itertools 2.2.3 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +16 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -31
- package/dist/index.d.ts +36 -31
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/package.json +12 -13
package/dist/index.cjs
CHANGED
|
@@ -270,7 +270,7 @@ function* islice(iterable, stopOrStart, possiblyStop, step = 1) {
|
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
-
function*
|
|
273
|
+
function* izip(xs, ys) {
|
|
274
274
|
const ixs = iter(xs);
|
|
275
275
|
const iys = iter(ys);
|
|
276
276
|
for (; ; ) {
|
|
@@ -298,7 +298,7 @@ function* izip3(xs, ys, zs) {
|
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
-
var
|
|
301
|
+
var izip2 = izip;
|
|
302
302
|
function* izipLongest2(xs, ys, filler) {
|
|
303
303
|
const filler_ = filler;
|
|
304
304
|
const ixs = iter(xs);
|
|
@@ -357,6 +357,17 @@ function* permutations(iterable, r) {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
|
+
function* repeat(thing, times) {
|
|
361
|
+
if (times === void 0) {
|
|
362
|
+
for (; ; ) {
|
|
363
|
+
yield thing;
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
for (const _ of range(times)) {
|
|
367
|
+
yield thing;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
360
371
|
function* takewhile(iterable, predicate) {
|
|
361
372
|
const it = iter(iterable);
|
|
362
373
|
let res;
|
|
@@ -414,7 +425,7 @@ var any = some;
|
|
|
414
425
|
function contains(haystack, needle) {
|
|
415
426
|
return some(haystack, (x) => x === needle);
|
|
416
427
|
}
|
|
417
|
-
function*
|
|
428
|
+
function* enumerate(iterable, start = 0) {
|
|
418
429
|
let index = start;
|
|
419
430
|
for (const value of iterable) {
|
|
420
431
|
yield [index++, value];
|
|
@@ -571,7 +582,8 @@ function flatmap(iterable, mapper) {
|
|
|
571
582
|
|
|
572
583
|
|
|
573
584
|
|
|
574
|
-
|
|
585
|
+
|
|
586
|
+
exports.all = all; exports.any = any; exports.chain = chain; exports.chunked = chunked; exports.compact = compact; exports.compactObject = compactObject; exports.compress = compress; exports.contains = contains; exports.count = count; exports.cycle = cycle; exports.dropwhile = dropwhile; exports.enumerate = enumerate; exports.every = every; exports.filter = filter; exports.find = find; exports.first = first; exports.flatmap = flatmap; exports.flatten = flatten; exports.groupby = groupby; exports.heads = heads; exports.icompact = icompact; exports.icompress = icompress; exports.ifilter = ifilter; exports.imap = imap; exports.islice = islice; exports.itake = itake; exports.iter = iter; exports.izip = izip; exports.izip2 = izip2; exports.izip3 = izip3; exports.izipLongest = izipLongest; exports.izipMany = izipMany; exports.map = map; exports.max = max; exports.min = min; exports.pairwise = pairwise; exports.partition = partition; exports.permutations = permutations; exports.range = range; exports.reduce = reduce; exports.repeat = repeat; exports.roundrobin = roundrobin; exports.some = some; exports.sorted = sorted; exports.sum = sum; exports.take = take; exports.takewhile = takewhile; exports.uniqueEverseen = uniqueEverseen; exports.uniqueJustseen = uniqueJustseen; exports.zip = zip; exports.zip3 = zip3; exports.zipLongest = zipLongest; exports.zipMany = zipMany;
|
|
575
587
|
// istanbul ignore else -- @preserve
|
|
576
588
|
// istanbul ignore if -- @preserve
|
|
577
589
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/more-itertools.ts","../src/itertools.ts","../src/builtins.ts","../src/custom.ts"],"names":["count","first","grouper","heads","enumerate"],"mappings":";AAIO,SAAS,SAAY,OAAyC;AACnE,SAAO,CAAC,GAAM,MAAS;AACrB,UAAM,KAAK,MAAM,CAAC;AAClB,UAAM,KAAK,M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B,IAAkB,IAAkB,IAAuC;AAC1G,SAAO,MAAM,KAAK,MAAM,IAAI,IAAI,EAAE,CAAC;AACrC;;;AClVA,SAAS,UAAa,GAA2B;AAC/C,SAAO,KAAK;AACd;AAEA,SAAS,UAAa,GAAe;AACnC,SAAO,MAAM;AACf;AAUO,SAAS,SAAY,UAAuD;AACjF,SAAO,QAAQ,UAAU,SAAS;AACpC;AAUO,SAAS,QAAW,UAA+C;AACxE,SAAO,MAAM,KAAK,SAAS,QAAQ,CAAC;AACtC;AASO,SAAS,cAAmC,KAAoD;AACrG,QAAM,SAAS,CAAC;AAChB,aAAW,CAAC,KAAK,MAAM,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC/C,UAAM,QAAQ;AACd,QAAI,SAAS,MAAM;AACjB,aAAO,GAAQ,IAAI;AAAA,IACrB;AAAA,EACF;AACA,SAAO;AACT;AAQO,SAAS,MAAS,UAAuB,OAAqC;AACnF,SAAO,KAAK,UAAU,wBAAS,SAAS;AAC1C;AAgBO,SAAS,QAAc,UAAuB,QAA+C;AAClG,SAAO,QAAQ,KAAK,UAAU,MAAM,CAAC;AACvC","sourcesContent":["import type { Primitive } from \"./types\";\n\ntype CmpFn<T> = (a: T, b: T) => number;\n\nexport function keyToCmp<T>(keyFn: (item: T) => Primitive): CmpFn<T> {\n return (a: T, b: T) => {\n const ka = keyFn(a);\n const kb = keyFn(b);\n // istanbul ignore else -- @preserve\n if (typeof ka === \"boolean\" && typeof kb === \"boolean\") {\n return ka === kb ? 0 : !ka && kb ? -1 : 1;\n } else if (typeof ka === \"number\" && typeof kb === \"number\") {\n return ka - kb;\n } else if (typeof ka === \"string\" && typeof kb === \"string\") {\n return ka === kb ? 0 : ka < kb ? -1 : 1;\n } else {\n return -1;\n }\n };\n}\n\nexport function identityPredicate(x: unknown): boolean {\n return !!x;\n}\n\nexport function numberIdentity(x: unknown): number {\n // istanbul ignore if -- @preserve\n if (typeof x !== \"number\") {\n throw new Error(\"Inputs must be numbers\");\n }\n return x;\n}\n\nexport function primitiveIdentity<P extends Primitive>(x: P): P;\nexport function primitiveIdentity(x: unknown): Primitive;\nexport function primitiveIdentity(x: unknown): Primitive {\n // istanbul ignore if -- @preserve\n if (typeof x !== \"string\" && typeof x !== \"number\" && typeof x !== \"boolean\") {\n throw new Error(\"Please provide a key function that can establish object identity\");\n }\n return x;\n}\n","import { iter, map } from \"./builtins\";\nimport { izip, repeat } from \"./itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { primitiveIdentity } from \"./utils\";\n\n/**\n * Break iterable into lists of length `size`:\n *\n * [...chunked([1, 2, 3, 4, 5, 6], 3)]\n * // [[1, 2, 3], [4, 5, 6]]\n *\n * If the length of iterable is not evenly divisible by `size`, the last returned\n * list will be shorter:\n *\n * [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]\n * // [[1, 2, 3], [4, 5, 6], [7, 8]]\n */\nexport function* chunked<T>(iterable: Iterable<T>, size: number): Iterable<T[]> {\n if (size < 1) {\n throw new Error(`Invalid chunk size: ${size}`);\n }\n\n const it = iter(iterable);\n for (;;) {\n const chunk = take(size, it);\n if (chunk.length > 0) {\n yield chunk;\n }\n if (chunk.length < size) {\n return;\n }\n }\n}\n\n/**\n * Return an iterator flattening one level of nesting in a list of lists:\n *\n * [...flatten([[0, 1], [2, 3]])]\n * // [0, 1, 2, 3]\n *\n */\nexport function* flatten<T>(iterableOfIterables: Iterable<Iterable<T>>): Iterable<T> {\n for (const iterable of iterableOfIterables) {\n for (const item of iterable) {\n yield item;\n }\n }\n}\n\n/**\n * Intersperse filler element `value` among the items in `iterable`.\n *\n * >>> [...intersperse(-1, range(1, 5))]\n * [1, -1, 2, -1, 3, -1, 4]\n *\n */\nexport function intersperse<T, V>(value: V, iterable: Iterable<T>): Iterable<T | V> {\n const stream = flatten(izip(repeat(value), iterable));\n take(1, stream); // eat away and discard the first value from the output\n return stream;\n}\n\n/**\n * Returns an iterable containing only the first `n` elements of the given\n * iterable.\n */\nexport function* itake<T>(n: number, iterable: Iterable<T>): Iterable<T> {\n const it = iter(iterable);\n let count = n;\n while (count-- > 0) {\n const s = it.next();\n if (!s.done) {\n yield s.value;\n } else {\n // Iterable exhausted, quit early\n return;\n }\n }\n}\n\n/**\n * Returns an iterator of paired items, overlapping, from the original. When\n * the input iterable has a finite number of items `n`, the outputted iterable\n * will have `n - 1` items.\n *\n * >>> pairwise([8, 2, 0, 7])\n * [(8, 2), (2, 0), (0, 7)]\n *\n */\nexport function* pairwise<T>(iterable: Iterable<T>): Iterable<[T, T]> {\n const it = iter(iterable);\n const first = it.next();\n if (first.done) {\n return;\n }\n\n let r1: T = first.value;\n for (const r2 of it) {\n yield [r1, r2];\n r1 = r2;\n }\n}\n\n/**\n * Returns a 2-tuple of arrays. Splits the elements in the input iterable into\n * either of the two arrays. Will fully exhaust the input iterable. The first\n * array contains all items that match the predicate, the second the rest:\n *\n * >>> const isOdd = x => x % 2 !== 0;\n * >>> const iterable = range(10);\n * >>> const [odds, evens] = partition(iterable, isOdd);\n * >>> odds\n * [1, 3, 5, 7, 9]\n * >>> evens\n * [0, 2, 4, 6, 8]\n *\n */\nexport function partition<T, N extends T>(\n iterable: Iterable<T>,\n predicate: (item: T) => item is N,\n): [N[], Exclude<T, N>[]];\nexport function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]];\nexport function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]] {\n const good = [];\n const bad = [];\n\n for (const item of iterable) {\n if (predicate(item)) {\n good.push(item);\n } else {\n bad.push(item);\n }\n }\n\n return [good, bad];\n}\n\n/**\n * Yields the next item from each iterable in turn, alternating between them.\n * Continues until all items are exhausted.\n *\n * >>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]\n * [1, 4, 5, 2, 6, 3, 7, 8]\n */\nexport function* roundrobin<T>(...iters: Iterable<T>[]): Iterable<T> {\n // We'll only keep lazy versions of the input iterables in here that we'll\n // slowly going to exhaust. Once an iterable is exhausted, it will be\n // removed from this list. Once the entire list is empty, this algorithm\n // ends.\n const iterables: Array<Iterator<T>> = map(iters, iter);\n\n while (iterables.length > 0) {\n let index = 0;\n while (index < iterables.length) {\n const it = iterables[index];\n const result = it.next();\n\n if (!result.done) {\n yield result.value;\n index++;\n } else {\n // This iterable is exhausted, make sure to remove it from the\n // list of iterables. We'll splice the array from under our\n // feet, and NOT advancing the index counter.\n iterables.splice(index, 1); // intentional side-effect!\n }\n }\n }\n}\n\n/**\n * Yields the heads of all of the given iterables. This is almost like\n * `roundrobin()`, except that the yielded outputs are grouped in to the\n * \"rounds\":\n *\n * >>> [...heads([1, 2, 3], [4], [5, 6, 7, 8])]\n * [[1, 4, 5], [2, 6], [3, 7], [8]]\n *\n * This is also different from `zipLongest()`, since the number of items in\n * each round can decrease over time, rather than being filled with a filler.\n */\nexport function* heads<T>(...iters: Array<Iterable<T>>): Iterable<T[]> {\n // We'll only keep lazy versions of the input iterables in here that we'll\n // slowly going to exhaust. Once an iterable is exhausted, it will be\n // removed from this list. Once the entire list is empty, this algorithm\n // ends.\n const iterables: Array<Iterator<T>> = map(iters, iter);\n\n while (iterables.length > 0) {\n let index = 0;\n const round = [];\n while (index < iterables.length) {\n const it = iterables[index];\n const result = it.next();\n\n if (!result.done) {\n round.push(result.value);\n index++;\n } else {\n // This iterable is exhausted, make sure to remove it from the\n // list of iterables. We'll splice the array from under our\n // feet, and NOT advancing the index counter.\n iterables.splice(index, 1); // intentional side-effect!\n }\n }\n if (round.length > 0) {\n yield round;\n }\n }\n}\n\n/**\n * Non-lazy version of itake().\n */\nexport function take<T>(n: number, iterable: Iterable<T>): T[] {\n return Array.from(itake(n, iterable));\n}\n\n/**\n * Yield unique elements, preserving order.\n *\n * >>> [...uniqueEverseen('AAAABBBCCDAABBB')]\n * ['A', 'B', 'C', 'D']\n * >>> [...uniqueEverseen('AbBCcAB', s => s.toLowerCase())]\n * ['A', 'b', 'C']\n *\n */\nexport function* uniqueEverseen<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n): Iterable<T> {\n const seen = new Set();\n for (const item of iterable) {\n const key = keyFn(item);\n if (!seen.has(key)) {\n seen.add(key);\n yield item;\n }\n }\n}\n\n/**\n * Yields elements in order, ignoring serial duplicates.\n *\n * >>> [...uniqueJustseen('AAAABBBCCDAABBB')]\n * ['A', 'B', 'C', 'D', 'A', 'B']\n * >>> [...uniqueJustseen('AbBCcAB', s => s.toLowerCase())]\n * ['A', 'b', 'C', 'A', 'B']\n *\n */\nexport function* uniqueJustseen<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n): Iterable<T> {\n let last = undefined;\n for (const item of iterable) {\n const key = keyFn(item);\n if (key !== last) {\n yield item;\n last = key;\n }\n }\n}\n","import { enumerate, every, iter, range } from \"./builtins\";\nimport { flatten } from \"./more-itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { primitiveIdentity } from \"./utils\";\n\nconst SENTINEL = Symbol();\n\n/**\n * Returns an iterator that returns elements from the first iterable until it\n * is exhausted, then proceeds to the next iterable, until all of the iterables\n * are exhausted. Used for treating consecutive sequences as a single\n * sequence.\n */\nexport function chain<T>(...iterables: Iterable<T>[]): Iterable<T> {\n return flatten(iterables);\n}\n\n/**\n * Returns an iterator that counts up values starting with number `start`\n * (default 0), incrementing by `step`. To decrement, use a negative step\n * number.\n */\nexport function* count(start = 0, step = 1): Iterable<number> {\n let n = start;\n for (;;) {\n yield n;\n n += step;\n }\n}\n\n/**\n * Non-lazy version of icompress().\n */\nexport function compress<T>(data: Iterable<T>, selectors: Iterable<boolean>): T[] {\n return Array.from(icompress(data, selectors));\n}\n\n/**\n * Returns an iterator producing elements from the iterable and saving a copy\n * of each. When the iterable is exhausted, return elements from the saved\n * copy. Repeats indefinitely.\n */\nexport function* cycle<T>(iterable: Iterable<T>): Iterable<T> {\n const saved = [];\n for (const element of iterable) {\n yield element;\n saved.push(element);\n }\n\n while (saved.length > 0) {\n for (const element of saved) {\n yield element;\n }\n }\n}\n\n/**\n * Returns an iterator that drops elements from the iterable as long as the\n * predicate is true; afterwards, returns every remaining element. Note, the\n * iterator does not produce any output until the predicate first becomes\n * false.\n */\nexport function* dropwhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T> {\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (!predicate(value)) {\n yield value;\n break; // we break, so we cannot use a for..of loop!\n }\n }\n\n for (const value of it) {\n yield value;\n }\n}\n\nexport function* groupby<T, K extends Primitive>(\n iterable: Iterable<T>,\n keyFn: (item: T) => K = primitiveIdentity,\n): Generator<[K, Generator<T, undefined>], undefined> {\n const it = iter(iterable);\n\n let currentValue: T;\n let currentKey: K = SENTINEL as unknown as K;\n // ^^^^^^^^^^^^^^^ Hack!\n let targetKey: K = currentKey;\n\n const grouper = function* grouper(tgtKey: K): Generator<T, undefined> {\n while (currentKey === tgtKey) {\n yield currentValue;\n\n const nextVal = it.next();\n if (nextVal.done) return;\n currentValue = nextVal.value;\n currentKey = keyFn(currentValue);\n }\n };\n\n for (;;) {\n while (currentKey === targetKey) {\n const nextVal = it.next();\n if (nextVal.done) {\n currentKey = SENTINEL as unknown as K;\n // ^^^^^^^^^^^^^^^ Hack!\n return;\n }\n currentValue = nextVal.value;\n currentKey = keyFn(currentValue);\n }\n\n targetKey = currentKey;\n yield [currentKey, grouper(targetKey)];\n }\n}\n\n/**\n * Returns an iterator that filters elements from data returning only those\n * that have a corresponding element in selectors that evaluates to `true`.\n * Stops when either the data or selectors iterables has been exhausted.\n */\nexport function* icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>): Iterable<T> {\n for (const [d, s] of izip(data, selectors)) {\n if (s) {\n yield d;\n }\n }\n}\n\n/**\n * Returns an iterator that filters elements from iterable returning only those\n * for which the predicate is true.\n */\nexport function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): Iterable<N>;\nexport function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T>;\nexport function* ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T> {\n for (const value of iterable) {\n if (predicate(value)) {\n yield value;\n }\n }\n}\n\n/**\n * Returns an iterator that computes the given mapper function using arguments\n * from each of the iterables.\n */\nexport function* imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): Iterable<V> {\n for (const value of iterable) {\n yield mapper(value);\n }\n}\n\n/**\n * Returns an iterator that returns selected elements from the iterable. If\n * `start` is non-zero, then elements from the iterable are skipped until start\n * is reached. Then, elements are returned by making steps of `step` (defaults\n * to 1). If set to higher than 1, items will be skipped. If `stop` is\n * provided, then iteration continues until the iterator reached that index,\n * otherwise, the iterable will be fully exhausted. `islice()` does not\n * support negative values for `start`, `stop`, or `step`.\n */\nexport function islice<T>(iterable: Iterable<T>, stop: number): Iterable<T>;\nexport function islice<T>(iterable: Iterable<T>, start: number, stop?: number | null, step?: number): Iterable<T>;\nexport function* islice<T>(\n iterable: Iterable<T>,\n stopOrStart: number,\n possiblyStop?: number | null,\n step = 1,\n): Iterable<T> {\n let start, stop;\n if (possiblyStop !== undefined) {\n // islice(iterable, start, stop[, step])\n start = stopOrStart;\n stop = possiblyStop;\n } else {\n // islice(iterable, stop)\n start = 0;\n stop = stopOrStart;\n }\n\n if (start < 0) throw new Error(\"start cannot be negative\");\n if (stop !== null && stop < 0) throw new Error(\"stop cannot be negative\");\n if (step <= 0) throw new Error(\"step cannot be negative\");\n\n let i = -1;\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (true) {\n i++;\n if (stop !== null && i >= stop) return; // early returns, so we cannot use a for..of loop!\n\n res = it.next();\n if (res.done) return;\n\n if (i < start) continue;\n if ((i - start) % step === 0) {\n yield res.value;\n }\n }\n}\n\n/**\n * Returns an iterator that aggregates elements from each of the iterables.\n * Used for lock-step iteration over several iterables at a time. When\n * iterating over two iterables, use `izip2`. When iterating over three\n * iterables, use `izip3`, etc. `izip` is an alias for `izip2`.\n */\nexport function* izip2<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): Iterable<[T1, T2]> {\n const ixs = iter(xs);\n const iys = iter(ys);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n if (!x.done && !y.done) {\n yield [x.value, y.value];\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\n/**\n * Like izip2, but for three input iterables.\n */\nexport function* izip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): Iterable<[T1, T2, T3]> {\n const ixs = iter(xs);\n const iys = iter(ys);\n const izs = iter(zs);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n const z = izs.next();\n if (!x.done && !y.done && !z.done) {\n yield [x.value, y.value, z.value];\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\nexport const izip = izip2;\n\n/**\n * Returns an iterator that aggregates elements from each of the iterables. If\n * the iterables are of uneven length, missing values are filled-in with\n * fillvalue. Iteration continues until the longest iterable is exhausted.\n */\nexport function* izipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): Iterable<[T1 | D, T2 | D]> {\n const filler_ = filler as D;\n const ixs = iter(xs);\n const iys = iter(ys);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n if (x.done && y.done) {\n // All iterables exhausted\n return;\n } else {\n yield [!x.done ? x.value : filler_, !y.done ? y.value : filler_];\n }\n }\n}\n\n/**\n * See izipLongest2, but for three.\n */\nexport function* izipLongest3<T1, T2, T3, D = undefined>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n filler?: D,\n): Iterable<[T1 | D, T2 | D, T3 | D]> {\n const filler_ = filler as D;\n const ixs = iter(xs);\n const iys = iter(ys);\n const izs = iter(zs);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n const z = izs.next();\n if (x.done && y.done && z.done) {\n // All iterables exhausted\n return;\n } else {\n yield [!x.done ? x.value : filler_, !y.done ? y.value : filler_, !z.done ? z.value : filler_];\n }\n }\n}\n\n/**\n * Like the other izips (`izip`, `izip3`, etc), but generalized to take an\n * unlimited amount of input iterables. Think `izip(*iterables)` in Python.\n *\n * **Note:** Due to Flow type system limitations, you can only \"generially\" zip\n * iterables with homogeneous types, so you cannot mix types like <A, B> like\n * you can with izip2().\n */\nexport function* izipMany<T>(...iters: Iterable<T>[]): Iterable<T[]> {\n // Make them all iterables\n const iterables = iters.map(iter);\n\n for (;;) {\n const heads: Array<IteratorResult<T, undefined>> = iterables.map((xs) => xs.next());\n if (every(heads, (h) => !h.done)) {\n yield heads.map((h) => h.value as T);\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\n/**\n * Return successive `r`-length permutations of elements in the iterable.\n *\n * If `r` is not specified, then `r` defaults to the length of the iterable and\n * all possible full-length permutations are generated.\n *\n * Permutations are emitted in lexicographic sort order. So, if the input\n * iterable is sorted, the permutation tuples will be produced in sorted order.\n *\n * Elements are treated as unique based on their position, not on their value.\n * So if the input elements are unique, there will be no repeat values in each\n * permutation.\n */\nexport function* permutations<T>(iterable: Iterable<T>, r?: number): Iterable<T[]> {\n const pool = Array.from(iterable);\n const n = pool.length;\n const x = r === undefined ? n : r;\n\n if (x > n) {\n return;\n }\n\n let indices: number[] = Array.from(range(n));\n const cycles: number[] = Array.from(range(n, n - x, -1));\n const poolgetter = (i: number) => pool[i];\n\n yield indices.slice(0, x).map(poolgetter);\n\n while (n > 0) {\n let cleanExit = true;\n for (const i of range(x - 1, -1, -1)) {\n cycles[i] -= 1;\n if (cycles[i] === 0) {\n indices = indices\n .slice(0, i)\n .concat(indices.slice(i + 1))\n .concat(indices.slice(i, i + 1));\n cycles[i] = n - i;\n } else {\n const j: number = cycles[i];\n\n const [p, q] = [indices[indices.length - j], indices[i]];\n indices[i] = p;\n indices[indices.length - j] = q;\n yield indices.slice(0, x).map(poolgetter);\n cleanExit = false;\n break;\n }\n }\n\n if (cleanExit) {\n return;\n }\n }\n}\n\n/**\n * Returns an iterator that produces values over and over again. Runs\n * indefinitely unless the times argument is specified.\n */\nexport function* repeat<T>(thing: T, times?: number): Iterable<T> {\n if (times === undefined) {\n for (;;) {\n yield thing;\n }\n } else {\n for (const _ of range(times)) {\n yield thing;\n }\n }\n}\n\n/**\n * Returns an iterator that produces elements from the iterable as long as the\n * predicate is true.\n */\nexport function* takewhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T> {\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (!predicate(value)) return; // early return, so we cannot use for..of loop!\n yield value;\n }\n}\n\nexport function zipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): Array<[T1 | D, T2 | D]> {\n return Array.from(izipLongest2(xs, ys, filler));\n}\n\nexport function zipLongest3<T1, T2, T3, D>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n filler?: D,\n): Array<[T1 | D, T2 | D, T3 | D]> {\n return Array.from(izipLongest3(xs, ys, zs, filler));\n}\n\nexport const izipLongest = izipLongest2;\nexport const zipLongest = zipLongest2;\n\nexport function zipMany<T>(...iters: Iterable<T>[]): T[][] {\n return Array.from(izipMany(...iters));\n}\n","import { count, ifilter, imap, izip, izip3, takewhile } from \"./itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { identityPredicate, keyToCmp, numberIdentity, primitiveIdentity } from \"./utils\";\n\n/**\n * Returns the first item in the iterable for which the predicate holds, if\n * any. If no predicate is given, it will return the first value returned by\n * the iterable.\n */\nexport function find<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n const it = iter(iterable);\n if (keyFn === undefined) {\n const value = it.next();\n return value.done ? value.value : value.value;\n } else {\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (keyFn(value)) {\n return value;\n }\n }\n return undefined;\n }\n}\n\n/**\n * Returns true when all of the items in iterable are truthy. An optional key\n * function can be used to define what truthiness means for this specific\n * collection.\n *\n * Examples:\n *\n * all([]) // => true\n * all([0]) // => false\n * all([0, 1, 2]) // => false\n * all([1, 2, 3]) // => true\n *\n * Examples with using a key function:\n *\n * all([2, 4, 6], n => n % 2 === 0) // => true\n * all([2, 4, 5], n => n % 2 === 0) // => false\n *\n */\nexport function every<T>(iterable: Iterable<T>, keyFn: Predicate<T> = identityPredicate): boolean {\n for (const item of iterable) {\n if (!keyFn(item)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Returns true when some of the items in iterable are truthy. An optional key\n * function can be used to define what truthiness means for this specific\n * collection.\n *\n * Examples:\n *\n * some([]) // => false\n * some([0]) // => false\n * some([0, 1, null, undefined]) // => true\n *\n * Examples with using a key function:\n *\n * some([1, 4, 5], n => n % 2 === 0) // => true\n * some([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false\n *\n */\nexport function some<T>(iterable: Iterable<T>, keyFn: Predicate<T> = identityPredicate): boolean {\n for (const item of iterable) {\n if (keyFn(item)) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Alias of `every()`.\n */\nexport const all = every;\n\n/**\n * Alias of `some()`.\n */\nexport const any = some;\n\n/**\n * Returns true when any of the items in the iterable are equal to the target object.\n *\n * Examples:\n *\n * contains([], 'whatever') // => false\n * contains([3], 42) // => false\n * contains([3], 3) // => true\n * contains([0, 1, 2], 2) // => true\n *\n */\nexport function contains<T>(haystack: Iterable<T>, needle: T): boolean {\n return some(haystack, (x) => x === needle);\n}\n\n/**\n * Returns an iterable of enumeration pairs. Iterable must be a sequence, an\n * iterator, or some other object which supports iteration. The elements\n * produced by returns a tuple containing a counter value (starting from 0 by\n * default) and the values obtained from iterating over given iterable.\n *\n * Example:\n *\n * import { enumerate } from 'itertools';\n *\n * console.log([...enumerate(['hello', 'world'])]);\n * // [0, 'hello'], [1, 'world']]\n */\nexport function* enumerate<T>(iterable: Iterable<T>, start = 0): Iterable<[number, T]> {\n let index: number = start;\n for (const value of iterable) {\n yield [index++, value];\n }\n}\n\n/**\n * Non-lazy version of ifilter().\n */\nexport function filter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): N[];\nexport function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[];\nexport function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[] {\n return Array.from(ifilter(iterable, predicate));\n}\n\n/**\n * Returns an iterator object for the given iterable. This can be used to\n * manually get an iterator for any iterable datastructure. The purpose and\n * main use case of this function is to get a single iterator (a thing with\n * state, think of it as a \"cursor\") which can only be consumed once.\n */\nexport function iter<T>(iterable: Iterable<T>): IterableIterator<T> {\n // class SelfIter implements IterableIterator<T> {\n // #iterator: Iterator<T>;\n // constructor(orig: Iterable<T>) {\n // this.#iterator = orig[Symbol.iterator]();\n // }\n // [Symbol.iterator]() {\n // return this;\n // }\n // next() {\n // return this.#iterator.next();\n // }\n // }\n // return new SelfIter(iterable);\n\n return iterable[Symbol.iterator]() as IterableIterator<T>;\n // ^^^^^^^^^^^^^^^^^^^^^^ Not safe!\n}\n\n/**\n * Non-lazy version of imap().\n */\nexport function map<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): V[] {\n return Array.from(imap(iterable, mapper));\n}\n\n/**\n * Return the largest item in an iterable. Only works for numbers, as ordering\n * is pretty poorly defined on any other data type in JS. The optional `keyFn`\n * argument specifies a one-argument ordering function like that used for\n * sorted().\n *\n * If the iterable is empty, `undefined` is returned.\n *\n * If multiple items are maximal, the function returns either one of them, but\n * which one is not defined.\n */\nexport function max<T>(iterable: Iterable<T>, keyFn: (item: T) => number = numberIdentity): T | undefined {\n return reduce2(iterable, (x, y) => (keyFn(x) > keyFn(y) ? x : y));\n}\n\n/**\n * Return the smallest item in an iterable. Only works for numbers, as\n * ordering is pretty poorly defined on any other data type in JS. The\n * optional `keyFn` argument specifies a one-argument ordering function like\n * that used for sorted().\n *\n * If the iterable is empty, `undefined` is returned.\n *\n * If multiple items are minimal, the function returns either one of them, but\n * which one is not defined.\n */\nexport function min<T>(iterable: Iterable<T>, keyFn: (item: T) => number = numberIdentity): T | undefined {\n return reduce2(iterable, (x, y) => (keyFn(x) < keyFn(y) ? x : y));\n}\n\n/**\n * Internal helper for the range function\n */\nfunction range_(start: number, stop: number, step: number): Iterable<number> {\n const counter = count(start, step);\n const pred = step >= 0 ? (n: number) => n < stop : (n: number) => n > stop;\n return takewhile(counter, pred);\n}\n\n/**\n * Returns an iterator producing all the numbers in the given range one by one,\n * starting from `start` (default 0), as long as `i < stop`, in increments of\n * `step` (default 1).\n *\n * `range(a)` is a convenient shorthand for `range(0, a)`.\n *\n * Various valid invocations:\n *\n * range(5) // [0, 1, 2, 3, 4]\n * range(2, 5) // [2, 3, 4]\n * range(0, 5, 2) // [0, 2, 4]\n * range(5, 0, -1) // [5, 4, 3, 2, 1]\n * range(-3) // []\n *\n * For a positive `step`, the iterator will keep producing values `n` as long\n * as the stop condition `n < stop` is satisfied.\n *\n * For a negative `step`, the iterator will keep producing values `n` as long\n * as the stop condition `n > stop` is satisfied.\n *\n * The produced range will be empty if the first value to produce already does\n * not meet the value constraint.\n */\n\nexport function range(stop: number): Iterable<number>;\nexport function range(start: number, stop: number, step?: number): Iterable<number>;\nexport function range(startOrStop: number, definitelyStop?: number, step = 1): Iterable<number> {\n if (definitelyStop !== undefined) {\n return range_(startOrStop /* as start */, definitelyStop, step);\n } else {\n return range_(0, startOrStop /* as stop */, step);\n }\n}\n\n/**\n * Apply function of two arguments cumulatively to the items of sequence, from\n * left to right, so as to reduce the sequence to a single value. For example:\n *\n * reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)\n *\n * calculates\n *\n * (((((0+1)+2)+3)+4)+5)\n *\n * The left argument, `x`, is the accumulated value and the right argument,\n * `y`, is the update value from the sequence.\n *\n * **Difference between `reduce()` and `reduce\\_()`**: `reduce()` requires an\n * explicit initializer, whereas `reduce_()` will automatically use the first\n * item in the given iterable as the initializer. When using `reduce()`, the\n * initializer value is placed before the items of the sequence in the\n * calculation, and serves as a default when the sequence is empty. When using\n * `reduce_()`, and the given iterable is empty, then no default value can be\n * derived and `undefined` will be returned.\n */\nexport function reduce<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined;\nexport function reduce<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O;\nexport function reduce<T, O>(\n iterable: Iterable<T>,\n reducer: ((agg: T, item: T, index: number) => T) | ((agg: O, item: T, index: number) => O),\n start?: O,\n): O | (T | undefined) {\n if (start === undefined) {\n return reduce2(iterable, reducer as (agg: T, item: T, index: number) => T);\n } else {\n return reduce3(iterable, reducer as (agg: O, item: T, index: number) => O, start);\n }\n}\n\nfunction reduce3<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O {\n let output = start;\n let index = 0;\n for (const item of iterable) {\n output = reducer(output, item, index++);\n }\n return output;\n}\n\nfunction reduce2<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined {\n const it = iter(iterable);\n const start = find(it);\n if (start === undefined) {\n return undefined;\n } else {\n return reduce3(it, reducer, start);\n }\n}\n\n/**\n * Return a new sorted list from the items in iterable.\n *\n * Has two optional arguments:\n *\n * * `keyFn` specifies a function of one argument providing a primitive\n * identity for each element in the iterable. that will be used to compare.\n * The default value is to use a default identity function that is only\n * defined for primitive types.\n *\n * * `reverse` is a boolean value. If `true`, then the list elements are\n * sorted as if each comparison were reversed.\n */\nexport function sorted<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n reverse = false,\n): T[] {\n const result = Array.from(iterable);\n result.sort(keyToCmp(keyFn)); // sort in-place\n\n if (reverse) {\n result.reverse(); // reverse in-place\n }\n\n return result;\n}\n\n/**\n * Sums the items of an iterable from left to right and returns the total. The\n * sum will defaults to 0 if the iterable is empty.\n */\nexport function sum(iterable: Iterable<number>): number {\n return reduce(iterable, (x, y) => x + y, 0);\n}\n\n/**\n * See izip.\n */\nexport function zip<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): Array<[T1, T2]> {\n return Array.from(izip(xs, ys));\n}\n\n/**\n * See izip3.\n */\nexport function zip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): Array<[T1, T2, T3]> {\n return Array.from(izip3(xs, ys, zs));\n}\n","import { find } from \"./builtins\";\nimport { ifilter, imap } from \"./itertools\";\nimport { flatten } from \"./more-itertools\";\nimport type { Predicate } from \"./types\";\n\nfunction isNullish<T>(x: T): x is NonNullable<T> {\n return x != null;\n}\n\nfunction isDefined<T>(x: T): boolean {\n return x !== undefined;\n}\n\n/**\n * Returns an iterable, filtering out any \"nullish\" values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3, null])\n * [1, 2, 3]\n *\n * For an eager version, @see compact().\n */\nexport function icompact<T>(iterable: Iterable<T | null | undefined>): Iterable<T> {\n return ifilter(iterable, isNullish);\n}\n\n/**\n * Returns an array, filtering out any \"nullish\" values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3, null])\n * [1, 2, 3]\n *\n * For a lazy version, @see icompact().\n */\nexport function compact<T>(iterable: Iterable<T | null | undefined>): T[] {\n return Array.from(icompact(iterable));\n}\n\n/**\n * Removes all \"nullish\" values from the given object. Returns a new object.\n *\n * >>> compactObject({ a: 1, b: undefined, c: 0, d: null })\n * { a: 1, c: 0 }\n *\n */\nexport function compactObject<K extends string, V>(obj: Record<K, V | null | undefined>): Record<K, V> {\n const result = {} as Record<K, V>;\n for (const [key, value_] of Object.entries(obj)) {\n const value = value_ as V | null | undefined;\n if (value != null) {\n result[key as K] = value;\n }\n }\n return result;\n}\n\n/**\n * Almost an alias of find(). There only is a difference if no key fn is\n * provided. In that case, `find()` will return the first item in the iterable,\n * whereas `first()` will return the first non-`undefined` value in the\n * iterable.\n */\nexport function first<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n return find(iterable, keyFn ?? isDefined);\n}\n\n/**\n * Returns 0 or more values for every value in the given iterable.\n * Technically, it's just calling map(), followed by flatten(), but it's a very\n * useful operation if you want to map over a structure, but not have a 1:1\n * input-output mapping. Instead, if you want to potentially return 0 or more\n * values per input element, use flatmap():\n *\n * For example, to return all numbers `n` in the input iterable `n` times:\n *\n * >>> const repeatN = n => repeat(n, n);\n * >>> [...flatmap([0, 1, 2, 3, 4], repeatN)]\n * [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0\n *\n */\nexport function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>): Iterable<S> {\n return flatten(imap(iterable, mapper));\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/more-itertools.ts","../src/itertools.ts","../src/builtins.ts","../src/custom.ts"],"names":["count","first","grouper","heads"],"mappings":";AAIO,SAAS,SAAY,OAAyC;AACnE,SAAO,CAAC,GAAM,MAAS;AACrB,UAAM,KAAK,MAAM,CAAC;AAClB,UAAM,KAAK,MAAM,CAAC;AAElB,QAAI,OAAO,OAAO,aAAa,OAAO,OAAO,WAAW;AACtD,aAAO,OAAO,KAAK,IAAI,CAAC,MAAM,KAAK,KAAK;AAAA,IAC1C,WAAW,OAAO,OAAO,YAAY,OAAO,OAAO,UAAU;AAC3D,aAAO,KAAK;AAAA,IACd,WAAW,OAAO,OAAO,YAAY,OAAO,OAAO,UAAU;AAC3D,aAAO,OAAO,KAAK,IAAI,KAAK,KAAK,KAAK;AAAA,IACxC,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,SAAS,kBAAkB,GAAqB;AACrD,SAAO,CAAC,CAAC;AACX;AAEO,SAAS,eAAe,GAAoB;AAEjD,MAAI,OAAO,MAAM,UAAU;AACzB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AACA,SAAO;AACT;AAIO,SAAS,kBAAkB,GAAuB;AAEvD,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM,WAAW;AAC5E,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AAC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;AAAA,IACrB;AAAA,EACF;AACA,SAAO;AACT;AAQO,SAAS,MAAS,UAAuB,OAAqC;AACnF,SAAO,KAAK,UAAU,wBAAS,SAAS;AAC1C;AAgBO,SAAS,QAAc,UAAuB,QAAuD;AAC1G,SAAO,QAAQ,KAAK,UAAU,MAAM,CAAC;AACvC","sourcesContent":["import type { Primitive } from \"./types\";\n\ntype CmpFn<T> = (a: T, b: T) => number;\n\nexport function keyToCmp<T>(keyFn: (item: T) => Primitive): CmpFn<T> {\n return (a: T, b: T) => {\n const ka = keyFn(a);\n const kb = keyFn(b);\n // istanbul ignore else -- @preserve\n if (typeof ka === \"boolean\" && typeof kb === \"boolean\") {\n return ka === kb ? 0 : !ka && kb ? -1 : 1;\n } else if (typeof ka === \"number\" && typeof kb === \"number\") {\n return ka - kb;\n } else if (typeof ka === \"string\" && typeof kb === \"string\") {\n return ka === kb ? 0 : ka < kb ? -1 : 1;\n } else {\n return -1;\n }\n };\n}\n\nexport function identityPredicate(x: unknown): boolean {\n return !!x;\n}\n\nexport function numberIdentity(x: unknown): number {\n // istanbul ignore if -- @preserve\n if (typeof x !== \"number\") {\n throw new Error(\"Inputs must be numbers\");\n }\n return x;\n}\n\nexport function primitiveIdentity<P extends Primitive>(x: P): P;\nexport function primitiveIdentity(x: unknown): Primitive;\nexport function primitiveIdentity(x: unknown): Primitive {\n // istanbul ignore if -- @preserve\n if (typeof x !== \"string\" && typeof x !== \"number\" && typeof x !== \"boolean\") {\n throw new Error(\"Please provide a key function that can establish object identity\");\n }\n return x;\n}\n","import { iter, map } from \"./builtins\";\nimport { izip, repeat } from \"./itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { primitiveIdentity } from \"./utils\";\n\n/**\n * Break iterable into lists of length `size`:\n *\n * [...chunked([1, 2, 3, 4, 5, 6], 3)]\n * // [[1, 2, 3], [4, 5, 6]]\n *\n * If the length of iterable is not evenly divisible by `size`, the last returned\n * list will be shorter:\n *\n * [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]\n * // [[1, 2, 3], [4, 5, 6], [7, 8]]\n */\nexport function* chunked<T>(iterable: Iterable<T>, size: number): IterableIterator<T[]> {\n if (size < 1) {\n throw new Error(`Invalid chunk size: ${size}`);\n }\n\n const it = iter(iterable);\n for (;;) {\n const chunk = take(size, it);\n if (chunk.length > 0) {\n yield chunk;\n }\n if (chunk.length < size) {\n return;\n }\n }\n}\n\n/**\n * Return an iterator flattening one level of nesting in a list of lists:\n *\n * [...flatten([[0, 1], [2, 3]])]\n * // [0, 1, 2, 3]\n *\n */\nexport function* flatten<T>(iterableOfIterables: Iterable<Iterable<T>>): IterableIterator<T> {\n for (const iterable of iterableOfIterables) {\n for (const item of iterable) {\n yield item;\n }\n }\n}\n\n/**\n * Intersperse filler element `value` among the items in `iterable`.\n *\n * >>> [...intersperse(-1, range(1, 5))]\n * [1, -1, 2, -1, 3, -1, 4]\n *\n */\nexport function intersperse<T, V>(value: V, iterable: Iterable<T>): IterableIterator<T | V> {\n const stream = flatten<T | V>(izip(repeat(value), iterable));\n stream.next(); // eat away and discard the first value from the output\n return stream;\n}\n\n/**\n * Returns an iterable containing only the first `n` elements of the given\n * iterable.\n */\nexport function* itake<T>(n: number, iterable: Iterable<T>): IterableIterator<T> {\n const it = iter(iterable);\n let count = n;\n while (count-- > 0) {\n const s = it.next();\n if (!s.done) {\n yield s.value;\n } else {\n // Iterable exhausted, quit early\n return;\n }\n }\n}\n\n/**\n * Returns an iterator of paired items, overlapping, from the original. When\n * the input iterable has a finite number of items `n`, the outputted iterable\n * will have `n - 1` items.\n *\n * >>> pairwise([8, 2, 0, 7])\n * [(8, 2), (2, 0), (0, 7)]\n *\n */\nexport function* pairwise<T>(iterable: Iterable<T>): IterableIterator<[T, T]> {\n const it = iter(iterable);\n const first = it.next();\n if (first.done) {\n return;\n }\n\n let r1: T = first.value;\n for (const r2 of it) {\n yield [r1, r2];\n r1 = r2;\n }\n}\n\n/**\n * Returns a 2-tuple of arrays. Splits the elements in the input iterable into\n * either of the two arrays. Will fully exhaust the input iterable. The first\n * array contains all items that match the predicate, the second the rest:\n *\n * >>> const isOdd = x => x % 2 !== 0;\n * >>> const iterable = range(10);\n * >>> const [odds, evens] = partition(iterable, isOdd);\n * >>> odds\n * [1, 3, 5, 7, 9]\n * >>> evens\n * [0, 2, 4, 6, 8]\n *\n */\nexport function partition<T, N extends T>(\n iterable: Iterable<T>,\n predicate: (item: T) => item is N,\n): [N[], Exclude<T, N>[]];\nexport function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]];\nexport function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]] {\n const good = [];\n const bad = [];\n\n for (const item of iterable) {\n if (predicate(item)) {\n good.push(item);\n } else {\n bad.push(item);\n }\n }\n\n return [good, bad];\n}\n\n/**\n * Yields the next item from each iterable in turn, alternating between them.\n * Continues until all items are exhausted.\n *\n * >>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]\n * [1, 4, 5, 2, 6, 3, 7, 8]\n */\nexport function* roundrobin<T>(...iters: Iterable<T>[]): IterableIterator<T> {\n // We'll only keep lazy versions of the input iterables in here that we'll\n // slowly going to exhaust. Once an iterable is exhausted, it will be\n // removed from this list. Once the entire list is empty, this algorithm\n // ends.\n const iterables: Array<Iterator<T>> = map(iters, iter);\n\n while (iterables.length > 0) {\n let index = 0;\n while (index < iterables.length) {\n const it = iterables[index];\n const result = it.next();\n\n if (!result.done) {\n yield result.value;\n index++;\n } else {\n // This iterable is exhausted, make sure to remove it from the\n // list of iterables. We'll splice the array from under our\n // feet, and NOT advancing the index counter.\n iterables.splice(index, 1); // intentional side-effect!\n }\n }\n }\n}\n\n/**\n * Yields the heads of all of the given iterables. This is almost like\n * `roundrobin()`, except that the yielded outputs are grouped in to the\n * \"rounds\":\n *\n * >>> [...heads([1, 2, 3], [4], [5, 6, 7, 8])]\n * [[1, 4, 5], [2, 6], [3, 7], [8]]\n *\n * This is also different from `zipLongest()`, since the number of items in\n * each round can decrease over time, rather than being filled with a filler.\n */\nexport function* heads<T>(...iters: Array<Iterable<T>>): IterableIterator<T[]> {\n // We'll only keep lazy versions of the input iterables in here that we'll\n // slowly going to exhaust. Once an iterable is exhausted, it will be\n // removed from this list. Once the entire list is empty, this algorithm\n // ends.\n const iterables: Array<Iterator<T>> = map(iters, iter);\n\n while (iterables.length > 0) {\n let index = 0;\n const round = [];\n while (index < iterables.length) {\n const it = iterables[index];\n const result = it.next();\n\n if (!result.done) {\n round.push(result.value);\n index++;\n } else {\n // This iterable is exhausted, make sure to remove it from the\n // list of iterables. We'll splice the array from under our\n // feet, and NOT advancing the index counter.\n iterables.splice(index, 1); // intentional side-effect!\n }\n }\n if (round.length > 0) {\n yield round;\n }\n }\n}\n\n/**\n * Non-lazy version of itake().\n */\nexport function take<T>(n: number, iterable: Iterable<T>): T[] {\n return Array.from(itake(n, iterable));\n}\n\n/**\n * Yield unique elements, preserving order.\n *\n * >>> [...uniqueEverseen('AAAABBBCCDAABBB')]\n * ['A', 'B', 'C', 'D']\n * >>> [...uniqueEverseen('AbBCcAB', s => s.toLowerCase())]\n * ['A', 'b', 'C']\n *\n */\nexport function* uniqueEverseen<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n): IterableIterator<T> {\n const seen = new Set();\n for (const item of iterable) {\n const key = keyFn(item);\n if (!seen.has(key)) {\n seen.add(key);\n yield item;\n }\n }\n}\n\n/**\n * Yields elements in order, ignoring serial duplicates.\n *\n * >>> [...uniqueJustseen('AAAABBBCCDAABBB')]\n * ['A', 'B', 'C', 'D', 'A', 'B']\n * >>> [...uniqueJustseen('AbBCcAB', s => s.toLowerCase())]\n * ['A', 'b', 'C', 'A', 'B']\n *\n */\nexport function* uniqueJustseen<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n): IterableIterator<T> {\n let last = undefined;\n for (const item of iterable) {\n const key = keyFn(item);\n if (key !== last) {\n yield item;\n last = key;\n }\n }\n}\n","import { every, iter, range } from \"./builtins\";\nimport { flatten } from \"./more-itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { primitiveIdentity } from \"./utils\";\n\nconst SENTINEL = Symbol();\n\n/**\n * Returns an iterator that returns elements from the first iterable until it\n * is exhausted, then proceeds to the next iterable, until all of the iterables\n * are exhausted. Used for treating consecutive sequences as a single\n * sequence.\n */\nexport function chain<T>(...iterables: Iterable<T>[]): IterableIterator<T> {\n return flatten(iterables);\n}\n\n/**\n * Returns an iterator that counts up values starting with number `start`\n * (default 0), incrementing by `step`. To decrement, use a negative step\n * number.\n */\nexport function* count(start = 0, step = 1): IterableIterator<number> {\n let n = start;\n for (;;) {\n yield n;\n n += step;\n }\n}\n\n/**\n * Non-lazy version of icompress().\n */\nexport function compress<T>(data: Iterable<T>, selectors: Iterable<boolean>): T[] {\n return Array.from(icompress(data, selectors));\n}\n\n/**\n * Returns an iterator producing elements from the iterable and saving a copy\n * of each. When the iterable is exhausted, return elements from the saved\n * copy. Repeats indefinitely.\n */\nexport function* cycle<T>(iterable: Iterable<T>): IterableIterator<T> {\n const saved = [];\n for (const element of iterable) {\n yield element;\n saved.push(element);\n }\n\n while (saved.length > 0) {\n for (const element of saved) {\n yield element;\n }\n }\n}\n\n/**\n * Returns an iterator that drops elements from the iterable as long as the\n * predicate is true; afterwards, returns every remaining element. Note, the\n * iterator does not produce any output until the predicate first becomes\n * false.\n */\nexport function* dropwhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T> {\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (!predicate(value)) {\n yield value;\n break; // we break, so we cannot use a for..of loop!\n }\n }\n\n for (const value of it) {\n yield value;\n }\n}\n\nexport function* groupby<T, K extends Primitive>(\n iterable: Iterable<T>,\n keyFn: (item: T) => K = primitiveIdentity,\n): Generator<[K, Generator<T, undefined>], undefined> {\n const it = iter(iterable);\n\n let currentValue: T;\n let currentKey: K = SENTINEL as unknown as K;\n // ^^^^^^^^^^^^^^^ Hack!\n let targetKey: K = currentKey;\n\n const grouper = function* grouper(tgtKey: K): Generator<T, undefined> {\n while (currentKey === tgtKey) {\n yield currentValue;\n\n const nextVal = it.next();\n if (nextVal.done) return;\n currentValue = nextVal.value;\n currentKey = keyFn(currentValue);\n }\n };\n\n for (;;) {\n while (currentKey === targetKey) {\n const nextVal = it.next();\n if (nextVal.done) {\n currentKey = SENTINEL as unknown as K;\n // ^^^^^^^^^^^^^^^ Hack!\n return;\n }\n currentValue = nextVal.value;\n currentKey = keyFn(currentValue);\n }\n\n targetKey = currentKey;\n yield [currentKey, grouper(targetKey)];\n }\n}\n\n/**\n * Returns an iterator that filters elements from data returning only those\n * that have a corresponding element in selectors that evaluates to `true`.\n * Stops when either the data or selectors iterables has been exhausted.\n */\nexport function* icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>): IterableIterator<T> {\n for (const [d, s] of izip(data, selectors)) {\n if (s) {\n yield d;\n }\n }\n}\n\n/**\n * Returns an iterator that filters elements from iterable returning only those\n * for which the predicate is true.\n */\nexport function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): IterableIterator<N>;\nexport function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T>;\nexport function* ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T> {\n for (const value of iterable) {\n if (predicate(value)) {\n yield value;\n }\n }\n}\n\n/**\n * Returns an iterator that computes the given mapper function using arguments\n * from each of the iterables.\n */\nexport function* imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): IterableIterator<V> {\n for (const value of iterable) {\n yield mapper(value);\n }\n}\n\n/**\n * Returns an iterator that returns selected elements from the iterable. If\n * `start` is non-zero, then elements from the iterable are skipped until start\n * is reached. Then, elements are returned by making steps of `step` (defaults\n * to 1). If set to higher than 1, items will be skipped. If `stop` is\n * provided, then iteration continues until the iterator reached that index,\n * otherwise, the iterable will be fully exhausted. `islice()` does not\n * support negative values for `start`, `stop`, or `step`.\n */\nexport function islice<T>(iterable: Iterable<T>, stop: number): IterableIterator<T>;\nexport function islice<T>(\n iterable: Iterable<T>,\n start: number,\n stop?: number | null,\n step?: number,\n): IterableIterator<T>;\nexport function* islice<T>(\n iterable: Iterable<T>,\n stopOrStart: number,\n possiblyStop?: number | null,\n step = 1,\n): IterableIterator<T> {\n let start, stop;\n if (possiblyStop !== undefined) {\n // islice(iterable, start, stop[, step])\n start = stopOrStart;\n stop = possiblyStop;\n } else {\n // islice(iterable, stop)\n start = 0;\n stop = stopOrStart;\n }\n\n if (start < 0) throw new Error(\"start cannot be negative\");\n if (stop !== null && stop < 0) throw new Error(\"stop cannot be negative\");\n if (step <= 0) throw new Error(\"step cannot be negative\");\n\n let i = -1;\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (true) {\n i++;\n if (stop !== null && i >= stop) return; // early returns, so we cannot use a for..of loop!\n\n res = it.next();\n if (res.done) return;\n\n if (i < start) continue;\n if ((i - start) % step === 0) {\n yield res.value;\n }\n }\n}\n\n/**\n * Returns an iterator that aggregates elements from each of the iterables.\n * Used for lock-step iteration over several iterables at a time. When\n * iterating over two iterables, use `izip2`. When iterating over three\n * iterables, use `izip3`, etc. `izip` is an alias for `izip2`.\n */\nexport function* izip<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): IterableIterator<[T1, T2]> {\n const ixs = iter(xs);\n const iys = iter(ys);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n if (!x.done && !y.done) {\n yield [x.value, y.value];\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\n/**\n * Like izip2, but for three input iterables.\n */\nexport function* izip3<T1, T2, T3>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n): IterableIterator<[T1, T2, T3]> {\n const ixs = iter(xs);\n const iys = iter(ys);\n const izs = iter(zs);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n const z = izs.next();\n if (!x.done && !y.done && !z.done) {\n yield [x.value, y.value, z.value];\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\nexport const izip2 = izip;\n\n/**\n * Returns an iterator that aggregates elements from each of the iterables. If\n * the iterables are of uneven length, missing values are filled-in with\n * fillvalue. Iteration continues until the longest iterable is exhausted.\n */\nexport function* izipLongest2<T1, T2, D>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n filler?: D,\n): IterableIterator<[T1 | D, T2 | D]> {\n const filler_ = filler as D;\n const ixs = iter(xs);\n const iys = iter(ys);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n if (x.done && y.done) {\n // All iterables exhausted\n return;\n } else {\n yield [!x.done ? x.value : filler_, !y.done ? y.value : filler_];\n }\n }\n}\n\n/**\n * See izipLongest2, but for three.\n */\nexport function* izipLongest3<T1, T2, T3, D = undefined>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n filler?: D,\n): IterableIterator<[T1 | D, T2 | D, T3 | D]> {\n const filler_ = filler as D;\n const ixs = iter(xs);\n const iys = iter(ys);\n const izs = iter(zs);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n const z = izs.next();\n if (x.done && y.done && z.done) {\n // All iterables exhausted\n return;\n } else {\n yield [!x.done ? x.value : filler_, !y.done ? y.value : filler_, !z.done ? z.value : filler_];\n }\n }\n}\n\n/**\n * Like the other izips (`izip`, `izip3`, etc), but generalized to take an\n * unlimited amount of input iterables. Think `izip(*iterables)` in Python.\n *\n * **Note:** Due to Flow type system limitations, you can only \"generially\" zip\n * iterables with homogeneous types, so you cannot mix types like <A, B> like\n * you can with izip2().\n */\nexport function* izipMany<T>(...iters: Iterable<T>[]): IterableIterator<T[]> {\n // Make them all iterables\n const iterables = iters.map(iter);\n\n for (;;) {\n const heads: Array<IteratorResult<T, undefined>> = iterables.map((xs) => xs.next());\n if (every(heads, (h) => !h.done)) {\n yield heads.map((h) => h.value as T);\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\n/**\n * Return successive `r`-length permutations of elements in the iterable.\n *\n * If `r` is not specified, then `r` defaults to the length of the iterable and\n * all possible full-length permutations are generated.\n *\n * Permutations are emitted in lexicographic sort order. So, if the input\n * iterable is sorted, the permutation tuples will be produced in sorted order.\n *\n * Elements are treated as unique based on their position, not on their value.\n * So if the input elements are unique, there will be no repeat values in each\n * permutation.\n */\nexport function* permutations<T>(iterable: Iterable<T>, r?: number): IterableIterator<T[]> {\n const pool = Array.from(iterable);\n const n = pool.length;\n const x = r === undefined ? n : r;\n\n if (x > n) {\n return;\n }\n\n let indices: number[] = Array.from(range(n));\n const cycles: number[] = Array.from(range(n, n - x, -1));\n const poolgetter = (i: number) => pool[i];\n\n yield indices.slice(0, x).map(poolgetter);\n\n while (n > 0) {\n let cleanExit = true;\n for (const i of range(x - 1, -1, -1)) {\n cycles[i] -= 1;\n if (cycles[i] === 0) {\n indices = indices\n .slice(0, i)\n .concat(indices.slice(i + 1))\n .concat(indices.slice(i, i + 1));\n cycles[i] = n - i;\n } else {\n const j: number = cycles[i];\n\n const [p, q] = [indices[indices.length - j], indices[i]];\n indices[i] = p;\n indices[indices.length - j] = q;\n yield indices.slice(0, x).map(poolgetter);\n cleanExit = false;\n break;\n }\n }\n\n if (cleanExit) {\n return;\n }\n }\n}\n\n/**\n * Returns an iterator that produces values over and over again. Runs\n * indefinitely unless the times argument is specified.\n */\nexport function* repeat<T>(thing: T, times?: number): IterableIterator<T> {\n if (times === undefined) {\n for (;;) {\n yield thing;\n }\n } else {\n for (const _ of range(times)) {\n yield thing;\n }\n }\n}\n\n/**\n * Returns an iterator that produces elements from the iterable as long as the\n * predicate is true.\n */\nexport function* takewhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T> {\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (!predicate(value)) return; // early return, so we cannot use for..of loop!\n yield value;\n }\n}\n\nexport function zipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): Array<[T1 | D, T2 | D]> {\n return Array.from(izipLongest2(xs, ys, filler));\n}\n\nexport function zipLongest3<T1, T2, T3, D>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n filler?: D,\n): Array<[T1 | D, T2 | D, T3 | D]> {\n return Array.from(izipLongest3(xs, ys, zs, filler));\n}\n\nexport const izipLongest = izipLongest2;\nexport const zipLongest = zipLongest2;\n\nexport function zipMany<T>(...iters: Iterable<T>[]): T[][] {\n return Array.from(izipMany(...iters));\n}\n","import { count, ifilter, imap, izip, izip3, takewhile } from \"./itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { identityPredicate, keyToCmp, numberIdentity, primitiveIdentity } from \"./utils\";\n\n/**\n * Returns the first item in the iterable for which the predicate holds, if\n * any. If no predicate is given, it will return the first value returned by\n * the iterable.\n */\nexport function find<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n const it = iter(iterable);\n if (keyFn === undefined) {\n const value = it.next();\n return value.done ? value.value : value.value;\n } else {\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (keyFn(value)) {\n return value;\n }\n }\n return undefined;\n }\n}\n\n/**\n * Returns true when all of the items in iterable are truthy. An optional key\n * function can be used to define what truthiness means for this specific\n * collection.\n *\n * Examples:\n *\n * all([]) // => true\n * all([0]) // => false\n * all([0, 1, 2]) // => false\n * all([1, 2, 3]) // => true\n *\n * Examples with using a key function:\n *\n * all([2, 4, 6], n => n % 2 === 0) // => true\n * all([2, 4, 5], n => n % 2 === 0) // => false\n *\n */\nexport function every<T>(iterable: Iterable<T>, keyFn: Predicate<T> = identityPredicate): boolean {\n for (const item of iterable) {\n if (!keyFn(item)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Returns true when some of the items in iterable are truthy. An optional key\n * function can be used to define what truthiness means for this specific\n * collection.\n *\n * Examples:\n *\n * some([]) // => false\n * some([0]) // => false\n * some([0, 1, null, undefined]) // => true\n *\n * Examples with using a key function:\n *\n * some([1, 4, 5], n => n % 2 === 0) // => true\n * some([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false\n *\n */\nexport function some<T>(iterable: Iterable<T>, keyFn: Predicate<T> = identityPredicate): boolean {\n for (const item of iterable) {\n if (keyFn(item)) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Alias of `every()`.\n */\nexport const all = every;\n\n/**\n * Alias of `some()`.\n */\nexport const any = some;\n\n/**\n * Returns true when any of the items in the iterable are equal to the target object.\n *\n * Examples:\n *\n * contains([], 'whatever') // => false\n * contains([3], 42) // => false\n * contains([3], 3) // => true\n * contains([0, 1, 2], 2) // => true\n *\n */\nexport function contains<T>(haystack: Iterable<T>, needle: T): boolean {\n return some(haystack, (x) => x === needle);\n}\n\n/**\n * Returns an iterable of enumeration pairs. Iterable must be a sequence, an\n * iterator, or some other object which supports iteration. The elements\n * produced by returns a tuple containing a counter value (starting from 0 by\n * default) and the values obtained from iterating over given iterable.\n *\n * Example:\n *\n * import { enumerate } from 'itertools';\n *\n * console.log([...enumerate(['hello', 'world'])]);\n * // [0, 'hello'], [1, 'world']]\n */\nexport function* enumerate<T>(iterable: Iterable<T>, start = 0): IterableIterator<[number, T]> {\n let index: number = start;\n for (const value of iterable) {\n yield [index++, value];\n }\n}\n\n/**\n * Non-lazy version of ifilter().\n */\nexport function filter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): N[];\nexport function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[];\nexport function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[] {\n return Array.from(ifilter(iterable, predicate));\n}\n\n/**\n * Returns an iterator object for the given iterable. This can be used to\n * manually get an iterator for any iterable datastructure. The purpose and\n * main use case of this function is to get a single iterator (a thing with\n * state, think of it as a \"cursor\") which can only be consumed once.\n */\nexport function iter<T>(iterable: Iterable<T>): IterableIterator<T> {\n // class SelfIter implements IterableIterator<T> {\n // #iterator: Iterator<T>;\n // constructor(orig: Iterable<T>) {\n // this.#iterator = orig[Symbol.iterator]();\n // }\n // [Symbol.iterator]() {\n // return this;\n // }\n // next() {\n // return this.#iterator.next();\n // }\n // }\n // return new SelfIter(iterable);\n\n return iterable[Symbol.iterator]() as IterableIterator<T>;\n // ^^^^^^^^^^^^^^^^^^^^^^ Not safe!\n}\n\n/**\n * Non-lazy version of imap().\n */\nexport function map<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): V[] {\n return Array.from(imap(iterable, mapper));\n}\n\n/**\n * Return the largest item in an iterable. Only works for numbers, as ordering\n * is pretty poorly defined on any other data type in JS. The optional `keyFn`\n * argument specifies a one-argument ordering function like that used for\n * sorted().\n *\n * If the iterable is empty, `undefined` is returned.\n *\n * If multiple items are maximal, the function returns either one of them, but\n * which one is not defined.\n */\nexport function max<T>(iterable: Iterable<T>, keyFn: (item: T) => number = numberIdentity): T | undefined {\n return reduce2(iterable, (x, y) => (keyFn(x) > keyFn(y) ? x : y));\n}\n\n/**\n * Return the smallest item in an iterable. Only works for numbers, as\n * ordering is pretty poorly defined on any other data type in JS. The\n * optional `keyFn` argument specifies a one-argument ordering function like\n * that used for sorted().\n *\n * If the iterable is empty, `undefined` is returned.\n *\n * If multiple items are minimal, the function returns either one of them, but\n * which one is not defined.\n */\nexport function min<T>(iterable: Iterable<T>, keyFn: (item: T) => number = numberIdentity): T | undefined {\n return reduce2(iterable, (x, y) => (keyFn(x) < keyFn(y) ? x : y));\n}\n\n/**\n * Internal helper for the range function\n */\nfunction range_(start: number, stop: number, step: number): IterableIterator<number> {\n const counter = count(start, step);\n const pred = step >= 0 ? (n: number) => n < stop : (n: number) => n > stop;\n return takewhile(counter, pred);\n}\n\n/**\n * Returns an iterator producing all the numbers in the given range one by one,\n * starting from `start` (default 0), as long as `i < stop`, in increments of\n * `step` (default 1).\n *\n * `range(a)` is a convenient shorthand for `range(0, a)`.\n *\n * Various valid invocations:\n *\n * range(5) // [0, 1, 2, 3, 4]\n * range(2, 5) // [2, 3, 4]\n * range(0, 5, 2) // [0, 2, 4]\n * range(5, 0, -1) // [5, 4, 3, 2, 1]\n * range(-3) // []\n *\n * For a positive `step`, the iterator will keep producing values `n` as long\n * as the stop condition `n < stop` is satisfied.\n *\n * For a negative `step`, the iterator will keep producing values `n` as long\n * as the stop condition `n > stop` is satisfied.\n *\n * The produced range will be empty if the first value to produce already does\n * not meet the value constraint.\n */\n\nexport function range(stop: number): IterableIterator<number>;\nexport function range(start: number, stop: number, step?: number): IterableIterator<number>;\nexport function range(startOrStop: number, definitelyStop?: number, step = 1): IterableIterator<number> {\n if (definitelyStop !== undefined) {\n return range_(startOrStop /* as start */, definitelyStop, step);\n } else {\n return range_(0, startOrStop /* as stop */, step);\n }\n}\n\n/**\n * Apply function of two arguments cumulatively to the items of sequence, from\n * left to right, so as to reduce the sequence to a single value. For example:\n *\n * reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)\n *\n * calculates\n *\n * (((((0+1)+2)+3)+4)+5)\n *\n * The left argument, `x`, is the accumulated value and the right argument,\n * `y`, is the update value from the sequence.\n *\n * **Difference between `reduce()` and `reduce\\_()`**: `reduce()` requires an\n * explicit initializer, whereas `reduce_()` will automatically use the first\n * item in the given iterable as the initializer. When using `reduce()`, the\n * initializer value is placed before the items of the sequence in the\n * calculation, and serves as a default when the sequence is empty. When using\n * `reduce_()`, and the given iterable is empty, then no default value can be\n * derived and `undefined` will be returned.\n */\nexport function reduce<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined;\nexport function reduce<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O;\nexport function reduce<T, O>(\n iterable: Iterable<T>,\n reducer: ((agg: T, item: T, index: number) => T) | ((agg: O, item: T, index: number) => O),\n start?: O,\n): O | (T | undefined) {\n if (start === undefined) {\n return reduce2(iterable, reducer as (agg: T, item: T, index: number) => T);\n } else {\n return reduce3(iterable, reducer as (agg: O, item: T, index: number) => O, start);\n }\n}\n\nfunction reduce3<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O {\n let output = start;\n let index = 0;\n for (const item of iterable) {\n output = reducer(output, item, index++);\n }\n return output;\n}\n\nfunction reduce2<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined {\n const it = iter(iterable);\n const start = find(it);\n if (start === undefined) {\n return undefined;\n } else {\n return reduce3(it, reducer, start);\n }\n}\n\n/**\n * Return a new sorted list from the items in iterable.\n *\n * Has two optional arguments:\n *\n * * `keyFn` specifies a function of one argument providing a primitive\n * identity for each element in the iterable. that will be used to compare.\n * The default value is to use a default identity function that is only\n * defined for primitive types.\n *\n * * `reverse` is a boolean value. If `true`, then the list elements are\n * sorted as if each comparison were reversed.\n */\nexport function sorted<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n reverse = false,\n): T[] {\n const result = Array.from(iterable);\n result.sort(keyToCmp(keyFn)); // sort in-place\n\n if (reverse) {\n result.reverse(); // reverse in-place\n }\n\n return result;\n}\n\n/**\n * Sums the items of an iterable from left to right and returns the total. The\n * sum will defaults to 0 if the iterable is empty.\n */\nexport function sum(iterable: Iterable<number>): number {\n return reduce(iterable, (x, y) => x + y, 0);\n}\n\n/**\n * See izip.\n */\nexport function zip<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): Array<[T1, T2]> {\n return Array.from(izip(xs, ys));\n}\n\n/**\n * See izip3.\n */\nexport function zip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): Array<[T1, T2, T3]> {\n return Array.from(izip3(xs, ys, zs));\n}\n","import { find } from \"./builtins\";\nimport { ifilter, imap } from \"./itertools\";\nimport { flatten } from \"./more-itertools\";\nimport type { Predicate } from \"./types\";\n\nfunction isNullish<T>(x: T): x is NonNullable<T> {\n return x != null;\n}\n\nfunction isDefined<T>(x: T): boolean {\n return x !== undefined;\n}\n\n/**\n * Returns an iterable, filtering out any \"nullish\" values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3, null])\n * [1, 2, 3]\n *\n * For an eager version, @see compact().\n */\nexport function icompact<T>(iterable: Iterable<T | null | undefined>): IterableIterator<T> {\n return ifilter(iterable, isNullish);\n}\n\n/**\n * Returns an array, filtering out any \"nullish\" values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3, null])\n * [1, 2, 3]\n *\n * For a lazy version, @see icompact().\n */\nexport function compact<T>(iterable: Iterable<T | null | undefined>): T[] {\n return Array.from(icompact(iterable));\n}\n\n/**\n * Removes all \"nullish\" values from the given object. Returns a new object.\n *\n * >>> compactObject({ a: 1, b: undefined, c: 0, d: null })\n * { a: 1, c: 0 }\n *\n */\nexport function compactObject<K extends string, V>(obj: Record<K, V | null | undefined>): Record<K, V> {\n const result = {} as Record<K, V>;\n for (const [key, value_] of Object.entries(obj)) {\n const value = value_ as V | null | undefined;\n if (value != null) {\n result[key as K] = value;\n }\n }\n return result;\n}\n\n/**\n * Almost an alias of find(). There only is a difference if no key fn is\n * provided. In that case, `find()` will return the first item in the iterable,\n * whereas `first()` will return the first non-`undefined` value in the\n * iterable.\n */\nexport function first<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n return find(iterable, keyFn ?? isDefined);\n}\n\n/**\n * Returns 0 or more values for every value in the given iterable.\n * Technically, it's just calling map(), followed by flatten(), but it's a very\n * useful operation if you want to map over a structure, but not have a 1:1\n * input-output mapping. Instead, if you want to potentially return 0 or more\n * values per input element, use flatmap():\n *\n * For example, to return all numbers `n` in the input iterable `n` times:\n *\n * >>> const repeatN = n => repeat(n, n);\n * >>> [...flatmap([0, 1, 2, 3, 4], repeatN)]\n * [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0\n *\n */\nexport function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>): IterableIterator<S> {\n return flatten(imap(iterable, mapper));\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -77,7 +77,7 @@ declare function contains<T>(haystack: Iterable<T>, needle: T): boolean;
|
|
|
77
77
|
* console.log([...enumerate(['hello', 'world'])]);
|
|
78
78
|
* // [0, 'hello'], [1, 'world']]
|
|
79
79
|
*/
|
|
80
|
-
declare function enumerate<T>(iterable: Iterable<T>, start?: number):
|
|
80
|
+
declare function enumerate<T>(iterable: Iterable<T>, start?: number): IterableIterator<[number, T]>;
|
|
81
81
|
/**
|
|
82
82
|
* Non-lazy version of ifilter().
|
|
83
83
|
*/
|
|
@@ -142,8 +142,8 @@ declare function min<T>(iterable: Iterable<T>, keyFn?: (item: T) => number): T |
|
|
|
142
142
|
* The produced range will be empty if the first value to produce already does
|
|
143
143
|
* not meet the value constraint.
|
|
144
144
|
*/
|
|
145
|
-
declare function range(stop: number):
|
|
146
|
-
declare function range(start: number, stop: number, step?: number):
|
|
145
|
+
declare function range(stop: number): IterableIterator<number>;
|
|
146
|
+
declare function range(start: number, stop: number, step?: number): IterableIterator<number>;
|
|
147
147
|
/**
|
|
148
148
|
* Apply function of two arguments cumulatively to the items of sequence, from
|
|
149
149
|
* left to right, so as to reduce the sequence to a single value. For example:
|
|
@@ -201,13 +201,13 @@ declare function zip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterab
|
|
|
201
201
|
* are exhausted. Used for treating consecutive sequences as a single
|
|
202
202
|
* sequence.
|
|
203
203
|
*/
|
|
204
|
-
declare function chain<T>(...iterables: Iterable<T>[]):
|
|
204
|
+
declare function chain<T>(...iterables: Iterable<T>[]): IterableIterator<T>;
|
|
205
205
|
/**
|
|
206
206
|
* Returns an iterator that counts up values starting with number `start`
|
|
207
207
|
* (default 0), incrementing by `step`. To decrement, use a negative step
|
|
208
208
|
* number.
|
|
209
209
|
*/
|
|
210
|
-
declare function count(start?: number, step?: number):
|
|
210
|
+
declare function count(start?: number, step?: number): IterableIterator<number>;
|
|
211
211
|
/**
|
|
212
212
|
* Non-lazy version of icompress().
|
|
213
213
|
*/
|
|
@@ -217,32 +217,32 @@ declare function compress<T>(data: Iterable<T>, selectors: Iterable<boolean>): T
|
|
|
217
217
|
* of each. When the iterable is exhausted, return elements from the saved
|
|
218
218
|
* copy. Repeats indefinitely.
|
|
219
219
|
*/
|
|
220
|
-
declare function cycle<T>(iterable: Iterable<T>):
|
|
220
|
+
declare function cycle<T>(iterable: Iterable<T>): IterableIterator<T>;
|
|
221
221
|
/**
|
|
222
222
|
* Returns an iterator that drops elements from the iterable as long as the
|
|
223
223
|
* predicate is true; afterwards, returns every remaining element. Note, the
|
|
224
224
|
* iterator does not produce any output until the predicate first becomes
|
|
225
225
|
* false.
|
|
226
226
|
*/
|
|
227
|
-
declare function dropwhile<T>(iterable: Iterable<T>, predicate: Predicate<T>):
|
|
227
|
+
declare function dropwhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T>;
|
|
228
228
|
declare function groupby<T, K extends Primitive>(iterable: Iterable<T>, keyFn?: (item: T) => K): Generator<[K, Generator<T, undefined>], undefined>;
|
|
229
229
|
/**
|
|
230
230
|
* Returns an iterator that filters elements from data returning only those
|
|
231
231
|
* that have a corresponding element in selectors that evaluates to `true`.
|
|
232
232
|
* Stops when either the data or selectors iterables has been exhausted.
|
|
233
233
|
*/
|
|
234
|
-
declare function icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>):
|
|
234
|
+
declare function icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>): IterableIterator<T>;
|
|
235
235
|
/**
|
|
236
236
|
* Returns an iterator that filters elements from iterable returning only those
|
|
237
237
|
* for which the predicate is true.
|
|
238
238
|
*/
|
|
239
|
-
declare function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N):
|
|
240
|
-
declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>):
|
|
239
|
+
declare function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): IterableIterator<N>;
|
|
240
|
+
declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T>;
|
|
241
241
|
/**
|
|
242
242
|
* Returns an iterator that computes the given mapper function using arguments
|
|
243
243
|
* from each of the iterables.
|
|
244
244
|
*/
|
|
245
|
-
declare function imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V):
|
|
245
|
+
declare function imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): IterableIterator<V>;
|
|
246
246
|
/**
|
|
247
247
|
* Returns an iterator that returns selected elements from the iterable. If
|
|
248
248
|
* `start` is non-zero, then elements from the iterable are skipped until start
|
|
@@ -252,26 +252,26 @@ declare function imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): Iter
|
|
|
252
252
|
* otherwise, the iterable will be fully exhausted. `islice()` does not
|
|
253
253
|
* support negative values for `start`, `stop`, or `step`.
|
|
254
254
|
*/
|
|
255
|
-
declare function islice<T>(iterable: Iterable<T>, stop: number):
|
|
256
|
-
declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number | null, step?: number):
|
|
255
|
+
declare function islice<T>(iterable: Iterable<T>, stop: number): IterableIterator<T>;
|
|
256
|
+
declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number | null, step?: number): IterableIterator<T>;
|
|
257
257
|
/**
|
|
258
258
|
* Returns an iterator that aggregates elements from each of the iterables.
|
|
259
259
|
* Used for lock-step iteration over several iterables at a time. When
|
|
260
260
|
* iterating over two iterables, use `izip2`. When iterating over three
|
|
261
261
|
* iterables, use `izip3`, etc. `izip` is an alias for `izip2`.
|
|
262
262
|
*/
|
|
263
|
-
declare function
|
|
263
|
+
declare function izip<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): IterableIterator<[T1, T2]>;
|
|
264
264
|
/**
|
|
265
265
|
* Like izip2, but for three input iterables.
|
|
266
266
|
*/
|
|
267
|
-
declare function izip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>):
|
|
268
|
-
declare const
|
|
267
|
+
declare function izip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): IterableIterator<[T1, T2, T3]>;
|
|
268
|
+
declare const izip2: typeof izip;
|
|
269
269
|
/**
|
|
270
270
|
* Returns an iterator that aggregates elements from each of the iterables. If
|
|
271
271
|
* the iterables are of uneven length, missing values are filled-in with
|
|
272
272
|
* fillvalue. Iteration continues until the longest iterable is exhausted.
|
|
273
273
|
*/
|
|
274
|
-
declare function izipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D):
|
|
274
|
+
declare function izipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): IterableIterator<[T1 | D, T2 | D]>;
|
|
275
275
|
/**
|
|
276
276
|
* Like the other izips (`izip`, `izip3`, etc), but generalized to take an
|
|
277
277
|
* unlimited amount of input iterables. Think `izip(*iterables)` in Python.
|
|
@@ -280,7 +280,7 @@ declare function izipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, fil
|
|
|
280
280
|
* iterables with homogeneous types, so you cannot mix types like <A, B> like
|
|
281
281
|
* you can with izip2().
|
|
282
282
|
*/
|
|
283
|
-
declare function izipMany<T>(...iters: Iterable<T>[]):
|
|
283
|
+
declare function izipMany<T>(...iters: Iterable<T>[]): IterableIterator<T[]>;
|
|
284
284
|
/**
|
|
285
285
|
* Return successive `r`-length permutations of elements in the iterable.
|
|
286
286
|
*
|
|
@@ -294,12 +294,17 @@ declare function izipMany<T>(...iters: Iterable<T>[]): Iterable<T[]>;
|
|
|
294
294
|
* So if the input elements are unique, there will be no repeat values in each
|
|
295
295
|
* permutation.
|
|
296
296
|
*/
|
|
297
|
-
declare function permutations<T>(iterable: Iterable<T>, r?: number):
|
|
297
|
+
declare function permutations<T>(iterable: Iterable<T>, r?: number): IterableIterator<T[]>;
|
|
298
|
+
/**
|
|
299
|
+
* Returns an iterator that produces values over and over again. Runs
|
|
300
|
+
* indefinitely unless the times argument is specified.
|
|
301
|
+
*/
|
|
302
|
+
declare function repeat<T>(thing: T, times?: number): IterableIterator<T>;
|
|
298
303
|
/**
|
|
299
304
|
* Returns an iterator that produces elements from the iterable as long as the
|
|
300
305
|
* predicate is true.
|
|
301
306
|
*/
|
|
302
|
-
declare function takewhile<T>(iterable: Iterable<T>, predicate: Predicate<T>):
|
|
307
|
+
declare function takewhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T>;
|
|
303
308
|
declare function zipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): Array<[T1 | D, T2 | D]>;
|
|
304
309
|
declare const izipLongest: typeof izipLongest2;
|
|
305
310
|
declare const zipLongest: typeof zipLongest2;
|
|
@@ -317,7 +322,7 @@ declare function zipMany<T>(...iters: Iterable<T>[]): T[][];
|
|
|
317
322
|
* [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]
|
|
318
323
|
* // [[1, 2, 3], [4, 5, 6], [7, 8]]
|
|
319
324
|
*/
|
|
320
|
-
declare function chunked<T>(iterable: Iterable<T>, size: number):
|
|
325
|
+
declare function chunked<T>(iterable: Iterable<T>, size: number): IterableIterator<T[]>;
|
|
321
326
|
/**
|
|
322
327
|
* Return an iterator flattening one level of nesting in a list of lists:
|
|
323
328
|
*
|
|
@@ -325,12 +330,12 @@ declare function chunked<T>(iterable: Iterable<T>, size: number): Iterable<T[]>;
|
|
|
325
330
|
* // [0, 1, 2, 3]
|
|
326
331
|
*
|
|
327
332
|
*/
|
|
328
|
-
declare function flatten<T>(iterableOfIterables: Iterable<Iterable<T>>):
|
|
333
|
+
declare function flatten<T>(iterableOfIterables: Iterable<Iterable<T>>): IterableIterator<T>;
|
|
329
334
|
/**
|
|
330
335
|
* Returns an iterable containing only the first `n` elements of the given
|
|
331
336
|
* iterable.
|
|
332
337
|
*/
|
|
333
|
-
declare function itake<T>(n: number, iterable: Iterable<T>):
|
|
338
|
+
declare function itake<T>(n: number, iterable: Iterable<T>): IterableIterator<T>;
|
|
334
339
|
/**
|
|
335
340
|
* Returns an iterator of paired items, overlapping, from the original. When
|
|
336
341
|
* the input iterable has a finite number of items `n`, the outputted iterable
|
|
@@ -340,7 +345,7 @@ declare function itake<T>(n: number, iterable: Iterable<T>): Iterable<T>;
|
|
|
340
345
|
* [(8, 2), (2, 0), (0, 7)]
|
|
341
346
|
*
|
|
342
347
|
*/
|
|
343
|
-
declare function pairwise<T>(iterable: Iterable<T>):
|
|
348
|
+
declare function pairwise<T>(iterable: Iterable<T>): IterableIterator<[T, T]>;
|
|
344
349
|
/**
|
|
345
350
|
* Returns a 2-tuple of arrays. Splits the elements in the input iterable into
|
|
346
351
|
* either of the two arrays. Will fully exhaust the input iterable. The first
|
|
@@ -364,7 +369,7 @@ declare function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [
|
|
|
364
369
|
* >>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
365
370
|
* [1, 4, 5, 2, 6, 3, 7, 8]
|
|
366
371
|
*/
|
|
367
|
-
declare function roundrobin<T>(...iters: Iterable<T>[]):
|
|
372
|
+
declare function roundrobin<T>(...iters: Iterable<T>[]): IterableIterator<T>;
|
|
368
373
|
/**
|
|
369
374
|
* Yields the heads of all of the given iterables. This is almost like
|
|
370
375
|
* `roundrobin()`, except that the yielded outputs are grouped in to the
|
|
@@ -376,7 +381,7 @@ declare function roundrobin<T>(...iters: Iterable<T>[]): Iterable<T>;
|
|
|
376
381
|
* This is also different from `zipLongest()`, since the number of items in
|
|
377
382
|
* each round can decrease over time, rather than being filled with a filler.
|
|
378
383
|
*/
|
|
379
|
-
declare function heads<T>(...iters: Array<Iterable<T>>):
|
|
384
|
+
declare function heads<T>(...iters: Array<Iterable<T>>): IterableIterator<T[]>;
|
|
380
385
|
/**
|
|
381
386
|
* Non-lazy version of itake().
|
|
382
387
|
*/
|
|
@@ -390,7 +395,7 @@ declare function take<T>(n: number, iterable: Iterable<T>): T[];
|
|
|
390
395
|
* ['A', 'b', 'C']
|
|
391
396
|
*
|
|
392
397
|
*/
|
|
393
|
-
declare function uniqueEverseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => Primitive):
|
|
398
|
+
declare function uniqueEverseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => Primitive): IterableIterator<T>;
|
|
394
399
|
/**
|
|
395
400
|
* Yields elements in order, ignoring serial duplicates.
|
|
396
401
|
*
|
|
@@ -400,7 +405,7 @@ declare function uniqueEverseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => P
|
|
|
400
405
|
* ['A', 'b', 'C', 'A', 'B']
|
|
401
406
|
*
|
|
402
407
|
*/
|
|
403
|
-
declare function uniqueJustseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => Primitive):
|
|
408
|
+
declare function uniqueJustseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => Primitive): IterableIterator<T>;
|
|
404
409
|
|
|
405
410
|
/**
|
|
406
411
|
* Returns an iterable, filtering out any "nullish" values from the iterable.
|
|
@@ -410,7 +415,7 @@ declare function uniqueJustseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => P
|
|
|
410
415
|
*
|
|
411
416
|
* For an eager version, @see compact().
|
|
412
417
|
*/
|
|
413
|
-
declare function icompact<T>(iterable: Iterable<T | null | undefined>):
|
|
418
|
+
declare function icompact<T>(iterable: Iterable<T | null | undefined>): IterableIterator<T>;
|
|
414
419
|
/**
|
|
415
420
|
* Returns an array, filtering out any "nullish" values from the iterable.
|
|
416
421
|
*
|
|
@@ -449,6 +454,6 @@ declare function first<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | unde
|
|
|
449
454
|
* [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0
|
|
450
455
|
*
|
|
451
456
|
*/
|
|
452
|
-
declare function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>):
|
|
457
|
+
declare function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>): IterableIterator<S>;
|
|
453
458
|
|
|
454
|
-
export { type Predicate, type Primitive, all, any, chain, chunked, compact, compactObject, compress, contains, count, cycle, dropwhile, enumerate, every, filter, find, first, flatmap, flatten, groupby, heads, icompact, icompress, ifilter, imap, islice, itake, iter, izip, izip2, izip3, izipLongest, izipMany, map, max, min, pairwise, partition, permutations, range, reduce, roundrobin, some, sorted, sum, take, takewhile, uniqueEverseen, uniqueJustseen, zip, zip3, zipLongest, zipMany };
|
|
459
|
+
export { type Predicate, type Primitive, all, any, chain, chunked, compact, compactObject, compress, contains, count, cycle, dropwhile, enumerate, every, filter, find, first, flatmap, flatten, groupby, heads, icompact, icompress, ifilter, imap, islice, itake, iter, izip, izip2, izip3, izipLongest, izipMany, map, max, min, pairwise, partition, permutations, range, reduce, repeat, roundrobin, some, sorted, sum, take, takewhile, uniqueEverseen, uniqueJustseen, zip, zip3, zipLongest, zipMany };
|
package/dist/index.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ declare function contains<T>(haystack: Iterable<T>, needle: T): boolean;
|
|
|
77
77
|
* console.log([...enumerate(['hello', 'world'])]);
|
|
78
78
|
* // [0, 'hello'], [1, 'world']]
|
|
79
79
|
*/
|
|
80
|
-
declare function enumerate<T>(iterable: Iterable<T>, start?: number):
|
|
80
|
+
declare function enumerate<T>(iterable: Iterable<T>, start?: number): IterableIterator<[number, T]>;
|
|
81
81
|
/**
|
|
82
82
|
* Non-lazy version of ifilter().
|
|
83
83
|
*/
|
|
@@ -142,8 +142,8 @@ declare function min<T>(iterable: Iterable<T>, keyFn?: (item: T) => number): T |
|
|
|
142
142
|
* The produced range will be empty if the first value to produce already does
|
|
143
143
|
* not meet the value constraint.
|
|
144
144
|
*/
|
|
145
|
-
declare function range(stop: number):
|
|
146
|
-
declare function range(start: number, stop: number, step?: number):
|
|
145
|
+
declare function range(stop: number): IterableIterator<number>;
|
|
146
|
+
declare function range(start: number, stop: number, step?: number): IterableIterator<number>;
|
|
147
147
|
/**
|
|
148
148
|
* Apply function of two arguments cumulatively to the items of sequence, from
|
|
149
149
|
* left to right, so as to reduce the sequence to a single value. For example:
|
|
@@ -201,13 +201,13 @@ declare function zip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterab
|
|
|
201
201
|
* are exhausted. Used for treating consecutive sequences as a single
|
|
202
202
|
* sequence.
|
|
203
203
|
*/
|
|
204
|
-
declare function chain<T>(...iterables: Iterable<T>[]):
|
|
204
|
+
declare function chain<T>(...iterables: Iterable<T>[]): IterableIterator<T>;
|
|
205
205
|
/**
|
|
206
206
|
* Returns an iterator that counts up values starting with number `start`
|
|
207
207
|
* (default 0), incrementing by `step`. To decrement, use a negative step
|
|
208
208
|
* number.
|
|
209
209
|
*/
|
|
210
|
-
declare function count(start?: number, step?: number):
|
|
210
|
+
declare function count(start?: number, step?: number): IterableIterator<number>;
|
|
211
211
|
/**
|
|
212
212
|
* Non-lazy version of icompress().
|
|
213
213
|
*/
|
|
@@ -217,32 +217,32 @@ declare function compress<T>(data: Iterable<T>, selectors: Iterable<boolean>): T
|
|
|
217
217
|
* of each. When the iterable is exhausted, return elements from the saved
|
|
218
218
|
* copy. Repeats indefinitely.
|
|
219
219
|
*/
|
|
220
|
-
declare function cycle<T>(iterable: Iterable<T>):
|
|
220
|
+
declare function cycle<T>(iterable: Iterable<T>): IterableIterator<T>;
|
|
221
221
|
/**
|
|
222
222
|
* Returns an iterator that drops elements from the iterable as long as the
|
|
223
223
|
* predicate is true; afterwards, returns every remaining element. Note, the
|
|
224
224
|
* iterator does not produce any output until the predicate first becomes
|
|
225
225
|
* false.
|
|
226
226
|
*/
|
|
227
|
-
declare function dropwhile<T>(iterable: Iterable<T>, predicate: Predicate<T>):
|
|
227
|
+
declare function dropwhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T>;
|
|
228
228
|
declare function groupby<T, K extends Primitive>(iterable: Iterable<T>, keyFn?: (item: T) => K): Generator<[K, Generator<T, undefined>], undefined>;
|
|
229
229
|
/**
|
|
230
230
|
* Returns an iterator that filters elements from data returning only those
|
|
231
231
|
* that have a corresponding element in selectors that evaluates to `true`.
|
|
232
232
|
* Stops when either the data or selectors iterables has been exhausted.
|
|
233
233
|
*/
|
|
234
|
-
declare function icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>):
|
|
234
|
+
declare function icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>): IterableIterator<T>;
|
|
235
235
|
/**
|
|
236
236
|
* Returns an iterator that filters elements from iterable returning only those
|
|
237
237
|
* for which the predicate is true.
|
|
238
238
|
*/
|
|
239
|
-
declare function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N):
|
|
240
|
-
declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>):
|
|
239
|
+
declare function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): IterableIterator<N>;
|
|
240
|
+
declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T>;
|
|
241
241
|
/**
|
|
242
242
|
* Returns an iterator that computes the given mapper function using arguments
|
|
243
243
|
* from each of the iterables.
|
|
244
244
|
*/
|
|
245
|
-
declare function imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V):
|
|
245
|
+
declare function imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): IterableIterator<V>;
|
|
246
246
|
/**
|
|
247
247
|
* Returns an iterator that returns selected elements from the iterable. If
|
|
248
248
|
* `start` is non-zero, then elements from the iterable are skipped until start
|
|
@@ -252,26 +252,26 @@ declare function imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): Iter
|
|
|
252
252
|
* otherwise, the iterable will be fully exhausted. `islice()` does not
|
|
253
253
|
* support negative values for `start`, `stop`, or `step`.
|
|
254
254
|
*/
|
|
255
|
-
declare function islice<T>(iterable: Iterable<T>, stop: number):
|
|
256
|
-
declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number | null, step?: number):
|
|
255
|
+
declare function islice<T>(iterable: Iterable<T>, stop: number): IterableIterator<T>;
|
|
256
|
+
declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number | null, step?: number): IterableIterator<T>;
|
|
257
257
|
/**
|
|
258
258
|
* Returns an iterator that aggregates elements from each of the iterables.
|
|
259
259
|
* Used for lock-step iteration over several iterables at a time. When
|
|
260
260
|
* iterating over two iterables, use `izip2`. When iterating over three
|
|
261
261
|
* iterables, use `izip3`, etc. `izip` is an alias for `izip2`.
|
|
262
262
|
*/
|
|
263
|
-
declare function
|
|
263
|
+
declare function izip<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): IterableIterator<[T1, T2]>;
|
|
264
264
|
/**
|
|
265
265
|
* Like izip2, but for three input iterables.
|
|
266
266
|
*/
|
|
267
|
-
declare function izip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>):
|
|
268
|
-
declare const
|
|
267
|
+
declare function izip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): IterableIterator<[T1, T2, T3]>;
|
|
268
|
+
declare const izip2: typeof izip;
|
|
269
269
|
/**
|
|
270
270
|
* Returns an iterator that aggregates elements from each of the iterables. If
|
|
271
271
|
* the iterables are of uneven length, missing values are filled-in with
|
|
272
272
|
* fillvalue. Iteration continues until the longest iterable is exhausted.
|
|
273
273
|
*/
|
|
274
|
-
declare function izipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D):
|
|
274
|
+
declare function izipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): IterableIterator<[T1 | D, T2 | D]>;
|
|
275
275
|
/**
|
|
276
276
|
* Like the other izips (`izip`, `izip3`, etc), but generalized to take an
|
|
277
277
|
* unlimited amount of input iterables. Think `izip(*iterables)` in Python.
|
|
@@ -280,7 +280,7 @@ declare function izipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, fil
|
|
|
280
280
|
* iterables with homogeneous types, so you cannot mix types like <A, B> like
|
|
281
281
|
* you can with izip2().
|
|
282
282
|
*/
|
|
283
|
-
declare function izipMany<T>(...iters: Iterable<T>[]):
|
|
283
|
+
declare function izipMany<T>(...iters: Iterable<T>[]): IterableIterator<T[]>;
|
|
284
284
|
/**
|
|
285
285
|
* Return successive `r`-length permutations of elements in the iterable.
|
|
286
286
|
*
|
|
@@ -294,12 +294,17 @@ declare function izipMany<T>(...iters: Iterable<T>[]): Iterable<T[]>;
|
|
|
294
294
|
* So if the input elements are unique, there will be no repeat values in each
|
|
295
295
|
* permutation.
|
|
296
296
|
*/
|
|
297
|
-
declare function permutations<T>(iterable: Iterable<T>, r?: number):
|
|
297
|
+
declare function permutations<T>(iterable: Iterable<T>, r?: number): IterableIterator<T[]>;
|
|
298
|
+
/**
|
|
299
|
+
* Returns an iterator that produces values over and over again. Runs
|
|
300
|
+
* indefinitely unless the times argument is specified.
|
|
301
|
+
*/
|
|
302
|
+
declare function repeat<T>(thing: T, times?: number): IterableIterator<T>;
|
|
298
303
|
/**
|
|
299
304
|
* Returns an iterator that produces elements from the iterable as long as the
|
|
300
305
|
* predicate is true.
|
|
301
306
|
*/
|
|
302
|
-
declare function takewhile<T>(iterable: Iterable<T>, predicate: Predicate<T>):
|
|
307
|
+
declare function takewhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T>;
|
|
303
308
|
declare function zipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): Array<[T1 | D, T2 | D]>;
|
|
304
309
|
declare const izipLongest: typeof izipLongest2;
|
|
305
310
|
declare const zipLongest: typeof zipLongest2;
|
|
@@ -317,7 +322,7 @@ declare function zipMany<T>(...iters: Iterable<T>[]): T[][];
|
|
|
317
322
|
* [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]
|
|
318
323
|
* // [[1, 2, 3], [4, 5, 6], [7, 8]]
|
|
319
324
|
*/
|
|
320
|
-
declare function chunked<T>(iterable: Iterable<T>, size: number):
|
|
325
|
+
declare function chunked<T>(iterable: Iterable<T>, size: number): IterableIterator<T[]>;
|
|
321
326
|
/**
|
|
322
327
|
* Return an iterator flattening one level of nesting in a list of lists:
|
|
323
328
|
*
|
|
@@ -325,12 +330,12 @@ declare function chunked<T>(iterable: Iterable<T>, size: number): Iterable<T[]>;
|
|
|
325
330
|
* // [0, 1, 2, 3]
|
|
326
331
|
*
|
|
327
332
|
*/
|
|
328
|
-
declare function flatten<T>(iterableOfIterables: Iterable<Iterable<T>>):
|
|
333
|
+
declare function flatten<T>(iterableOfIterables: Iterable<Iterable<T>>): IterableIterator<T>;
|
|
329
334
|
/**
|
|
330
335
|
* Returns an iterable containing only the first `n` elements of the given
|
|
331
336
|
* iterable.
|
|
332
337
|
*/
|
|
333
|
-
declare function itake<T>(n: number, iterable: Iterable<T>):
|
|
338
|
+
declare function itake<T>(n: number, iterable: Iterable<T>): IterableIterator<T>;
|
|
334
339
|
/**
|
|
335
340
|
* Returns an iterator of paired items, overlapping, from the original. When
|
|
336
341
|
* the input iterable has a finite number of items `n`, the outputted iterable
|
|
@@ -340,7 +345,7 @@ declare function itake<T>(n: number, iterable: Iterable<T>): Iterable<T>;
|
|
|
340
345
|
* [(8, 2), (2, 0), (0, 7)]
|
|
341
346
|
*
|
|
342
347
|
*/
|
|
343
|
-
declare function pairwise<T>(iterable: Iterable<T>):
|
|
348
|
+
declare function pairwise<T>(iterable: Iterable<T>): IterableIterator<[T, T]>;
|
|
344
349
|
/**
|
|
345
350
|
* Returns a 2-tuple of arrays. Splits the elements in the input iterable into
|
|
346
351
|
* either of the two arrays. Will fully exhaust the input iterable. The first
|
|
@@ -364,7 +369,7 @@ declare function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [
|
|
|
364
369
|
* >>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
365
370
|
* [1, 4, 5, 2, 6, 3, 7, 8]
|
|
366
371
|
*/
|
|
367
|
-
declare function roundrobin<T>(...iters: Iterable<T>[]):
|
|
372
|
+
declare function roundrobin<T>(...iters: Iterable<T>[]): IterableIterator<T>;
|
|
368
373
|
/**
|
|
369
374
|
* Yields the heads of all of the given iterables. This is almost like
|
|
370
375
|
* `roundrobin()`, except that the yielded outputs are grouped in to the
|
|
@@ -376,7 +381,7 @@ declare function roundrobin<T>(...iters: Iterable<T>[]): Iterable<T>;
|
|
|
376
381
|
* This is also different from `zipLongest()`, since the number of items in
|
|
377
382
|
* each round can decrease over time, rather than being filled with a filler.
|
|
378
383
|
*/
|
|
379
|
-
declare function heads<T>(...iters: Array<Iterable<T>>):
|
|
384
|
+
declare function heads<T>(...iters: Array<Iterable<T>>): IterableIterator<T[]>;
|
|
380
385
|
/**
|
|
381
386
|
* Non-lazy version of itake().
|
|
382
387
|
*/
|
|
@@ -390,7 +395,7 @@ declare function take<T>(n: number, iterable: Iterable<T>): T[];
|
|
|
390
395
|
* ['A', 'b', 'C']
|
|
391
396
|
*
|
|
392
397
|
*/
|
|
393
|
-
declare function uniqueEverseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => Primitive):
|
|
398
|
+
declare function uniqueEverseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => Primitive): IterableIterator<T>;
|
|
394
399
|
/**
|
|
395
400
|
* Yields elements in order, ignoring serial duplicates.
|
|
396
401
|
*
|
|
@@ -400,7 +405,7 @@ declare function uniqueEverseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => P
|
|
|
400
405
|
* ['A', 'b', 'C', 'A', 'B']
|
|
401
406
|
*
|
|
402
407
|
*/
|
|
403
|
-
declare function uniqueJustseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => Primitive):
|
|
408
|
+
declare function uniqueJustseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => Primitive): IterableIterator<T>;
|
|
404
409
|
|
|
405
410
|
/**
|
|
406
411
|
* Returns an iterable, filtering out any "nullish" values from the iterable.
|
|
@@ -410,7 +415,7 @@ declare function uniqueJustseen<T>(iterable: Iterable<T>, keyFn?: (item: T) => P
|
|
|
410
415
|
*
|
|
411
416
|
* For an eager version, @see compact().
|
|
412
417
|
*/
|
|
413
|
-
declare function icompact<T>(iterable: Iterable<T | null | undefined>):
|
|
418
|
+
declare function icompact<T>(iterable: Iterable<T | null | undefined>): IterableIterator<T>;
|
|
414
419
|
/**
|
|
415
420
|
* Returns an array, filtering out any "nullish" values from the iterable.
|
|
416
421
|
*
|
|
@@ -449,6 +454,6 @@ declare function first<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | unde
|
|
|
449
454
|
* [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0
|
|
450
455
|
*
|
|
451
456
|
*/
|
|
452
|
-
declare function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>):
|
|
457
|
+
declare function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>): IterableIterator<S>;
|
|
453
458
|
|
|
454
|
-
export { type Predicate, type Primitive, all, any, chain, chunked, compact, compactObject, compress, contains, count, cycle, dropwhile, enumerate, every, filter, find, first, flatmap, flatten, groupby, heads, icompact, icompress, ifilter, imap, islice, itake, iter, izip, izip2, izip3, izipLongest, izipMany, map, max, min, pairwise, partition, permutations, range, reduce, roundrobin, some, sorted, sum, take, takewhile, uniqueEverseen, uniqueJustseen, zip, zip3, zipLongest, zipMany };
|
|
459
|
+
export { type Predicate, type Primitive, all, any, chain, chunked, compact, compactObject, compress, contains, count, cycle, dropwhile, enumerate, every, filter, find, first, flatmap, flatten, groupby, heads, icompact, icompress, ifilter, imap, islice, itake, iter, izip, izip2, izip3, izipLongest, izipMany, map, max, min, pairwise, partition, permutations, range, reduce, repeat, roundrobin, some, sorted, sum, take, takewhile, uniqueEverseen, uniqueJustseen, zip, zip3, zipLongest, zipMany };
|
package/dist/index.js
CHANGED
|
@@ -270,7 +270,7 @@ function* islice(iterable, stopOrStart, possiblyStop, step = 1) {
|
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
-
function*
|
|
273
|
+
function* izip(xs, ys) {
|
|
274
274
|
const ixs = iter(xs);
|
|
275
275
|
const iys = iter(ys);
|
|
276
276
|
for (; ; ) {
|
|
@@ -298,7 +298,7 @@ function* izip3(xs, ys, zs) {
|
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
-
var
|
|
301
|
+
var izip2 = izip;
|
|
302
302
|
function* izipLongest2(xs, ys, filler) {
|
|
303
303
|
const filler_ = filler;
|
|
304
304
|
const ixs = iter(xs);
|
|
@@ -357,6 +357,17 @@ function* permutations(iterable, r) {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
|
+
function* repeat(thing, times) {
|
|
361
|
+
if (times === void 0) {
|
|
362
|
+
for (; ; ) {
|
|
363
|
+
yield thing;
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
for (const _ of range(times)) {
|
|
367
|
+
yield thing;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
360
371
|
function* takewhile(iterable, predicate) {
|
|
361
372
|
const it = iter(iterable);
|
|
362
373
|
let res;
|
|
@@ -414,7 +425,7 @@ var any = some;
|
|
|
414
425
|
function contains(haystack, needle) {
|
|
415
426
|
return some(haystack, (x) => x === needle);
|
|
416
427
|
}
|
|
417
|
-
function*
|
|
428
|
+
function* enumerate(iterable, start = 0) {
|
|
418
429
|
let index = start;
|
|
419
430
|
for (const value of iterable) {
|
|
420
431
|
yield [index++, value];
|
|
@@ -530,7 +541,7 @@ export {
|
|
|
530
541
|
count,
|
|
531
542
|
cycle,
|
|
532
543
|
dropwhile,
|
|
533
|
-
|
|
544
|
+
enumerate,
|
|
534
545
|
every,
|
|
535
546
|
filter,
|
|
536
547
|
find,
|
|
@@ -559,6 +570,7 @@ export {
|
|
|
559
570
|
permutations,
|
|
560
571
|
range,
|
|
561
572
|
reduce,
|
|
573
|
+
repeat,
|
|
562
574
|
roundrobin,
|
|
563
575
|
some,
|
|
564
576
|
sorted,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/more-itertools.ts","../src/itertools.ts","../src/builtins.ts","../src/custom.ts"],"sourcesContent":["import type { Primitive } from \"./types\";\n\ntype CmpFn<T> = (a: T, b: T) => number;\n\nexport function keyToCmp<T>(keyFn: (item: T) => Primitive): CmpFn<T> {\n return (a: T, b: T) => {\n const ka = keyFn(a);\n const kb = keyFn(b);\n // istanbul ignore else -- @preserve\n if (typeof ka === \"boolean\" && typeof kb === \"boolean\") {\n return ka === kb ? 0 : !ka && kb ? -1 : 1;\n } else if (typeof ka === \"number\" && typeof kb === \"number\") {\n return ka - kb;\n } else if (typeof ka === \"string\" && typeof kb === \"string\") {\n return ka === kb ? 0 : ka < kb ? -1 : 1;\n } else {\n return -1;\n }\n };\n}\n\nexport function identityPredicate(x: unknown): boolean {\n return !!x;\n}\n\nexport function numberIdentity(x: unknown): number {\n // istanbul ignore if -- @preserve\n if (typeof x !== \"number\") {\n throw new Error(\"Inputs must be numbers\");\n }\n return x;\n}\n\nexport function primitiveIdentity<P extends Primitive>(x: P): P;\nexport function primitiveIdentity(x: unknown): Primitive;\nexport function primitiveIdentity(x: unknown): Primitive {\n // istanbul ignore if -- @preserve\n if (typeof x !== \"string\" && typeof x !== \"number\" && typeof x !== \"boolean\") {\n throw new Error(\"Please provide a key function that can establish object identity\");\n }\n return x;\n}\n","import { iter, map } from \"./builtins\";\nimport { izip, repeat } from \"./itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { primitiveIdentity } from \"./utils\";\n\n/**\n * Break iterable into lists of length `size`:\n *\n * [...chunked([1, 2, 3, 4, 5, 6], 3)]\n * // [[1, 2, 3], [4, 5, 6]]\n *\n * If the length of iterable is not evenly divisible by `size`, the last returned\n * list will be shorter:\n *\n * [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]\n * // [[1, 2, 3], [4, 5, 6], [7, 8]]\n */\nexport function* chunked<T>(iterable: Iterable<T>, size: number): Iterable<T[]> {\n if (size < 1) {\n throw new Error(`Invalid chunk size: ${size}`);\n }\n\n const it = iter(iterable);\n for (;;) {\n const chunk = take(size, it);\n if (chunk.length > 0) {\n yield chunk;\n }\n if (chunk.length < size) {\n return;\n }\n }\n}\n\n/**\n * Return an iterator flattening one level of nesting in a list of lists:\n *\n * [...flatten([[0, 1], [2, 3]])]\n * // [0, 1, 2, 3]\n *\n */\nexport function* flatten<T>(iterableOfIterables: Iterable<Iterable<T>>): Iterable<T> {\n for (const iterable of iterableOfIterables) {\n for (const item of iterable) {\n yield item;\n }\n }\n}\n\n/**\n * Intersperse filler element `value` among the items in `iterable`.\n *\n * >>> [...intersperse(-1, range(1, 5))]\n * [1, -1, 2, -1, 3, -1, 4]\n *\n */\nexport function intersperse<T, V>(value: V, iterable: Iterable<T>): Iterable<T | V> {\n const stream = flatten(izip(repeat(value), iterable));\n take(1, stream); // eat away and discard the first value from the output\n return stream;\n}\n\n/**\n * Returns an iterable containing only the first `n` elements of the given\n * iterable.\n */\nexport function* itake<T>(n: number, iterable: Iterable<T>): Iterable<T> {\n const it = iter(iterable);\n let count = n;\n while (count-- > 0) {\n const s = it.next();\n if (!s.done) {\n yield s.value;\n } else {\n // Iterable exhausted, quit early\n return;\n }\n }\n}\n\n/**\n * Returns an iterator of paired items, overlapping, from the original. When\n * the input iterable has a finite number of items `n`, the outputted iterable\n * will have `n - 1` items.\n *\n * >>> pairwise([8, 2, 0, 7])\n * [(8, 2), (2, 0), (0, 7)]\n *\n */\nexport function* pairwise<T>(iterable: Iterable<T>): Iterable<[T, T]> {\n const it = iter(iterable);\n const first = it.next();\n if (first.done) {\n return;\n }\n\n let r1: T = first.value;\n for (const r2 of it) {\n yield [r1, r2];\n r1 = r2;\n }\n}\n\n/**\n * Returns a 2-tuple of arrays. Splits the elements in the input iterable into\n * either of the two arrays. Will fully exhaust the input iterable. The first\n * array contains all items that match the predicate, the second the rest:\n *\n * >>> const isOdd = x => x % 2 !== 0;\n * >>> const iterable = range(10);\n * >>> const [odds, evens] = partition(iterable, isOdd);\n * >>> odds\n * [1, 3, 5, 7, 9]\n * >>> evens\n * [0, 2, 4, 6, 8]\n *\n */\nexport function partition<T, N extends T>(\n iterable: Iterable<T>,\n predicate: (item: T) => item is N,\n): [N[], Exclude<T, N>[]];\nexport function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]];\nexport function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]] {\n const good = [];\n const bad = [];\n\n for (const item of iterable) {\n if (predicate(item)) {\n good.push(item);\n } else {\n bad.push(item);\n }\n }\n\n return [good, bad];\n}\n\n/**\n * Yields the next item from each iterable in turn, alternating between them.\n * Continues until all items are exhausted.\n *\n * >>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]\n * [1, 4, 5, 2, 6, 3, 7, 8]\n */\nexport function* roundrobin<T>(...iters: Iterable<T>[]): Iterable<T> {\n // We'll only keep lazy versions of the input iterables in here that we'll\n // slowly going to exhaust. Once an iterable is exhausted, it will be\n // removed from this list. Once the entire list is empty, this algorithm\n // ends.\n const iterables: Array<Iterator<T>> = map(iters, iter);\n\n while (iterables.length > 0) {\n let index = 0;\n while (index < iterables.length) {\n const it = iterables[index];\n const result = it.next();\n\n if (!result.done) {\n yield result.value;\n index++;\n } else {\n // This iterable is exhausted, make sure to remove it from the\n // list of iterables. We'll splice the array from under our\n // feet, and NOT advancing the index counter.\n iterables.splice(index, 1); // intentional side-effect!\n }\n }\n }\n}\n\n/**\n * Yields the heads of all of the given iterables. This is almost like\n * `roundrobin()`, except that the yielded outputs are grouped in to the\n * \"rounds\":\n *\n * >>> [...heads([1, 2, 3], [4], [5, 6, 7, 8])]\n * [[1, 4, 5], [2, 6], [3, 7], [8]]\n *\n * This is also different from `zipLongest()`, since the number of items in\n * each round can decrease over time, rather than being filled with a filler.\n */\nexport function* heads<T>(...iters: Array<Iterable<T>>): Iterable<T[]> {\n // We'll only keep lazy versions of the input iterables in here that we'll\n // slowly going to exhaust. Once an iterable is exhausted, it will be\n // removed from this list. Once the entire list is empty, this algorithm\n // ends.\n const iterables: Array<Iterator<T>> = map(iters, iter);\n\n while (iterables.length > 0) {\n let index = 0;\n const round = [];\n while (index < iterables.length) {\n const it = iterables[index];\n const result = it.next();\n\n if (!result.done) {\n round.push(result.value);\n index++;\n } else {\n // This iterable is exhausted, make sure to remove it from the\n // list of iterables. We'll splice the array from under our\n // feet, and NOT advancing the index counter.\n iterables.splice(index, 1); // intentional side-effect!\n }\n }\n if (round.length > 0) {\n yield round;\n }\n }\n}\n\n/**\n * Non-lazy version of itake().\n */\nexport function take<T>(n: number, iterable: Iterable<T>): T[] {\n return Array.from(itake(n, iterable));\n}\n\n/**\n * Yield unique elements, preserving order.\n *\n * >>> [...uniqueEverseen('AAAABBBCCDAABBB')]\n * ['A', 'B', 'C', 'D']\n * >>> [...uniqueEverseen('AbBCcAB', s => s.toLowerCase())]\n * ['A', 'b', 'C']\n *\n */\nexport function* uniqueEverseen<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n): Iterable<T> {\n const seen = new Set();\n for (const item of iterable) {\n const key = keyFn(item);\n if (!seen.has(key)) {\n seen.add(key);\n yield item;\n }\n }\n}\n\n/**\n * Yields elements in order, ignoring serial duplicates.\n *\n * >>> [...uniqueJustseen('AAAABBBCCDAABBB')]\n * ['A', 'B', 'C', 'D', 'A', 'B']\n * >>> [...uniqueJustseen('AbBCcAB', s => s.toLowerCase())]\n * ['A', 'b', 'C', 'A', 'B']\n *\n */\nexport function* uniqueJustseen<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n): Iterable<T> {\n let last = undefined;\n for (const item of iterable) {\n const key = keyFn(item);\n if (key !== last) {\n yield item;\n last = key;\n }\n }\n}\n","import { enumerate, every, iter, range } from \"./builtins\";\nimport { flatten } from \"./more-itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { primitiveIdentity } from \"./utils\";\n\nconst SENTINEL = Symbol();\n\n/**\n * Returns an iterator that returns elements from the first iterable until it\n * is exhausted, then proceeds to the next iterable, until all of the iterables\n * are exhausted. Used for treating consecutive sequences as a single\n * sequence.\n */\nexport function chain<T>(...iterables: Iterable<T>[]): Iterable<T> {\n return flatten(iterables);\n}\n\n/**\n * Returns an iterator that counts up values starting with number `start`\n * (default 0), incrementing by `step`. To decrement, use a negative step\n * number.\n */\nexport function* count(start = 0, step = 1): Iterable<number> {\n let n = start;\n for (;;) {\n yield n;\n n += step;\n }\n}\n\n/**\n * Non-lazy version of icompress().\n */\nexport function compress<T>(data: Iterable<T>, selectors: Iterable<boolean>): T[] {\n return Array.from(icompress(data, selectors));\n}\n\n/**\n * Returns an iterator producing elements from the iterable and saving a copy\n * of each. When the iterable is exhausted, return elements from the saved\n * copy. Repeats indefinitely.\n */\nexport function* cycle<T>(iterable: Iterable<T>): Iterable<T> {\n const saved = [];\n for (const element of iterable) {\n yield element;\n saved.push(element);\n }\n\n while (saved.length > 0) {\n for (const element of saved) {\n yield element;\n }\n }\n}\n\n/**\n * Returns an iterator that drops elements from the iterable as long as the\n * predicate is true; afterwards, returns every remaining element. Note, the\n * iterator does not produce any output until the predicate first becomes\n * false.\n */\nexport function* dropwhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T> {\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (!predicate(value)) {\n yield value;\n break; // we break, so we cannot use a for..of loop!\n }\n }\n\n for (const value of it) {\n yield value;\n }\n}\n\nexport function* groupby<T, K extends Primitive>(\n iterable: Iterable<T>,\n keyFn: (item: T) => K = primitiveIdentity,\n): Generator<[K, Generator<T, undefined>], undefined> {\n const it = iter(iterable);\n\n let currentValue: T;\n let currentKey: K = SENTINEL as unknown as K;\n // ^^^^^^^^^^^^^^^ Hack!\n let targetKey: K = currentKey;\n\n const grouper = function* grouper(tgtKey: K): Generator<T, undefined> {\n while (currentKey === tgtKey) {\n yield currentValue;\n\n const nextVal = it.next();\n if (nextVal.done) return;\n currentValue = nextVal.value;\n currentKey = keyFn(currentValue);\n }\n };\n\n for (;;) {\n while (currentKey === targetKey) {\n const nextVal = it.next();\n if (nextVal.done) {\n currentKey = SENTINEL as unknown as K;\n // ^^^^^^^^^^^^^^^ Hack!\n return;\n }\n currentValue = nextVal.value;\n currentKey = keyFn(currentValue);\n }\n\n targetKey = currentKey;\n yield [currentKey, grouper(targetKey)];\n }\n}\n\n/**\n * Returns an iterator that filters elements from data returning only those\n * that have a corresponding element in selectors that evaluates to `true`.\n * Stops when either the data or selectors iterables has been exhausted.\n */\nexport function* icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>): Iterable<T> {\n for (const [d, s] of izip(data, selectors)) {\n if (s) {\n yield d;\n }\n }\n}\n\n/**\n * Returns an iterator that filters elements from iterable returning only those\n * for which the predicate is true.\n */\nexport function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): Iterable<N>;\nexport function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T>;\nexport function* ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T> {\n for (const value of iterable) {\n if (predicate(value)) {\n yield value;\n }\n }\n}\n\n/**\n * Returns an iterator that computes the given mapper function using arguments\n * from each of the iterables.\n */\nexport function* imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): Iterable<V> {\n for (const value of iterable) {\n yield mapper(value);\n }\n}\n\n/**\n * Returns an iterator that returns selected elements from the iterable. If\n * `start` is non-zero, then elements from the iterable are skipped until start\n * is reached. Then, elements are returned by making steps of `step` (defaults\n * to 1). If set to higher than 1, items will be skipped. If `stop` is\n * provided, then iteration continues until the iterator reached that index,\n * otherwise, the iterable will be fully exhausted. `islice()` does not\n * support negative values for `start`, `stop`, or `step`.\n */\nexport function islice<T>(iterable: Iterable<T>, stop: number): Iterable<T>;\nexport function islice<T>(iterable: Iterable<T>, start: number, stop?: number | null, step?: number): Iterable<T>;\nexport function* islice<T>(\n iterable: Iterable<T>,\n stopOrStart: number,\n possiblyStop?: number | null,\n step = 1,\n): Iterable<T> {\n let start, stop;\n if (possiblyStop !== undefined) {\n // islice(iterable, start, stop[, step])\n start = stopOrStart;\n stop = possiblyStop;\n } else {\n // islice(iterable, stop)\n start = 0;\n stop = stopOrStart;\n }\n\n if (start < 0) throw new Error(\"start cannot be negative\");\n if (stop !== null && stop < 0) throw new Error(\"stop cannot be negative\");\n if (step <= 0) throw new Error(\"step cannot be negative\");\n\n let i = -1;\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (true) {\n i++;\n if (stop !== null && i >= stop) return; // early returns, so we cannot use a for..of loop!\n\n res = it.next();\n if (res.done) return;\n\n if (i < start) continue;\n if ((i - start) % step === 0) {\n yield res.value;\n }\n }\n}\n\n/**\n * Returns an iterator that aggregates elements from each of the iterables.\n * Used for lock-step iteration over several iterables at a time. When\n * iterating over two iterables, use `izip2`. When iterating over three\n * iterables, use `izip3`, etc. `izip` is an alias for `izip2`.\n */\nexport function* izip2<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): Iterable<[T1, T2]> {\n const ixs = iter(xs);\n const iys = iter(ys);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n if (!x.done && !y.done) {\n yield [x.value, y.value];\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\n/**\n * Like izip2, but for three input iterables.\n */\nexport function* izip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): Iterable<[T1, T2, T3]> {\n const ixs = iter(xs);\n const iys = iter(ys);\n const izs = iter(zs);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n const z = izs.next();\n if (!x.done && !y.done && !z.done) {\n yield [x.value, y.value, z.value];\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\nexport const izip = izip2;\n\n/**\n * Returns an iterator that aggregates elements from each of the iterables. If\n * the iterables are of uneven length, missing values are filled-in with\n * fillvalue. Iteration continues until the longest iterable is exhausted.\n */\nexport function* izipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): Iterable<[T1 | D, T2 | D]> {\n const filler_ = filler as D;\n const ixs = iter(xs);\n const iys = iter(ys);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n if (x.done && y.done) {\n // All iterables exhausted\n return;\n } else {\n yield [!x.done ? x.value : filler_, !y.done ? y.value : filler_];\n }\n }\n}\n\n/**\n * See izipLongest2, but for three.\n */\nexport function* izipLongest3<T1, T2, T3, D = undefined>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n filler?: D,\n): Iterable<[T1 | D, T2 | D, T3 | D]> {\n const filler_ = filler as D;\n const ixs = iter(xs);\n const iys = iter(ys);\n const izs = iter(zs);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n const z = izs.next();\n if (x.done && y.done && z.done) {\n // All iterables exhausted\n return;\n } else {\n yield [!x.done ? x.value : filler_, !y.done ? y.value : filler_, !z.done ? z.value : filler_];\n }\n }\n}\n\n/**\n * Like the other izips (`izip`, `izip3`, etc), but generalized to take an\n * unlimited amount of input iterables. Think `izip(*iterables)` in Python.\n *\n * **Note:** Due to Flow type system limitations, you can only \"generially\" zip\n * iterables with homogeneous types, so you cannot mix types like <A, B> like\n * you can with izip2().\n */\nexport function* izipMany<T>(...iters: Iterable<T>[]): Iterable<T[]> {\n // Make them all iterables\n const iterables = iters.map(iter);\n\n for (;;) {\n const heads: Array<IteratorResult<T, undefined>> = iterables.map((xs) => xs.next());\n if (every(heads, (h) => !h.done)) {\n yield heads.map((h) => h.value as T);\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\n/**\n * Return successive `r`-length permutations of elements in the iterable.\n *\n * If `r` is not specified, then `r` defaults to the length of the iterable and\n * all possible full-length permutations are generated.\n *\n * Permutations are emitted in lexicographic sort order. So, if the input\n * iterable is sorted, the permutation tuples will be produced in sorted order.\n *\n * Elements are treated as unique based on their position, not on their value.\n * So if the input elements are unique, there will be no repeat values in each\n * permutation.\n */\nexport function* permutations<T>(iterable: Iterable<T>, r?: number): Iterable<T[]> {\n const pool = Array.from(iterable);\n const n = pool.length;\n const x = r === undefined ? n : r;\n\n if (x > n) {\n return;\n }\n\n let indices: number[] = Array.from(range(n));\n const cycles: number[] = Array.from(range(n, n - x, -1));\n const poolgetter = (i: number) => pool[i];\n\n yield indices.slice(0, x).map(poolgetter);\n\n while (n > 0) {\n let cleanExit = true;\n for (const i of range(x - 1, -1, -1)) {\n cycles[i] -= 1;\n if (cycles[i] === 0) {\n indices = indices\n .slice(0, i)\n .concat(indices.slice(i + 1))\n .concat(indices.slice(i, i + 1));\n cycles[i] = n - i;\n } else {\n const j: number = cycles[i];\n\n const [p, q] = [indices[indices.length - j], indices[i]];\n indices[i] = p;\n indices[indices.length - j] = q;\n yield indices.slice(0, x).map(poolgetter);\n cleanExit = false;\n break;\n }\n }\n\n if (cleanExit) {\n return;\n }\n }\n}\n\n/**\n * Returns an iterator that produces values over and over again. Runs\n * indefinitely unless the times argument is specified.\n */\nexport function* repeat<T>(thing: T, times?: number): Iterable<T> {\n if (times === undefined) {\n for (;;) {\n yield thing;\n }\n } else {\n for (const _ of range(times)) {\n yield thing;\n }\n }\n}\n\n/**\n * Returns an iterator that produces elements from the iterable as long as the\n * predicate is true.\n */\nexport function* takewhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T> {\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (!predicate(value)) return; // early return, so we cannot use for..of loop!\n yield value;\n }\n}\n\nexport function zipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): Array<[T1 | D, T2 | D]> {\n return Array.from(izipLongest2(xs, ys, filler));\n}\n\nexport function zipLongest3<T1, T2, T3, D>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n filler?: D,\n): Array<[T1 | D, T2 | D, T3 | D]> {\n return Array.from(izipLongest3(xs, ys, zs, filler));\n}\n\nexport const izipLongest = izipLongest2;\nexport const zipLongest = zipLongest2;\n\nexport function zipMany<T>(...iters: Iterable<T>[]): T[][] {\n return Array.from(izipMany(...iters));\n}\n","import { count, ifilter, imap, izip, izip3, takewhile } from \"./itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { identityPredicate, keyToCmp, numberIdentity, primitiveIdentity } from \"./utils\";\n\n/**\n * Returns the first item in the iterable for which the predicate holds, if\n * any. If no predicate is given, it will return the first value returned by\n * the iterable.\n */\nexport function find<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n const it = iter(iterable);\n if (keyFn === undefined) {\n const value = it.next();\n return value.done ? value.value : value.value;\n } else {\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (keyFn(value)) {\n return value;\n }\n }\n return undefined;\n }\n}\n\n/**\n * Returns true when all of the items in iterable are truthy. An optional key\n * function can be used to define what truthiness means for this specific\n * collection.\n *\n * Examples:\n *\n * all([]) // => true\n * all([0]) // => false\n * all([0, 1, 2]) // => false\n * all([1, 2, 3]) // => true\n *\n * Examples with using a key function:\n *\n * all([2, 4, 6], n => n % 2 === 0) // => true\n * all([2, 4, 5], n => n % 2 === 0) // => false\n *\n */\nexport function every<T>(iterable: Iterable<T>, keyFn: Predicate<T> = identityPredicate): boolean {\n for (const item of iterable) {\n if (!keyFn(item)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Returns true when some of the items in iterable are truthy. An optional key\n * function can be used to define what truthiness means for this specific\n * collection.\n *\n * Examples:\n *\n * some([]) // => false\n * some([0]) // => false\n * some([0, 1, null, undefined]) // => true\n *\n * Examples with using a key function:\n *\n * some([1, 4, 5], n => n % 2 === 0) // => true\n * some([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false\n *\n */\nexport function some<T>(iterable: Iterable<T>, keyFn: Predicate<T> = identityPredicate): boolean {\n for (const item of iterable) {\n if (keyFn(item)) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Alias of `every()`.\n */\nexport const all = every;\n\n/**\n * Alias of `some()`.\n */\nexport const any = some;\n\n/**\n * Returns true when any of the items in the iterable are equal to the target object.\n *\n * Examples:\n *\n * contains([], 'whatever') // => false\n * contains([3], 42) // => false\n * contains([3], 3) // => true\n * contains([0, 1, 2], 2) // => true\n *\n */\nexport function contains<T>(haystack: Iterable<T>, needle: T): boolean {\n return some(haystack, (x) => x === needle);\n}\n\n/**\n * Returns an iterable of enumeration pairs. Iterable must be a sequence, an\n * iterator, or some other object which supports iteration. The elements\n * produced by returns a tuple containing a counter value (starting from 0 by\n * default) and the values obtained from iterating over given iterable.\n *\n * Example:\n *\n * import { enumerate } from 'itertools';\n *\n * console.log([...enumerate(['hello', 'world'])]);\n * // [0, 'hello'], [1, 'world']]\n */\nexport function* enumerate<T>(iterable: Iterable<T>, start = 0): Iterable<[number, T]> {\n let index: number = start;\n for (const value of iterable) {\n yield [index++, value];\n }\n}\n\n/**\n * Non-lazy version of ifilter().\n */\nexport function filter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): N[];\nexport function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[];\nexport function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[] {\n return Array.from(ifilter(iterable, predicate));\n}\n\n/**\n * Returns an iterator object for the given iterable. This can be used to\n * manually get an iterator for any iterable datastructure. The purpose and\n * main use case of this function is to get a single iterator (a thing with\n * state, think of it as a \"cursor\") which can only be consumed once.\n */\nexport function iter<T>(iterable: Iterable<T>): IterableIterator<T> {\n // class SelfIter implements IterableIterator<T> {\n // #iterator: Iterator<T>;\n // constructor(orig: Iterable<T>) {\n // this.#iterator = orig[Symbol.iterator]();\n // }\n // [Symbol.iterator]() {\n // return this;\n // }\n // next() {\n // return this.#iterator.next();\n // }\n // }\n // return new SelfIter(iterable);\n\n return iterable[Symbol.iterator]() as IterableIterator<T>;\n // ^^^^^^^^^^^^^^^^^^^^^^ Not safe!\n}\n\n/**\n * Non-lazy version of imap().\n */\nexport function map<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): V[] {\n return Array.from(imap(iterable, mapper));\n}\n\n/**\n * Return the largest item in an iterable. Only works for numbers, as ordering\n * is pretty poorly defined on any other data type in JS. The optional `keyFn`\n * argument specifies a one-argument ordering function like that used for\n * sorted().\n *\n * If the iterable is empty, `undefined` is returned.\n *\n * If multiple items are maximal, the function returns either one of them, but\n * which one is not defined.\n */\nexport function max<T>(iterable: Iterable<T>, keyFn: (item: T) => number = numberIdentity): T | undefined {\n return reduce2(iterable, (x, y) => (keyFn(x) > keyFn(y) ? x : y));\n}\n\n/**\n * Return the smallest item in an iterable. Only works for numbers, as\n * ordering is pretty poorly defined on any other data type in JS. The\n * optional `keyFn` argument specifies a one-argument ordering function like\n * that used for sorted().\n *\n * If the iterable is empty, `undefined` is returned.\n *\n * If multiple items are minimal, the function returns either one of them, but\n * which one is not defined.\n */\nexport function min<T>(iterable: Iterable<T>, keyFn: (item: T) => number = numberIdentity): T | undefined {\n return reduce2(iterable, (x, y) => (keyFn(x) < keyFn(y) ? x : y));\n}\n\n/**\n * Internal helper for the range function\n */\nfunction range_(start: number, stop: number, step: number): Iterable<number> {\n const counter = count(start, step);\n const pred = step >= 0 ? (n: number) => n < stop : (n: number) => n > stop;\n return takewhile(counter, pred);\n}\n\n/**\n * Returns an iterator producing all the numbers in the given range one by one,\n * starting from `start` (default 0), as long as `i < stop`, in increments of\n * `step` (default 1).\n *\n * `range(a)` is a convenient shorthand for `range(0, a)`.\n *\n * Various valid invocations:\n *\n * range(5) // [0, 1, 2, 3, 4]\n * range(2, 5) // [2, 3, 4]\n * range(0, 5, 2) // [0, 2, 4]\n * range(5, 0, -1) // [5, 4, 3, 2, 1]\n * range(-3) // []\n *\n * For a positive `step`, the iterator will keep producing values `n` as long\n * as the stop condition `n < stop` is satisfied.\n *\n * For a negative `step`, the iterator will keep producing values `n` as long\n * as the stop condition `n > stop` is satisfied.\n *\n * The produced range will be empty if the first value to produce already does\n * not meet the value constraint.\n */\n\nexport function range(stop: number): Iterable<number>;\nexport function range(start: number, stop: number, step?: number): Iterable<number>;\nexport function range(startOrStop: number, definitelyStop?: number, step = 1): Iterable<number> {\n if (definitelyStop !== undefined) {\n return range_(startOrStop /* as start */, definitelyStop, step);\n } else {\n return range_(0, startOrStop /* as stop */, step);\n }\n}\n\n/**\n * Apply function of two arguments cumulatively to the items of sequence, from\n * left to right, so as to reduce the sequence to a single value. For example:\n *\n * reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)\n *\n * calculates\n *\n * (((((0+1)+2)+3)+4)+5)\n *\n * The left argument, `x`, is the accumulated value and the right argument,\n * `y`, is the update value from the sequence.\n *\n * **Difference between `reduce()` and `reduce\\_()`**: `reduce()` requires an\n * explicit initializer, whereas `reduce_()` will automatically use the first\n * item in the given iterable as the initializer. When using `reduce()`, the\n * initializer value is placed before the items of the sequence in the\n * calculation, and serves as a default when the sequence is empty. When using\n * `reduce_()`, and the given iterable is empty, then no default value can be\n * derived and `undefined` will be returned.\n */\nexport function reduce<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined;\nexport function reduce<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O;\nexport function reduce<T, O>(\n iterable: Iterable<T>,\n reducer: ((agg: T, item: T, index: number) => T) | ((agg: O, item: T, index: number) => O),\n start?: O,\n): O | (T | undefined) {\n if (start === undefined) {\n return reduce2(iterable, reducer as (agg: T, item: T, index: number) => T);\n } else {\n return reduce3(iterable, reducer as (agg: O, item: T, index: number) => O, start);\n }\n}\n\nfunction reduce3<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O {\n let output = start;\n let index = 0;\n for (const item of iterable) {\n output = reducer(output, item, index++);\n }\n return output;\n}\n\nfunction reduce2<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined {\n const it = iter(iterable);\n const start = find(it);\n if (start === undefined) {\n return undefined;\n } else {\n return reduce3(it, reducer, start);\n }\n}\n\n/**\n * Return a new sorted list from the items in iterable.\n *\n * Has two optional arguments:\n *\n * * `keyFn` specifies a function of one argument providing a primitive\n * identity for each element in the iterable. that will be used to compare.\n * The default value is to use a default identity function that is only\n * defined for primitive types.\n *\n * * `reverse` is a boolean value. If `true`, then the list elements are\n * sorted as if each comparison were reversed.\n */\nexport function sorted<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n reverse = false,\n): T[] {\n const result = Array.from(iterable);\n result.sort(keyToCmp(keyFn)); // sort in-place\n\n if (reverse) {\n result.reverse(); // reverse in-place\n }\n\n return result;\n}\n\n/**\n * Sums the items of an iterable from left to right and returns the total. The\n * sum will defaults to 0 if the iterable is empty.\n */\nexport function sum(iterable: Iterable<number>): number {\n return reduce(iterable, (x, y) => x + y, 0);\n}\n\n/**\n * See izip.\n */\nexport function zip<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): Array<[T1, T2]> {\n return Array.from(izip(xs, ys));\n}\n\n/**\n * See izip3.\n */\nexport function zip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): Array<[T1, T2, T3]> {\n return Array.from(izip3(xs, ys, zs));\n}\n","import { find } from \"./builtins\";\nimport { ifilter, imap } from \"./itertools\";\nimport { flatten } from \"./more-itertools\";\nimport type { Predicate } from \"./types\";\n\nfunction isNullish<T>(x: T): x is NonNullable<T> {\n return x != null;\n}\n\nfunction isDefined<T>(x: T): boolean {\n return x !== undefined;\n}\n\n/**\n * Returns an iterable, filtering out any \"nullish\" values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3, null])\n * [1, 2, 3]\n *\n * For an eager version, @see compact().\n */\nexport function icompact<T>(iterable: Iterable<T | null | undefined>): Iterable<T> {\n return ifilter(iterable, isNullish);\n}\n\n/**\n * Returns an array, filtering out any \"nullish\" values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3, null])\n * [1, 2, 3]\n *\n * For a lazy version, @see icompact().\n */\nexport function compact<T>(iterable: Iterable<T | null | undefined>): T[] {\n return Array.from(icompact(iterable));\n}\n\n/**\n * Removes all \"nullish\" values from the given object. Returns a new object.\n *\n * >>> compactObject({ a: 1, b: undefined, c: 0, d: null })\n * { a: 1, c: 0 }\n *\n */\nexport function compactObject<K extends string, V>(obj: Record<K, V | null | undefined>): Record<K, V> {\n const result = {} as Record<K, V>;\n for (const [key, value_] of Object.entries(obj)) {\n const value = value_ as V | null | undefined;\n if (value != null) {\n result[key as K] = value;\n }\n }\n return result;\n}\n\n/**\n * Almost an alias of find(). There only is a difference if no key fn is\n * provided. In that case, `find()` will return the first item in the iterable,\n * whereas `first()` will return the first non-`undefined` value in the\n * iterable.\n */\nexport function first<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n return find(iterable, keyFn ?? isDefined);\n}\n\n/**\n * Returns 0 or more values for every value in the given iterable.\n * Technically, it's just calling map(), followed by flatten(), but it's a very\n * useful operation if you want to map over a structure, but not have a 1:1\n * input-output mapping. Instead, if you want to potentially return 0 or more\n * values per input element, use flatmap():\n *\n * For example, to return all numbers `n` in the input iterable `n` times:\n *\n * >>> const repeatN = n => repeat(n, n);\n * >>> [...flatmap([0, 1, 2, 3, 4], repeatN)]\n * [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0\n *\n */\nexport function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>): Iterable<S> {\n return flatten(imap(iterable, mapper));\n}\n"],"mappings":";AAIO,SAAS,SAAY,OAAyC;AACnE,SAAO,CAAC,GAAM,MAAS;AACrB,UAAM,KAAK,MAAM,CAAC;AAClB,UAAM,KAAK,MAAM,CAAC;AAElB,QAAI,OAAO,OAAO,aAAa,OAAO,OAAO,WAAW;AACtD,aAAO,OAAO,KAAK,IAAI,CAAC,MAAM,KAAK,KAAK;AAAA,IAC1C,WAAW,OAAO,OAAO,YAAY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UAAa,GAAe;AACnC,SAAO,MAAM;AACf;AAUO,SAAS,SAAY,UAAuD;AACjF,SAAO,QAAQ,UAAU,SAAS;AACpC;AAUO,SAAS,QAAW,UAA+C;AACxE,SAAO,MAAM,KAAK,SAAS,QAAQ,CAAC;AACtC;AASO,SAAS,cAAmC,KAAoD;AACrG,QAAM,SAAS,CAAC;AAChB,aAAW,CAAC,KAAK,MAAM,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC/C,UAAM,QAAQ;AACd,QAAI,SAAS,MAAM;AACjB,aAAO,GAAQ,IAAI;AAAA,IACrB;AAAA,EACF;AACA,SAAO;AACT;AAQO,SAAS,MAAS,UAAuB,OAAqC;AACnF,SAAO,KAAK,UAAU,wBAAS,SAAS;AAC1C;AAgBO,SAAS,QAAc,UAAuB,QAA+C;AAClG,SAAO,QAAQ,KAAK,UAAU,MAAM,CAAC;AACvC;","names":["count","first","grouper","heads","enumerate"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/more-itertools.ts","../src/itertools.ts","../src/builtins.ts","../src/custom.ts"],"sourcesContent":["import type { Primitive } from \"./types\";\n\ntype CmpFn<T> = (a: T, b: T) => number;\n\nexport function keyToCmp<T>(keyFn: (item: T) => Primitive): CmpFn<T> {\n return (a: T, b: T) => {\n const ka = keyFn(a);\n const kb = keyFn(b);\n // istanbul ignore else -- @preserve\n if (typeof ka === \"boolean\" && typeof kb === \"boolean\") {\n return ka === kb ? 0 : !ka && kb ? -1 : 1;\n } else if (typeof ka === \"number\" && typeof kb === \"number\") {\n return ka - kb;\n } else if (typeof ka === \"string\" && typeof kb === \"string\") {\n return ka === kb ? 0 : ka < kb ? -1 : 1;\n } else {\n return -1;\n }\n };\n}\n\nexport function identityPredicate(x: unknown): boolean {\n return !!x;\n}\n\nexport function numberIdentity(x: unknown): number {\n // istanbul ignore if -- @preserve\n if (typeof x !== \"number\") {\n throw new Error(\"Inputs must be numbers\");\n }\n return x;\n}\n\nexport function primitiveIdentity<P extends Primitive>(x: P): P;\nexport function primitiveIdentity(x: unknown): Primitive;\nexport function primitiveIdentity(x: unknown): Primitive {\n // istanbul ignore if -- @preserve\n if (typeof x !== \"string\" && typeof x !== \"number\" && typeof x !== \"boolean\") {\n throw new Error(\"Please provide a key function that can establish object identity\");\n }\n return x;\n}\n","import { iter, map } from \"./builtins\";\nimport { izip, repeat } from \"./itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { primitiveIdentity } from \"./utils\";\n\n/**\n * Break iterable into lists of length `size`:\n *\n * [...chunked([1, 2, 3, 4, 5, 6], 3)]\n * // [[1, 2, 3], [4, 5, 6]]\n *\n * If the length of iterable is not evenly divisible by `size`, the last returned\n * list will be shorter:\n *\n * [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]\n * // [[1, 2, 3], [4, 5, 6], [7, 8]]\n */\nexport function* chunked<T>(iterable: Iterable<T>, size: number): IterableIterator<T[]> {\n if (size < 1) {\n throw new Error(`Invalid chunk size: ${size}`);\n }\n\n const it = iter(iterable);\n for (;;) {\n const chunk = take(size, it);\n if (chunk.length > 0) {\n yield chunk;\n }\n if (chunk.length < size) {\n return;\n }\n }\n}\n\n/**\n * Return an iterator flattening one level of nesting in a list of lists:\n *\n * [...flatten([[0, 1], [2, 3]])]\n * // [0, 1, 2, 3]\n *\n */\nexport function* flatten<T>(iterableOfIterables: Iterable<Iterable<T>>): IterableIterator<T> {\n for (const iterable of iterableOfIterables) {\n for (const item of iterable) {\n yield item;\n }\n }\n}\n\n/**\n * Intersperse filler element `value` among the items in `iterable`.\n *\n * >>> [...intersperse(-1, range(1, 5))]\n * [1, -1, 2, -1, 3, -1, 4]\n *\n */\nexport function intersperse<T, V>(value: V, iterable: Iterable<T>): IterableIterator<T | V> {\n const stream = flatten<T | V>(izip(repeat(value), iterable));\n stream.next(); // eat away and discard the first value from the output\n return stream;\n}\n\n/**\n * Returns an iterable containing only the first `n` elements of the given\n * iterable.\n */\nexport function* itake<T>(n: number, iterable: Iterable<T>): IterableIterator<T> {\n const it = iter(iterable);\n let count = n;\n while (count-- > 0) {\n const s = it.next();\n if (!s.done) {\n yield s.value;\n } else {\n // Iterable exhausted, quit early\n return;\n }\n }\n}\n\n/**\n * Returns an iterator of paired items, overlapping, from the original. When\n * the input iterable has a finite number of items `n`, the outputted iterable\n * will have `n - 1` items.\n *\n * >>> pairwise([8, 2, 0, 7])\n * [(8, 2), (2, 0), (0, 7)]\n *\n */\nexport function* pairwise<T>(iterable: Iterable<T>): IterableIterator<[T, T]> {\n const it = iter(iterable);\n const first = it.next();\n if (first.done) {\n return;\n }\n\n let r1: T = first.value;\n for (const r2 of it) {\n yield [r1, r2];\n r1 = r2;\n }\n}\n\n/**\n * Returns a 2-tuple of arrays. Splits the elements in the input iterable into\n * either of the two arrays. Will fully exhaust the input iterable. The first\n * array contains all items that match the predicate, the second the rest:\n *\n * >>> const isOdd = x => x % 2 !== 0;\n * >>> const iterable = range(10);\n * >>> const [odds, evens] = partition(iterable, isOdd);\n * >>> odds\n * [1, 3, 5, 7, 9]\n * >>> evens\n * [0, 2, 4, 6, 8]\n *\n */\nexport function partition<T, N extends T>(\n iterable: Iterable<T>,\n predicate: (item: T) => item is N,\n): [N[], Exclude<T, N>[]];\nexport function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]];\nexport function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]] {\n const good = [];\n const bad = [];\n\n for (const item of iterable) {\n if (predicate(item)) {\n good.push(item);\n } else {\n bad.push(item);\n }\n }\n\n return [good, bad];\n}\n\n/**\n * Yields the next item from each iterable in turn, alternating between them.\n * Continues until all items are exhausted.\n *\n * >>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]\n * [1, 4, 5, 2, 6, 3, 7, 8]\n */\nexport function* roundrobin<T>(...iters: Iterable<T>[]): IterableIterator<T> {\n // We'll only keep lazy versions of the input iterables in here that we'll\n // slowly going to exhaust. Once an iterable is exhausted, it will be\n // removed from this list. Once the entire list is empty, this algorithm\n // ends.\n const iterables: Array<Iterator<T>> = map(iters, iter);\n\n while (iterables.length > 0) {\n let index = 0;\n while (index < iterables.length) {\n const it = iterables[index];\n const result = it.next();\n\n if (!result.done) {\n yield result.value;\n index++;\n } else {\n // This iterable is exhausted, make sure to remove it from the\n // list of iterables. We'll splice the array from under our\n // feet, and NOT advancing the index counter.\n iterables.splice(index, 1); // intentional side-effect!\n }\n }\n }\n}\n\n/**\n * Yields the heads of all of the given iterables. This is almost like\n * `roundrobin()`, except that the yielded outputs are grouped in to the\n * \"rounds\":\n *\n * >>> [...heads([1, 2, 3], [4], [5, 6, 7, 8])]\n * [[1, 4, 5], [2, 6], [3, 7], [8]]\n *\n * This is also different from `zipLongest()`, since the number of items in\n * each round can decrease over time, rather than being filled with a filler.\n */\nexport function* heads<T>(...iters: Array<Iterable<T>>): IterableIterator<T[]> {\n // We'll only keep lazy versions of the input iterables in here that we'll\n // slowly going to exhaust. Once an iterable is exhausted, it will be\n // removed from this list. Once the entire list is empty, this algorithm\n // ends.\n const iterables: Array<Iterator<T>> = map(iters, iter);\n\n while (iterables.length > 0) {\n let index = 0;\n const round = [];\n while (index < iterables.length) {\n const it = iterables[index];\n const result = it.next();\n\n if (!result.done) {\n round.push(result.value);\n index++;\n } else {\n // This iterable is exhausted, make sure to remove it from the\n // list of iterables. We'll splice the array from under our\n // feet, and NOT advancing the index counter.\n iterables.splice(index, 1); // intentional side-effect!\n }\n }\n if (round.length > 0) {\n yield round;\n }\n }\n}\n\n/**\n * Non-lazy version of itake().\n */\nexport function take<T>(n: number, iterable: Iterable<T>): T[] {\n return Array.from(itake(n, iterable));\n}\n\n/**\n * Yield unique elements, preserving order.\n *\n * >>> [...uniqueEverseen('AAAABBBCCDAABBB')]\n * ['A', 'B', 'C', 'D']\n * >>> [...uniqueEverseen('AbBCcAB', s => s.toLowerCase())]\n * ['A', 'b', 'C']\n *\n */\nexport function* uniqueEverseen<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n): IterableIterator<T> {\n const seen = new Set();\n for (const item of iterable) {\n const key = keyFn(item);\n if (!seen.has(key)) {\n seen.add(key);\n yield item;\n }\n }\n}\n\n/**\n * Yields elements in order, ignoring serial duplicates.\n *\n * >>> [...uniqueJustseen('AAAABBBCCDAABBB')]\n * ['A', 'B', 'C', 'D', 'A', 'B']\n * >>> [...uniqueJustseen('AbBCcAB', s => s.toLowerCase())]\n * ['A', 'b', 'C', 'A', 'B']\n *\n */\nexport function* uniqueJustseen<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n): IterableIterator<T> {\n let last = undefined;\n for (const item of iterable) {\n const key = keyFn(item);\n if (key !== last) {\n yield item;\n last = key;\n }\n }\n}\n","import { every, iter, range } from \"./builtins\";\nimport { flatten } from \"./more-itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { primitiveIdentity } from \"./utils\";\n\nconst SENTINEL = Symbol();\n\n/**\n * Returns an iterator that returns elements from the first iterable until it\n * is exhausted, then proceeds to the next iterable, until all of the iterables\n * are exhausted. Used for treating consecutive sequences as a single\n * sequence.\n */\nexport function chain<T>(...iterables: Iterable<T>[]): IterableIterator<T> {\n return flatten(iterables);\n}\n\n/**\n * Returns an iterator that counts up values starting with number `start`\n * (default 0), incrementing by `step`. To decrement, use a negative step\n * number.\n */\nexport function* count(start = 0, step = 1): IterableIterator<number> {\n let n = start;\n for (;;) {\n yield n;\n n += step;\n }\n}\n\n/**\n * Non-lazy version of icompress().\n */\nexport function compress<T>(data: Iterable<T>, selectors: Iterable<boolean>): T[] {\n return Array.from(icompress(data, selectors));\n}\n\n/**\n * Returns an iterator producing elements from the iterable and saving a copy\n * of each. When the iterable is exhausted, return elements from the saved\n * copy. Repeats indefinitely.\n */\nexport function* cycle<T>(iterable: Iterable<T>): IterableIterator<T> {\n const saved = [];\n for (const element of iterable) {\n yield element;\n saved.push(element);\n }\n\n while (saved.length > 0) {\n for (const element of saved) {\n yield element;\n }\n }\n}\n\n/**\n * Returns an iterator that drops elements from the iterable as long as the\n * predicate is true; afterwards, returns every remaining element. Note, the\n * iterator does not produce any output until the predicate first becomes\n * false.\n */\nexport function* dropwhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T> {\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (!predicate(value)) {\n yield value;\n break; // we break, so we cannot use a for..of loop!\n }\n }\n\n for (const value of it) {\n yield value;\n }\n}\n\nexport function* groupby<T, K extends Primitive>(\n iterable: Iterable<T>,\n keyFn: (item: T) => K = primitiveIdentity,\n): Generator<[K, Generator<T, undefined>], undefined> {\n const it = iter(iterable);\n\n let currentValue: T;\n let currentKey: K = SENTINEL as unknown as K;\n // ^^^^^^^^^^^^^^^ Hack!\n let targetKey: K = currentKey;\n\n const grouper = function* grouper(tgtKey: K): Generator<T, undefined> {\n while (currentKey === tgtKey) {\n yield currentValue;\n\n const nextVal = it.next();\n if (nextVal.done) return;\n currentValue = nextVal.value;\n currentKey = keyFn(currentValue);\n }\n };\n\n for (;;) {\n while (currentKey === targetKey) {\n const nextVal = it.next();\n if (nextVal.done) {\n currentKey = SENTINEL as unknown as K;\n // ^^^^^^^^^^^^^^^ Hack!\n return;\n }\n currentValue = nextVal.value;\n currentKey = keyFn(currentValue);\n }\n\n targetKey = currentKey;\n yield [currentKey, grouper(targetKey)];\n }\n}\n\n/**\n * Returns an iterator that filters elements from data returning only those\n * that have a corresponding element in selectors that evaluates to `true`.\n * Stops when either the data or selectors iterables has been exhausted.\n */\nexport function* icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>): IterableIterator<T> {\n for (const [d, s] of izip(data, selectors)) {\n if (s) {\n yield d;\n }\n }\n}\n\n/**\n * Returns an iterator that filters elements from iterable returning only those\n * for which the predicate is true.\n */\nexport function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): IterableIterator<N>;\nexport function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T>;\nexport function* ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T> {\n for (const value of iterable) {\n if (predicate(value)) {\n yield value;\n }\n }\n}\n\n/**\n * Returns an iterator that computes the given mapper function using arguments\n * from each of the iterables.\n */\nexport function* imap<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): IterableIterator<V> {\n for (const value of iterable) {\n yield mapper(value);\n }\n}\n\n/**\n * Returns an iterator that returns selected elements from the iterable. If\n * `start` is non-zero, then elements from the iterable are skipped until start\n * is reached. Then, elements are returned by making steps of `step` (defaults\n * to 1). If set to higher than 1, items will be skipped. If `stop` is\n * provided, then iteration continues until the iterator reached that index,\n * otherwise, the iterable will be fully exhausted. `islice()` does not\n * support negative values for `start`, `stop`, or `step`.\n */\nexport function islice<T>(iterable: Iterable<T>, stop: number): IterableIterator<T>;\nexport function islice<T>(\n iterable: Iterable<T>,\n start: number,\n stop?: number | null,\n step?: number,\n): IterableIterator<T>;\nexport function* islice<T>(\n iterable: Iterable<T>,\n stopOrStart: number,\n possiblyStop?: number | null,\n step = 1,\n): IterableIterator<T> {\n let start, stop;\n if (possiblyStop !== undefined) {\n // islice(iterable, start, stop[, step])\n start = stopOrStart;\n stop = possiblyStop;\n } else {\n // islice(iterable, stop)\n start = 0;\n stop = stopOrStart;\n }\n\n if (start < 0) throw new Error(\"start cannot be negative\");\n if (stop !== null && stop < 0) throw new Error(\"stop cannot be negative\");\n if (step <= 0) throw new Error(\"step cannot be negative\");\n\n let i = -1;\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (true) {\n i++;\n if (stop !== null && i >= stop) return; // early returns, so we cannot use a for..of loop!\n\n res = it.next();\n if (res.done) return;\n\n if (i < start) continue;\n if ((i - start) % step === 0) {\n yield res.value;\n }\n }\n}\n\n/**\n * Returns an iterator that aggregates elements from each of the iterables.\n * Used for lock-step iteration over several iterables at a time. When\n * iterating over two iterables, use `izip2`. When iterating over three\n * iterables, use `izip3`, etc. `izip` is an alias for `izip2`.\n */\nexport function* izip<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): IterableIterator<[T1, T2]> {\n const ixs = iter(xs);\n const iys = iter(ys);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n if (!x.done && !y.done) {\n yield [x.value, y.value];\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\n/**\n * Like izip2, but for three input iterables.\n */\nexport function* izip3<T1, T2, T3>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n): IterableIterator<[T1, T2, T3]> {\n const ixs = iter(xs);\n const iys = iter(ys);\n const izs = iter(zs);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n const z = izs.next();\n if (!x.done && !y.done && !z.done) {\n yield [x.value, y.value, z.value];\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\nexport const izip2 = izip;\n\n/**\n * Returns an iterator that aggregates elements from each of the iterables. If\n * the iterables are of uneven length, missing values are filled-in with\n * fillvalue. Iteration continues until the longest iterable is exhausted.\n */\nexport function* izipLongest2<T1, T2, D>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n filler?: D,\n): IterableIterator<[T1 | D, T2 | D]> {\n const filler_ = filler as D;\n const ixs = iter(xs);\n const iys = iter(ys);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n if (x.done && y.done) {\n // All iterables exhausted\n return;\n } else {\n yield [!x.done ? x.value : filler_, !y.done ? y.value : filler_];\n }\n }\n}\n\n/**\n * See izipLongest2, but for three.\n */\nexport function* izipLongest3<T1, T2, T3, D = undefined>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n filler?: D,\n): IterableIterator<[T1 | D, T2 | D, T3 | D]> {\n const filler_ = filler as D;\n const ixs = iter(xs);\n const iys = iter(ys);\n const izs = iter(zs);\n for (;;) {\n const x = ixs.next();\n const y = iys.next();\n const z = izs.next();\n if (x.done && y.done && z.done) {\n // All iterables exhausted\n return;\n } else {\n yield [!x.done ? x.value : filler_, !y.done ? y.value : filler_, !z.done ? z.value : filler_];\n }\n }\n}\n\n/**\n * Like the other izips (`izip`, `izip3`, etc), but generalized to take an\n * unlimited amount of input iterables. Think `izip(*iterables)` in Python.\n *\n * **Note:** Due to Flow type system limitations, you can only \"generially\" zip\n * iterables with homogeneous types, so you cannot mix types like <A, B> like\n * you can with izip2().\n */\nexport function* izipMany<T>(...iters: Iterable<T>[]): IterableIterator<T[]> {\n // Make them all iterables\n const iterables = iters.map(iter);\n\n for (;;) {\n const heads: Array<IteratorResult<T, undefined>> = iterables.map((xs) => xs.next());\n if (every(heads, (h) => !h.done)) {\n yield heads.map((h) => h.value as T);\n } else {\n // One of the iterables exhausted\n return;\n }\n }\n}\n\n/**\n * Return successive `r`-length permutations of elements in the iterable.\n *\n * If `r` is not specified, then `r` defaults to the length of the iterable and\n * all possible full-length permutations are generated.\n *\n * Permutations are emitted in lexicographic sort order. So, if the input\n * iterable is sorted, the permutation tuples will be produced in sorted order.\n *\n * Elements are treated as unique based on their position, not on their value.\n * So if the input elements are unique, there will be no repeat values in each\n * permutation.\n */\nexport function* permutations<T>(iterable: Iterable<T>, r?: number): IterableIterator<T[]> {\n const pool = Array.from(iterable);\n const n = pool.length;\n const x = r === undefined ? n : r;\n\n if (x > n) {\n return;\n }\n\n let indices: number[] = Array.from(range(n));\n const cycles: number[] = Array.from(range(n, n - x, -1));\n const poolgetter = (i: number) => pool[i];\n\n yield indices.slice(0, x).map(poolgetter);\n\n while (n > 0) {\n let cleanExit = true;\n for (const i of range(x - 1, -1, -1)) {\n cycles[i] -= 1;\n if (cycles[i] === 0) {\n indices = indices\n .slice(0, i)\n .concat(indices.slice(i + 1))\n .concat(indices.slice(i, i + 1));\n cycles[i] = n - i;\n } else {\n const j: number = cycles[i];\n\n const [p, q] = [indices[indices.length - j], indices[i]];\n indices[i] = p;\n indices[indices.length - j] = q;\n yield indices.slice(0, x).map(poolgetter);\n cleanExit = false;\n break;\n }\n }\n\n if (cleanExit) {\n return;\n }\n }\n}\n\n/**\n * Returns an iterator that produces values over and over again. Runs\n * indefinitely unless the times argument is specified.\n */\nexport function* repeat<T>(thing: T, times?: number): IterableIterator<T> {\n if (times === undefined) {\n for (;;) {\n yield thing;\n }\n } else {\n for (const _ of range(times)) {\n yield thing;\n }\n }\n}\n\n/**\n * Returns an iterator that produces elements from the iterable as long as the\n * predicate is true.\n */\nexport function* takewhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): IterableIterator<T> {\n const it = iter(iterable);\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (!predicate(value)) return; // early return, so we cannot use for..of loop!\n yield value;\n }\n}\n\nexport function zipLongest2<T1, T2, D>(xs: Iterable<T1>, ys: Iterable<T2>, filler?: D): Array<[T1 | D, T2 | D]> {\n return Array.from(izipLongest2(xs, ys, filler));\n}\n\nexport function zipLongest3<T1, T2, T3, D>(\n xs: Iterable<T1>,\n ys: Iterable<T2>,\n zs: Iterable<T3>,\n filler?: D,\n): Array<[T1 | D, T2 | D, T3 | D]> {\n return Array.from(izipLongest3(xs, ys, zs, filler));\n}\n\nexport const izipLongest = izipLongest2;\nexport const zipLongest = zipLongest2;\n\nexport function zipMany<T>(...iters: Iterable<T>[]): T[][] {\n return Array.from(izipMany(...iters));\n}\n","import { count, ifilter, imap, izip, izip3, takewhile } from \"./itertools\";\nimport type { Predicate, Primitive } from \"./types\";\nimport { identityPredicate, keyToCmp, numberIdentity, primitiveIdentity } from \"./utils\";\n\n/**\n * Returns the first item in the iterable for which the predicate holds, if\n * any. If no predicate is given, it will return the first value returned by\n * the iterable.\n */\nexport function find<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n const it = iter(iterable);\n if (keyFn === undefined) {\n const value = it.next();\n return value.done ? value.value : value.value;\n } else {\n let res: IteratorResult<T>;\n while (!(res = it.next()).done) {\n const value = res.value;\n if (keyFn(value)) {\n return value;\n }\n }\n return undefined;\n }\n}\n\n/**\n * Returns true when all of the items in iterable are truthy. An optional key\n * function can be used to define what truthiness means for this specific\n * collection.\n *\n * Examples:\n *\n * all([]) // => true\n * all([0]) // => false\n * all([0, 1, 2]) // => false\n * all([1, 2, 3]) // => true\n *\n * Examples with using a key function:\n *\n * all([2, 4, 6], n => n % 2 === 0) // => true\n * all([2, 4, 5], n => n % 2 === 0) // => false\n *\n */\nexport function every<T>(iterable: Iterable<T>, keyFn: Predicate<T> = identityPredicate): boolean {\n for (const item of iterable) {\n if (!keyFn(item)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Returns true when some of the items in iterable are truthy. An optional key\n * function can be used to define what truthiness means for this specific\n * collection.\n *\n * Examples:\n *\n * some([]) // => false\n * some([0]) // => false\n * some([0, 1, null, undefined]) // => true\n *\n * Examples with using a key function:\n *\n * some([1, 4, 5], n => n % 2 === 0) // => true\n * some([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false\n *\n */\nexport function some<T>(iterable: Iterable<T>, keyFn: Predicate<T> = identityPredicate): boolean {\n for (const item of iterable) {\n if (keyFn(item)) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Alias of `every()`.\n */\nexport const all = every;\n\n/**\n * Alias of `some()`.\n */\nexport const any = some;\n\n/**\n * Returns true when any of the items in the iterable are equal to the target object.\n *\n * Examples:\n *\n * contains([], 'whatever') // => false\n * contains([3], 42) // => false\n * contains([3], 3) // => true\n * contains([0, 1, 2], 2) // => true\n *\n */\nexport function contains<T>(haystack: Iterable<T>, needle: T): boolean {\n return some(haystack, (x) => x === needle);\n}\n\n/**\n * Returns an iterable of enumeration pairs. Iterable must be a sequence, an\n * iterator, or some other object which supports iteration. The elements\n * produced by returns a tuple containing a counter value (starting from 0 by\n * default) and the values obtained from iterating over given iterable.\n *\n * Example:\n *\n * import { enumerate } from 'itertools';\n *\n * console.log([...enumerate(['hello', 'world'])]);\n * // [0, 'hello'], [1, 'world']]\n */\nexport function* enumerate<T>(iterable: Iterable<T>, start = 0): IterableIterator<[number, T]> {\n let index: number = start;\n for (const value of iterable) {\n yield [index++, value];\n }\n}\n\n/**\n * Non-lazy version of ifilter().\n */\nexport function filter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): N[];\nexport function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[];\nexport function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[] {\n return Array.from(ifilter(iterable, predicate));\n}\n\n/**\n * Returns an iterator object for the given iterable. This can be used to\n * manually get an iterator for any iterable datastructure. The purpose and\n * main use case of this function is to get a single iterator (a thing with\n * state, think of it as a \"cursor\") which can only be consumed once.\n */\nexport function iter<T>(iterable: Iterable<T>): IterableIterator<T> {\n // class SelfIter implements IterableIterator<T> {\n // #iterator: Iterator<T>;\n // constructor(orig: Iterable<T>) {\n // this.#iterator = orig[Symbol.iterator]();\n // }\n // [Symbol.iterator]() {\n // return this;\n // }\n // next() {\n // return this.#iterator.next();\n // }\n // }\n // return new SelfIter(iterable);\n\n return iterable[Symbol.iterator]() as IterableIterator<T>;\n // ^^^^^^^^^^^^^^^^^^^^^^ Not safe!\n}\n\n/**\n * Non-lazy version of imap().\n */\nexport function map<T, V>(iterable: Iterable<T>, mapper: (item: T) => V): V[] {\n return Array.from(imap(iterable, mapper));\n}\n\n/**\n * Return the largest item in an iterable. Only works for numbers, as ordering\n * is pretty poorly defined on any other data type in JS. The optional `keyFn`\n * argument specifies a one-argument ordering function like that used for\n * sorted().\n *\n * If the iterable is empty, `undefined` is returned.\n *\n * If multiple items are maximal, the function returns either one of them, but\n * which one is not defined.\n */\nexport function max<T>(iterable: Iterable<T>, keyFn: (item: T) => number = numberIdentity): T | undefined {\n return reduce2(iterable, (x, y) => (keyFn(x) > keyFn(y) ? x : y));\n}\n\n/**\n * Return the smallest item in an iterable. Only works for numbers, as\n * ordering is pretty poorly defined on any other data type in JS. The\n * optional `keyFn` argument specifies a one-argument ordering function like\n * that used for sorted().\n *\n * If the iterable is empty, `undefined` is returned.\n *\n * If multiple items are minimal, the function returns either one of them, but\n * which one is not defined.\n */\nexport function min<T>(iterable: Iterable<T>, keyFn: (item: T) => number = numberIdentity): T | undefined {\n return reduce2(iterable, (x, y) => (keyFn(x) < keyFn(y) ? x : y));\n}\n\n/**\n * Internal helper for the range function\n */\nfunction range_(start: number, stop: number, step: number): IterableIterator<number> {\n const counter = count(start, step);\n const pred = step >= 0 ? (n: number) => n < stop : (n: number) => n > stop;\n return takewhile(counter, pred);\n}\n\n/**\n * Returns an iterator producing all the numbers in the given range one by one,\n * starting from `start` (default 0), as long as `i < stop`, in increments of\n * `step` (default 1).\n *\n * `range(a)` is a convenient shorthand for `range(0, a)`.\n *\n * Various valid invocations:\n *\n * range(5) // [0, 1, 2, 3, 4]\n * range(2, 5) // [2, 3, 4]\n * range(0, 5, 2) // [0, 2, 4]\n * range(5, 0, -1) // [5, 4, 3, 2, 1]\n * range(-3) // []\n *\n * For a positive `step`, the iterator will keep producing values `n` as long\n * as the stop condition `n < stop` is satisfied.\n *\n * For a negative `step`, the iterator will keep producing values `n` as long\n * as the stop condition `n > stop` is satisfied.\n *\n * The produced range will be empty if the first value to produce already does\n * not meet the value constraint.\n */\n\nexport function range(stop: number): IterableIterator<number>;\nexport function range(start: number, stop: number, step?: number): IterableIterator<number>;\nexport function range(startOrStop: number, definitelyStop?: number, step = 1): IterableIterator<number> {\n if (definitelyStop !== undefined) {\n return range_(startOrStop /* as start */, definitelyStop, step);\n } else {\n return range_(0, startOrStop /* as stop */, step);\n }\n}\n\n/**\n * Apply function of two arguments cumulatively to the items of sequence, from\n * left to right, so as to reduce the sequence to a single value. For example:\n *\n * reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)\n *\n * calculates\n *\n * (((((0+1)+2)+3)+4)+5)\n *\n * The left argument, `x`, is the accumulated value and the right argument,\n * `y`, is the update value from the sequence.\n *\n * **Difference between `reduce()` and `reduce\\_()`**: `reduce()` requires an\n * explicit initializer, whereas `reduce_()` will automatically use the first\n * item in the given iterable as the initializer. When using `reduce()`, the\n * initializer value is placed before the items of the sequence in the\n * calculation, and serves as a default when the sequence is empty. When using\n * `reduce_()`, and the given iterable is empty, then no default value can be\n * derived and `undefined` will be returned.\n */\nexport function reduce<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined;\nexport function reduce<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O;\nexport function reduce<T, O>(\n iterable: Iterable<T>,\n reducer: ((agg: T, item: T, index: number) => T) | ((agg: O, item: T, index: number) => O),\n start?: O,\n): O | (T | undefined) {\n if (start === undefined) {\n return reduce2(iterable, reducer as (agg: T, item: T, index: number) => T);\n } else {\n return reduce3(iterable, reducer as (agg: O, item: T, index: number) => O, start);\n }\n}\n\nfunction reduce3<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O {\n let output = start;\n let index = 0;\n for (const item of iterable) {\n output = reducer(output, item, index++);\n }\n return output;\n}\n\nfunction reduce2<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined {\n const it = iter(iterable);\n const start = find(it);\n if (start === undefined) {\n return undefined;\n } else {\n return reduce3(it, reducer, start);\n }\n}\n\n/**\n * Return a new sorted list from the items in iterable.\n *\n * Has two optional arguments:\n *\n * * `keyFn` specifies a function of one argument providing a primitive\n * identity for each element in the iterable. that will be used to compare.\n * The default value is to use a default identity function that is only\n * defined for primitive types.\n *\n * * `reverse` is a boolean value. If `true`, then the list elements are\n * sorted as if each comparison were reversed.\n */\nexport function sorted<T>(\n iterable: Iterable<T>,\n keyFn: (item: T) => Primitive = primitiveIdentity,\n reverse = false,\n): T[] {\n const result = Array.from(iterable);\n result.sort(keyToCmp(keyFn)); // sort in-place\n\n if (reverse) {\n result.reverse(); // reverse in-place\n }\n\n return result;\n}\n\n/**\n * Sums the items of an iterable from left to right and returns the total. The\n * sum will defaults to 0 if the iterable is empty.\n */\nexport function sum(iterable: Iterable<number>): number {\n return reduce(iterable, (x, y) => x + y, 0);\n}\n\n/**\n * See izip.\n */\nexport function zip<T1, T2>(xs: Iterable<T1>, ys: Iterable<T2>): Array<[T1, T2]> {\n return Array.from(izip(xs, ys));\n}\n\n/**\n * See izip3.\n */\nexport function zip3<T1, T2, T3>(xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): Array<[T1, T2, T3]> {\n return Array.from(izip3(xs, ys, zs));\n}\n","import { find } from \"./builtins\";\nimport { ifilter, imap } from \"./itertools\";\nimport { flatten } from \"./more-itertools\";\nimport type { Predicate } from \"./types\";\n\nfunction isNullish<T>(x: T): x is NonNullable<T> {\n return x != null;\n}\n\nfunction isDefined<T>(x: T): boolean {\n return x !== undefined;\n}\n\n/**\n * Returns an iterable, filtering out any \"nullish\" values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3, null])\n * [1, 2, 3]\n *\n * For an eager version, @see compact().\n */\nexport function icompact<T>(iterable: Iterable<T | null | undefined>): IterableIterator<T> {\n return ifilter(iterable, isNullish);\n}\n\n/**\n * Returns an array, filtering out any \"nullish\" values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3, null])\n * [1, 2, 3]\n *\n * For a lazy version, @see icompact().\n */\nexport function compact<T>(iterable: Iterable<T | null | undefined>): T[] {\n return Array.from(icompact(iterable));\n}\n\n/**\n * Removes all \"nullish\" values from the given object. Returns a new object.\n *\n * >>> compactObject({ a: 1, b: undefined, c: 0, d: null })\n * { a: 1, c: 0 }\n *\n */\nexport function compactObject<K extends string, V>(obj: Record<K, V | null | undefined>): Record<K, V> {\n const result = {} as Record<K, V>;\n for (const [key, value_] of Object.entries(obj)) {\n const value = value_ as V | null | undefined;\n if (value != null) {\n result[key as K] = value;\n }\n }\n return result;\n}\n\n/**\n * Almost an alias of find(). There only is a difference if no key fn is\n * provided. In that case, `find()` will return the first item in the iterable,\n * whereas `first()` will return the first non-`undefined` value in the\n * iterable.\n */\nexport function first<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n return find(iterable, keyFn ?? isDefined);\n}\n\n/**\n * Returns 0 or more values for every value in the given iterable.\n * Technically, it's just calling map(), followed by flatten(), but it's a very\n * useful operation if you want to map over a structure, but not have a 1:1\n * input-output mapping. Instead, if you want to potentially return 0 or more\n * values per input element, use flatmap():\n *\n * For example, to return all numbers `n` in the input iterable `n` times:\n *\n * >>> const repeatN = n => repeat(n, n);\n * >>> [...flatmap([0, 1, 2, 3, 4], repeatN)]\n * [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0\n *\n */\nexport function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>): IterableIterator<S> {\n return flatten(imap(iterable, mapper));\n}\n"],"mappings":";AAIO,SAAS,SAAY,OAAyC;AACnE,SAAO,CAAC,GAAM,MAAS;AACrB,UAAM,KAAK,MAAM,CAAC;AAClB,UAAM,KAAK,MAAM,CAAC;AAElB,QAAI,OAAO,OAAO,aAAa,OAAO,OAAO,WAAW;AACtD,aAAO,OAAO,KAAK,IAAI,CAAC,MAAM,KAAK,KAAK;AAAA,IAC1C,WAAW,OAAO,OAAO,YAAY,OAAO,OAAO,UAAU;AAC3D,aAAO,KAAK;AAAA,IACd,WAAW,OAAO,OAAO,YAAY,OAAO,OAAO,UAAU;AAC3D,aAAO,OAAO,KAAK,IAAI,KAAK,KAAK,KAAK;AAAA,IACxC,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,SAAS,kBAAkB,GAAqB;AACrD,SAAO,CAAC,CAAC;AACX;AAEO,SAAS,eAAe,GAAoB;AAEjD,MAAI,OAAO,MAAM,UAAU;AACzB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AACA,SAAO;AACT;AAIO,SAAS,kBAAkB,GAAuB;AAEvD,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM,WAAW;AAC5E,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,SAAO;AACT;;;ACxBO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F;AACA,SAAO;AACT;AAQO,SAAS,MAAS,UAAuB,OAAqC;AACnF,SAAO,KAAK,UAAU,wBAAS,SAAS;AAC1C;AAgBO,SAAS,QAAc,UAAuB,QAAuD;AAC1G,SAAO,QAAQ,KAAK,UAAU,MAAM,CAAC;AACvC;","names":["count","first","grouper","heads"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itertools",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "A JavaScript port of Python's awesome itertools standard library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -49,21 +49,20 @@
|
|
|
49
49
|
"node-itertools"
|
|
50
50
|
],
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@arethetypeswrong/cli": "^0.
|
|
52
|
+
"@arethetypeswrong/cli": "^0.15.0",
|
|
53
53
|
"@release-it/keep-a-changelog": "^5.0.0",
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
55
|
-
"@typescript-eslint/parser": "^
|
|
56
|
-
"@vitest/coverage-istanbul": "^1.1
|
|
57
|
-
"eslint": "^8.
|
|
58
|
-
"fast-check": "^3.
|
|
59
|
-
"
|
|
60
|
-
"prettier": "^3.1.1",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
|
55
|
+
"@typescript-eslint/parser": "^7.0.2",
|
|
56
|
+
"@vitest/coverage-istanbul": "^1.3.1",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"fast-check": "^3.16.0",
|
|
59
|
+
"prettier": "^3.2.5",
|
|
61
60
|
"publint": "^0.2.7",
|
|
62
|
-
"release-it": "^17.
|
|
63
|
-
"tsup": "^8.0.
|
|
61
|
+
"release-it": "^17.1.1",
|
|
62
|
+
"tsup": "^8.0.2",
|
|
64
63
|
"typescript": "^5.3.3",
|
|
65
|
-
"vite-tsconfig-paths": "^4.
|
|
66
|
-
"vitest": "^1.1
|
|
64
|
+
"vite-tsconfig-paths": "^4.3.1",
|
|
65
|
+
"vitest": "^1.3.1"
|
|
67
66
|
},
|
|
68
67
|
"githubUrl": "https://github.com/nvie/itertools",
|
|
69
68
|
"sideEffects": false
|