itertools 2.0.0 → 2.1.0
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/README.md +61 -41
- package/dist/index.d.ts +21 -10
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/itertools)
|
|
2
2
|
[](https://github.com/nvie/itertools.js/actions)
|
|
3
|
-
[](https://coveralls.io/github/nvie/itertools.js?branch=master)
|
|
4
3
|
[](https://bundlephobia.com/result?p=itertools)
|
|
5
4
|
|
|
6
5
|
A JavaScript port of Python's awesome
|
|
@@ -8,7 +7,7 @@ A JavaScript port of Python's awesome
|
|
|
8
7
|
|
|
9
8
|
Usage example:
|
|
10
9
|
|
|
11
|
-
```
|
|
10
|
+
```ts
|
|
12
11
|
>>> import { izip, cycle } from 'itertools';
|
|
13
12
|
>>>
|
|
14
13
|
>>> const xs = [1, 2, 3, 4];
|
|
@@ -46,7 +45,7 @@ The rationale for this flipping of argument order is because in practice, the
|
|
|
46
45
|
function bodies can span multiple lines, in which case the following block will
|
|
47
46
|
remaing aesthetically pleasing:
|
|
48
47
|
|
|
49
|
-
```
|
|
48
|
+
```ts
|
|
50
49
|
import { map } from 'itertools';
|
|
51
50
|
|
|
52
51
|
const numbers = [1, 2, 3];
|
|
@@ -73,8 +72,8 @@ The `itertools` package consists of a few building blocks:
|
|
|
73
72
|
|
|
74
73
|
### Ports of builtins
|
|
75
74
|
|
|
76
|
-
* [
|
|
77
|
-
* [
|
|
75
|
+
* [every](#every)
|
|
76
|
+
* [some](#some)
|
|
78
77
|
* [contains](#contains)
|
|
79
78
|
* [enumerate](#enumerate)
|
|
80
79
|
* [filter](#filter)
|
|
@@ -84,65 +83,64 @@ The `itertools` package consists of a few building blocks:
|
|
|
84
83
|
* [min](#min)
|
|
85
84
|
* [range](#range)
|
|
86
85
|
* [reduce](#reduce)
|
|
87
|
-
* [reduce\_](#reduce_)
|
|
88
86
|
* [sorted](#sorted)
|
|
89
87
|
* [sum](#sum)
|
|
90
88
|
* [zip](#zip)
|
|
91
89
|
* [zip3](#zip3)
|
|
92
90
|
|
|
93
|
-
<a name="
|
|
91
|
+
<a name="every" href="#every">#</a> <b>every</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>Predicate<T></i>): <i>boolean</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")
|
|
94
92
|
|
|
95
|
-
Returns true when
|
|
93
|
+
Returns true when every of the items in iterable are truthy. An optional key
|
|
96
94
|
function can be used to define what truthiness means for this specific
|
|
97
95
|
collection.
|
|
98
96
|
|
|
99
97
|
Examples:
|
|
100
98
|
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
```ts
|
|
100
|
+
every([]) // => true
|
|
101
|
+
every([0]) // => false
|
|
102
|
+
every([0, 1, 2]) // => false
|
|
103
|
+
every([1, 2, 3]) // => true
|
|
106
104
|
```
|
|
107
105
|
|
|
108
106
|
Examples with using a key function:
|
|
109
107
|
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
```ts
|
|
109
|
+
every([2, 4, 6], n => n % 2 === 0) // => true
|
|
110
|
+
every([2, 4, 5], n => n % 2 === 0) // => false
|
|
113
111
|
```
|
|
114
112
|
|
|
115
113
|
|
|
116
|
-
<a name="
|
|
114
|
+
<a name="some" href="#some">#</a> <b>some</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>Predicate<T></i>): <i>boolean</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")
|
|
117
115
|
|
|
118
|
-
Returns true when
|
|
116
|
+
Returns true when some of the items in iterable are truthy. An optional key
|
|
119
117
|
function can be used to define what truthiness means for this specific
|
|
120
118
|
collection.
|
|
121
119
|
|
|
122
120
|
Examples:
|
|
123
121
|
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
```ts
|
|
123
|
+
some([]) // => false
|
|
124
|
+
some([0]) // => false
|
|
125
|
+
some([0, 1, null, undefined]) // => true
|
|
128
126
|
```
|
|
129
127
|
|
|
130
128
|
Examples with using a key function:
|
|
131
129
|
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
```ts
|
|
131
|
+
some([1, 4, 5], n => n % 2 === 0) // => true
|
|
132
|
+
some([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false
|
|
135
133
|
```
|
|
136
134
|
|
|
137
135
|
|
|
138
136
|
<a name="contains" href="#contains">#</a> <b>contains</b>(haystack: <i>Iterable<T></i>, needle: <i>T</i>): <i>boolean</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")
|
|
139
137
|
|
|
140
|
-
Returns true when
|
|
138
|
+
Returns true when some of the items in the iterable are equal to the target
|
|
141
139
|
object.
|
|
142
140
|
|
|
143
141
|
Examples:
|
|
144
142
|
|
|
145
|
-
```
|
|
143
|
+
```ts
|
|
146
144
|
contains([], 'whatever') // => false
|
|
147
145
|
contains([3], 42) // => false
|
|
148
146
|
contains([3], 3) // => true
|
|
@@ -159,7 +157,7 @@ the values obtained from iterating over given iterable.
|
|
|
159
157
|
|
|
160
158
|
Example:
|
|
161
159
|
|
|
162
|
-
```
|
|
160
|
+
```ts
|
|
163
161
|
import { enumerate } from 'itertools';
|
|
164
162
|
|
|
165
163
|
console.log([...enumerate(['hello', 'world'])]);
|
|
@@ -210,7 +208,7 @@ If multiple items are minimal, the function returns either one of them, but
|
|
|
210
208
|
which one is not defined.
|
|
211
209
|
|
|
212
210
|
|
|
213
|
-
<a name="range" href="#range">#</a> <b>range</b>(
|
|
211
|
+
<a name="range" href="#range">#</a> <b>range</b>(stop: <i>number</i>): <i>Iterable<number></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")<br />
|
|
214
212
|
<a name="range" href="#range">#</a> <b>range</b>(start: <i>number</i>, stop: <i>number</i>, step: <i>number</i> = 1): <i>Iterable<number></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")
|
|
215
213
|
|
|
216
214
|
Returns an iterator producing all the numbers in the given range one by one,
|
|
@@ -238,27 +236,39 @@ meet the value constraint.
|
|
|
238
236
|
|
|
239
237
|
|
|
240
238
|
<a name="reduce" href="#reduce">#</a> <b>reduce</b>(iterable: <i>Iterable<T></i>, reducer: <i>(O, T, number) => O</i>, start: <i>O</i>): <i>O</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")<br />
|
|
241
|
-
<a name="
|
|
239
|
+
<a name="reduce" href="#reduce">#</a> <b>reduce</b>(iterable: <i>Iterable<T></i>, reducer: <i>(T, T, number) => T</i>): <i>Maybe<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")
|
|
242
240
|
|
|
243
241
|
Apply function of two arguments cumulatively to the items of sequence, from
|
|
244
242
|
left to right, so as to reduce the sequence to a single value. For example:
|
|
245
243
|
|
|
246
|
-
|
|
244
|
+
```ts
|
|
245
|
+
reduce(
|
|
246
|
+
[1, 2, 3, 4, 5],
|
|
247
|
+
(total, x) => total + x,
|
|
248
|
+
0
|
|
249
|
+
)
|
|
250
|
+
```
|
|
247
251
|
|
|
248
252
|
calculates
|
|
249
253
|
|
|
250
254
|
(((((0+1)+2)+3)+4)+5)
|
|
251
255
|
|
|
252
|
-
The left argument, `
|
|
253
|
-
is the update value from the sequence.
|
|
256
|
+
The left argument, `total`, is the accumulated value and the right argument,
|
|
257
|
+
`x`, is the update value from the sequence.
|
|
258
|
+
|
|
259
|
+
Without an explicit initializer arg:
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
reduce(
|
|
263
|
+
[1, 2, 3, 4, 5],
|
|
264
|
+
(total, x) => total + x
|
|
265
|
+
)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
it calculates
|
|
269
|
+
|
|
270
|
+
((((1+2)+3)+4)+5)
|
|
254
271
|
|
|
255
|
-
**Difference between `reduce()` and `reduce\_()`**: `reduce()` requires an
|
|
256
|
-
explicit initializer, whereas `reduce_()` will automatically use the first item
|
|
257
|
-
in the given iterable as the initializer. When using `reduce()`, the
|
|
258
|
-
initializer value is placed before the items of the sequence in the
|
|
259
|
-
calculation, and serves as a default when the sequence is empty. When using
|
|
260
|
-
`reduce_()`, and the given iterable is empty, then no default value can be
|
|
261
|
-
derived and `undefined` will be returned.
|
|
262
272
|
|
|
263
273
|
|
|
264
274
|
<a name="sorted" href="#sorted">#</a> <b>sorted</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>T => Primitive</i></i>, reverse?: <i>boolean</i>): <i>Array<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")
|
|
@@ -573,6 +583,7 @@ Yields elements in order, ignoring serial duplicates.
|
|
|
573
583
|
|
|
574
584
|
* [compact](#compact)
|
|
575
585
|
* [compactObject](#compactObject)
|
|
586
|
+
* [find](#find)
|
|
576
587
|
* [first](#first)
|
|
577
588
|
* [flatmap](#flatmap)
|
|
578
589
|
* [icompact](#icompact)
|
|
@@ -592,13 +603,22 @@ Removes all undefined values from the given object. Returns a new object.
|
|
|
592
603
|
{ a: 1, c: 0, d: null }
|
|
593
604
|
|
|
594
605
|
|
|
595
|
-
<a name="
|
|
606
|
+
<a name="find" href="#find">#</a> <b>find</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>Predicate<T></i>): <i>Maybe<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js "Source")
|
|
596
607
|
|
|
597
608
|
Returns the first item in the iterable for which the predicate holds, if any.
|
|
598
609
|
If no such item exists, `undefined` is returned. The default predicate is any
|
|
599
610
|
defined value.
|
|
600
611
|
|
|
601
612
|
|
|
613
|
+
<a name="first" href="#first">#</a> <b>first</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>Predicate<T></i>): <i>Maybe<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js "Source")
|
|
614
|
+
|
|
615
|
+
Almost the same as `find()`, except when no explicit predicate function is
|
|
616
|
+
given. `find()` will always return the first value in the iterable, whereas
|
|
617
|
+
`first()` will return the first non-undefined value in the iterable.
|
|
618
|
+
|
|
619
|
+
Prefer using `find()`, as its behavior is more intuitive and predictable.
|
|
620
|
+
|
|
621
|
+
|
|
602
622
|
<a name="flatmap" href="#flatmap">#</a> <b>flatmap</b>(iterable: <i>Iterable<T></i>, mapper: <i>T => Iterable<S></i>): <i>Iterable<S></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js "Source")
|
|
603
623
|
|
|
604
624
|
Returns 0 or more values for every value in the given iterable. Technically,
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare type Primitive = string | number | boolean;
|
|
|
19
19
|
* all([2, 4, 5], n => n % 2 === 0) // => false
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
declare function
|
|
22
|
+
declare function every<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): boolean;
|
|
23
23
|
/**
|
|
24
24
|
* Returns true when any of the items in iterable are truthy. An optional key
|
|
25
25
|
* function can be used to define what truthiness means for this specific
|
|
@@ -37,7 +37,15 @@ declare function all<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): boolean;
|
|
|
37
37
|
* any([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false
|
|
38
38
|
*
|
|
39
39
|
*/
|
|
40
|
-
declare function
|
|
40
|
+
declare function some<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Alias of `every()`.
|
|
43
|
+
*/
|
|
44
|
+
declare const all: typeof every;
|
|
45
|
+
/**
|
|
46
|
+
* Alias of `some()`.
|
|
47
|
+
*/
|
|
48
|
+
declare const any: typeof some;
|
|
41
49
|
/**
|
|
42
50
|
* Returns true when any of the items in the iterable are equal to the target object.
|
|
43
51
|
*
|
|
@@ -67,6 +75,7 @@ declare function enumerate<T>(iterable: Iterable<T>, start?: number): Iterable<[
|
|
|
67
75
|
/**
|
|
68
76
|
* Non-lazy version of ifilter().
|
|
69
77
|
*/
|
|
78
|
+
declare function filter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): N[];
|
|
70
79
|
declare function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[];
|
|
71
80
|
/**
|
|
72
81
|
* Returns an iterator object for the given iterable. This can be used to
|
|
@@ -127,7 +136,8 @@ declare function min<T>(iterable: Iterable<T>, keyFn?: (item: T) => number): T |
|
|
|
127
136
|
* The produced range will be empty if the first value to produce already does
|
|
128
137
|
* not meet the value constraint.
|
|
129
138
|
*/
|
|
130
|
-
declare function range(
|
|
139
|
+
declare function range(stop: number): Iterable<number>;
|
|
140
|
+
declare function range(start: number, stop: number, step?: number): Iterable<number>;
|
|
131
141
|
/**
|
|
132
142
|
* Apply function of two arguments cumulatively to the items of sequence, from
|
|
133
143
|
* left to right, so as to reduce the sequence to a single value. For example:
|
|
@@ -149,6 +159,7 @@ declare function range(a: number, ...rest: number[]): Iterable<number>;
|
|
|
149
159
|
* `reduce_()`, and the given iterable is empty, then no default value can be
|
|
150
160
|
* derived and `undefined` will be returned.
|
|
151
161
|
*/
|
|
162
|
+
declare function reduce<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined;
|
|
152
163
|
declare function reduce<T, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O;
|
|
153
164
|
/**
|
|
154
165
|
* Return a new sorted list from the items in iterable.
|
|
@@ -219,6 +230,7 @@ declare function icompress<T>(data: Iterable<T>, selectors: Iterable<boolean>):
|
|
|
219
230
|
* Returns an iterator that filters elements from iterable returning only those
|
|
220
231
|
* for which the predicate is true.
|
|
221
232
|
*/
|
|
233
|
+
declare function ifilter<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): Iterable<N>;
|
|
222
234
|
declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T>;
|
|
223
235
|
/**
|
|
224
236
|
* Returns an iterator that computes the given mapper function using arguments
|
|
@@ -337,6 +349,7 @@ declare function pairwise<T>(iterable: Iterable<T>): Iterable<[T, T]>;
|
|
|
337
349
|
* [0, 2, 4, 6, 8]
|
|
338
350
|
*
|
|
339
351
|
*/
|
|
352
|
+
declare function partition<T, N extends T>(iterable: Iterable<T>, predicate: (item: T) => item is N): [N[], Exclude<T, N>[]];
|
|
340
353
|
declare function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): [T[], T[]];
|
|
341
354
|
/**
|
|
342
355
|
* Yields the next item from each iterable in turn, alternating between them.
|
|
@@ -404,16 +417,14 @@ declare function compact<T>(iterable: Iterable<T | null | undefined>): T[];
|
|
|
404
417
|
declare function compactObject<K extends string, V>(obj: Record<K, V | null | undefined>): Record<K, V>;
|
|
405
418
|
/**
|
|
406
419
|
* Returns the first item in the iterable for which the predicate holds, if
|
|
407
|
-
* any.
|
|
408
|
-
*
|
|
420
|
+
* any. If no predicate is given, it will return the first value returned by
|
|
421
|
+
* the iterable.
|
|
409
422
|
*/
|
|
410
423
|
declare function find<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined;
|
|
411
424
|
/**
|
|
412
|
-
*
|
|
413
|
-
* any. If no such item exists, `undefined` is returned. The default
|
|
414
|
-
* predicate is any defined value.
|
|
425
|
+
* Almost an alias of find(). The key difference is that if an empty
|
|
415
426
|
*/
|
|
416
|
-
declare
|
|
427
|
+
declare function first<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined;
|
|
417
428
|
/**
|
|
418
429
|
* Returns 0 or more values for every value in the given iterable.
|
|
419
430
|
* Technically, it's just calling map(), followed by flatten(), but it's a very
|
|
@@ -430,4 +441,4 @@ declare const first: typeof find;
|
|
|
430
441
|
*/
|
|
431
442
|
declare function flatmap<T, S>(iterable: Iterable<T>, mapper: (item: T) => Iterable<S>): Iterable<S>;
|
|
432
443
|
|
|
433
|
-
export { Predicate, Primitive, all, any, chain, chunked, compact, compactObject, compress, contains, count, cycle, dropwhile, enumerate, filter, 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, sorted, sum, take, takewhile, uniqueEverseen, uniqueJustseen, zip, zip3, zipLongest, zipMany };
|
|
444
|
+
export { Predicate, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});function
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});function k(t){return(e,r)=>{let n=t(e),i=t(r);return typeof n=="boolean"&&typeof i=="boolean"?n===i?0:!n&&i?-1:1:typeof n=="number"&&typeof i=="number"?n-i:typeof n=="string"&&typeof i=="string"?n===i?0:n<i?-1:1:-1}}function I(t){return!!t}function x(t){if(typeof t!="number")throw new Error("Inputs must be numbers");return t}function T(t){if(typeof t!="string"&&typeof t!="number"&&typeof t!="boolean")throw new Error("Please provide a key function that can establish object identity");return t}function*Q(t,e){if(e<1)throw new Error(`Invalid chunk size: ${e}`);let r=a(t);for(;;){let n=V(e,r);if(n.length>0&&(yield n),n.length<e)return}}function*s(t){for(let e of t)for(let r of e)yield r}function*O(t,e){let r=a(e),n=t;for(;n-- >0;){let i=r.next();if(!i.done)yield i.value;else return}}function*U(t){let e=a(t),r=e.next();if(r.done)return;let n=r.value;for(let i of e)yield[n,i],n=i}function W(t,e){let r=[],n=[];for(let i of t)e(i)?r.push(i):n.push(i);return[r,n]}function*X(...t){let e=m(t,a);for(;e.length>0;){let r=0;for(;r<e.length;){let i=e[r].next();i.done?e.splice(r,1):(yield i.value,r++)}}}function*Y(...t){let e=m(t,a);for(;e.length>0;){let r=0,n=[];for(;r<e.length;){let o=e[r].next();o.done?e.splice(r,1):(n.push(o.value),r++)}n.length>0&&(yield n)}}function V(t,e){return Array.from(O(t,e))}function*Z(t,e=T){let r=new Set;for(let n of t){let i=e(n);r.has(i)||(r.add(i),yield n)}}function*F(t,e=T){let r;for(let n of t){let i=e(n);i!==r&&(yield n,r=i)}}var K=Symbol();function E(t,e){return r=>t(r)&&e(r)}function ee(t,e,r){if(t<0)throw new Error("start cannot be negative");if(e!==null&&e<0)throw new Error("stop cannot be negative");if(r<0)throw new Error("step cannot be negative");let n=i=>i>=t;if(e!==null){let i=e;n=E(n,o=>o<i)}return r>1&&(n=E(n,i=>(i-t)%r===0)),n}function te(...t){return s(t)}function*y(t=0,e=1){let r=t;for(;;)yield r,r+=e}function re(t,e){return Array.from(N(t,e))}function*ne(t){let e=[];for(let r of t)yield r,e.push(r);for(;e.length>0;)for(let r of e)yield r}function*ie(t,e){let r=a(t);for(let n of r)if(!e(n)){yield n;break}for(let n of r)yield n}function*oe(t,e=T){let r=a(t),n,i=K,o=i,l=function*(c){for(;i===c;){yield n;let f=r.next();if(f.done)return;n=f.value,i=e(n)}};for(;;){for(;i===o;){let u=r.next();if(u.done){i=K;return}n=u.value,i=e(n)}o=i,yield[i,l(o)]}}function*N(t,e){for(let[r,n]of d(t,e))n&&(yield r)}function*v(t,e){for(let r of t)e(r)&&(yield r)}function*p(t,e){for(let r of t)yield e(r)}function*ae(t,e,r,n=1){let i,o;r!==void 0?(i=e,o=r):(i=0,o=e);let l=ee(i,o,n);for(let[u,c]of w(t))l(u)&&(yield c)}function*L(t,e){let r=a(t),n=a(e);for(;;){let i=r.next(),o=n.next();if(!i.done&&!o.done)yield[i.value,o.value];else return}}function*g(t,e,r){let n=a(t),i=a(e),o=a(r);for(;;){let l=n.next(),u=i.next(),c=o.next();if(!l.done&&!u.done&&!c.done)yield[l.value,u.value,c.value];else return}}var d=L;function*j(t,e,r){let n=r,i=a(t),o=a(e);for(;;){let l=i.next(),u=o.next();if(l.done&&u.done)return;yield[l.done?n:l.value,u.done?n:u.value]}}function*q(...t){let e=t.map(a);for(;;){let r=e.map(n=>n.next());if(P(r,n=>!n.done))yield r.map(n=>n.value);else return}}function*le(t,e){let r=Array.from(t),n=r.length,i=e===void 0?n:e;if(i>n)return;let o=Array.from(b(n)),l=Array.from(b(n,n-i,-1)),u=c=>r[c];for(yield o.slice(0,i).map(u);n>0;){let c=!0;for(let f of b(i-1,-1,-1))if(l[f]-=1,l[f]===0)o=o.slice(0,f).concat(o.slice(f+1)).concat(o.slice(f,f+1)),l[f]=n-f;else{let D=l[f],[B,H]=[o[o.length-D],o[f]];o[f]=B,o[o.length-D]=H,yield o.slice(0,i).map(u),c=!1;break}if(c)return}}function*h(t,e){for(let r of t){if(!e(r))return;yield r}}function ue(t,e,r){return Array.from(j(t,e,r))}var fe=j,ce= exports.zipLongest =ue;function Te(...t){return Array.from(q(...t))}function se(t){return t!==void 0}function*_(t){for(let e of t)e!=null&&(yield e)}function be(t){return Array.from(_(t))}function pe(t){let e={};for(let[r,n]of Object.entries(t)){let i=n;i!=null&&(e[r]=i)}return e}function C(t,e){if(e===void 0){for(let r of t)return r;return}else{for(let r of t)if(e(r))return r;return}}function z(t,e){return C(t,e!=null?e:se)}function me(t,e){return s(p(t,e))}function R(t,e=I){for(let r of t)if(!e(r))return!1;return!0}function S(t,e=I){for(let r of t)if(e(r))return!0;return!1}var P=R,G= exports.any =S;function de(t,e){return G(t,r=>r===e)}function*w(t,e=0){let r=e;for(let n of t)yield[r++,n]}function Ie(t,e){return Array.from(v(t,e))}function a(t){return t[Symbol.iterator]()}function m(t,e){return Array.from(p(t,e))}function xe(t,e=x){return A(t,(r,n)=>e(r)>e(n)?r:n)}function ye(t,e=x){return A(t,(r,n)=>e(r)<e(n)?r:n)}function M(t,e,r){let n=y(t,r),i=r>=0?o=>o<e:o=>o>e;return h(n,i)}function b(t,e,r=1){return e!==void 0?M(t,e,r):M(0,t,r)}function J(t,e,r){return r===void 0?A(t,e):$(t,e,r)}function $(t,e,r){let n=r,i=0;for(let o of t)n=e(n,o,i++);return n}function A(t,e){let r=a(t),n=z(r);if(n!==void 0)return $(r,e,n)}function ve(t,e=T,r=!1){let n=Array.from(t);return n.sort(k(e)),r&&n.reverse(),n}function ge(t){return J(t,(e,r)=>e+r,0)}function he(t,e){return Array.from(d(t,e))}function Pe(t,e,r){return Array.from(g(t,e,r))}exports.all = P; exports.any = G; exports.chain = te; exports.chunked = Q; exports.compact = be; exports.compactObject = pe; exports.compress = re; exports.contains = de; exports.count = y; exports.cycle = ne; exports.dropwhile = ie; exports.enumerate = w; exports.every = R; exports.filter = Ie; exports.find = C; exports.first = z; exports.flatmap = me; exports.flatten = s; exports.groupby = oe; exports.heads = Y; exports.icompact = _; exports.icompress = N; exports.ifilter = v; exports.imap = p; exports.islice = ae; exports.itake = O; exports.iter = a; exports.izip = d; exports.izip2 = L; exports.izip3 = g; exports.izipLongest = fe; exports.izipMany = q; exports.map = m; exports.max = xe; exports.min = ye; exports.pairwise = U; exports.partition = W; exports.permutations = le; exports.range = b; exports.reduce = J; exports.roundrobin = X; exports.some = S; exports.sorted = ve; exports.sum = ge; exports.take = V; exports.takewhile = h; exports.uniqueEverseen = Z; exports.uniqueJustseen = F; exports.zip = he; exports.zip3 = Pe; exports.zipLongest = ce; exports.zipMany = Te;
|
|
2
2
|
// istanbul ignore else -- @preserve
|
|
3
3
|
// istanbul ignore if -- @preserve
|
|
4
|
-
// istanbul ignore next -- @preserve
|
|
5
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/more-itertools.ts","../src/itertools.ts","../src/custom.ts","../src/builtins.ts"],"names":["keyToCmp","keyFn","a","b","ka","kb","identityPredicate","x","numberIdentity","primitiveIdentity","chunked","iterable","size","it","iter","r1","chunk","item","flatten","iterableOfIterables","itake","n","count","s","pairwise","first","r2","partition","predicate","good","bad","roundrobin","iters","iterables","map","index","result","heads","round","take","uniqueEverseen","seen","key","uniqueJustseen","last","SENTINEL","composeAnd","f1","f2","slicePredicate","start","stop","step","pred","definedStop","chain","compress","data","selectors","icompress","cycle","saved","element","dropwhile","value","groupby","currentValue","currentKey","targetKey","grouper","tgtKey","nextVal","d","izip","ifilter","imap","mapper","islice","stopOrStart","possiblyStop","i","enumerate","izip2","xs","ys","ixs","iys","y","izip3","zs","izs","z","izipLongest2","filler","filler_","izipMany","all","h","permutations","pool","indices","range","cycles","poolgetter","cleanExit","j","p","q","takewhile","zipLongest2","izipLongest","zipLongest","zipMany","isDefined","icompact","compact","compactObject","obj","value_","find","fn","flatmap","any","contains","haystack","needle","filter","max","reduce_","min","_range","counter","rest","args","reduce","reducer","output","sorted","reverse","sum","zip","zip3"],"mappings":"AAIO,SAASA,EAAYC,EAAyC,CACjE,MAAO,CAACC,EAAMC,IAAS,CACnB,IAAMC,EAAKH,EAAMC,CAAC,EACZG,EAAKJ,EAAME,CAAC,EAElB,OAAI,OAAOC,GAAO,WAAa,OAAOC,GAAO,UAClCD,IAAOC,EAAK,EAAI,CAACD,GAAMC,EAAK,GAAK,EACjC,OAAOD,GAAO,UAAY,OAAOC,GAAO,SACxCD,EAAKC,EACL,OAAOD,GAAO,UAAY,OAAOC,GAAO,SACxCD,IAAOC,EAAK,EAAID,EAAKC,EAAK,GAAK,EAE/B,EAEf,CACJ,CAEO,SAASC,EAAkBC,EAAqB,CACnD,MAAO,CAAC,CAACA,CACb,CAEO,SAASC,EAAeD,EAAoB,CAE/C,GAAI,OAAOA,GAAM,SACb,MAAM,IAAI,MAAM,wBAAwB,EAE5C,OAAOA,CACX,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,EAAQC,EAAQvH,EAAMkB,CAAK,EAExC,OAAOqG,CACX,CAKO,SAASR,EAAWrH,EAAuB4H,EAA+D,CAC7G,IAAM1H,EAAKC,EAAKH,CAAQ,EAClBuC,EAAQzB,EAAMZ,CAAE,EACtB,GAAIqC,IAAU,OAGV,OAAOoF,EAAOzH,EAAI0H,EAASrF,CAAK,CAExC,CAeO,SAASuF,GACZ9H,EACAV,EAAgCQ,EAChCiI,EAAU,GACP,CACH,IAAMtG,EAAS,MAAM,KAAKzB,CAAQ,EAClC,OAAAyB,EAAO,KAAKpC,EAASC,CAAK,CAAC,EAEvByI,GACAtG,EAAO,QAAQ,EAGZA,CACX,CAMO,SAASuG,GAAIhI,EAAoC,CACpD,OAAO2H,EAAO3H,EAAU,CAACJ,EAAGgF,IAAMhF,EAAIgF,EAAG,CAAC,CAC9C,CAKO,SAASqD,GAAYzD,EAAkBC,EAAmC,CAC7E,OAAO,MAAM,KAAKX,EAAKU,EAAIC,CAAE,CAAC,CAClC,CAKO,SAASyD,GAAiB1D,EAAkBC,EAAkBK,EAAuC,CACxG,OAAO,MAAM,KAAKD,EAAML,EAAIC,EAAIK,CAAE,CAAC,CACvC","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 const it = iter(iterable);\n const r1 = it.next();\n if (r1.done) {\n return;\n }\n\n let chunk = [r1.value];\n\n for (const item of it) {\n chunk.push(item);\n\n if (chunk.length === size) {\n yield chunk;\n chunk = [];\n }\n }\n\n // Yield the remainder, if there is any\n if (chunk.length > 0) {\n yield chunk;\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>(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 { all, enumerate, iter, range } from './builtins';\nimport { flatten } from './more-itertools';\nimport type { Predicate, Primitive } from './types';\nimport { primitiveIdentity } from './utils';\n\nconst SENTINEL = Symbol();\n\nfunction composeAnd(f1: (v1: number) => boolean, f2: (v2: number) => boolean): (v3: number) => boolean {\n return (n: number) => f1(n) && f2(n);\n}\n\nfunction slicePredicate(start: number, stop: number | null, step: number) {\n // istanbul ignore if -- @preserve\n if (start < 0) throw new Error('start cannot be negative');\n // istanbul ignore if -- @preserve\n if (stop !== null && stop < 0) throw new Error('stop cannot be negative');\n // istanbul ignore if -- @preserve\n if (step < 0) throw new Error('step cannot be negative');\n\n let pred = (n: number) => n >= start;\n\n if (stop !== null) {\n const definedStop = stop;\n pred = composeAnd(pred, (n: number) => n < definedStop);\n }\n\n if (step > 1) {\n pred = composeAnd(pred, (n: number) => (n - start) % step === 0);\n }\n\n return pred;\n}\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 for (const value of it) {\n if (!predicate(value)) {\n yield value;\n break;\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>(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 const pred = slicePredicate(start, stop, step);\n for (const [i, value] of enumerate(iterable)) {\n if (pred(i)) {\n yield 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 (all(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 for (const value of iterable) {\n if (!predicate(value)) return;\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 { imap } from './itertools';\nimport { flatten } from './more-itertools';\nimport type { Predicate } from './types';\n\nfunction isDefined<T>(x: T): boolean {\n return x !== undefined;\n}\n\n/**\n * Returns an iterable, filtering out any `undefined` values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3])\n * [1, 2, 3]\n */\nexport function* icompact<T>(iterable: Iterable<T | null | undefined>): Iterable<T> {\n for (const item of iterable) {\n if (item != null) {\n yield item;\n }\n }\n}\n\n/**\n * 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 undefined values from the given object. Returns a new object.\n *\n * >>> compactObject({ a: 1, b: undefined, c: 0 })\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 * Returns the first item in the iterable for which the predicate holds, if\n * any. If no such item exists, `undefined` is returned. The default\n * predicate is any defined value.\n */\nexport function find<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n const fn = keyFn || isDefined;\n for (const value of iterable) {\n if (fn(value)) {\n return value;\n }\n }\n return undefined;\n}\n\n/**\n * Returns the first item in the iterable for which the predicate holds, if\n * any. If no such item exists, `undefined` is returned. The default\n * predicate is any defined value.\n */\nexport const first = find;\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","import { first } from './custom';\nimport { 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 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 all<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 any 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 * any([]) // => false\n * any([0]) // => false\n * any([0, 1, null, undefined]) // => true\n *\n * Examples with using a key function:\n *\n * any([1, 4, 5], n => n % 2 === 0) // => true\n * any([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false\n *\n */\nexport function any<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 * 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 any(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>(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 reduce_(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 reduce_(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 */\nexport function range(a: number, ...rest: number[]): Iterable<number> {\n const args = [a, ...rest]; // \"a\" was only used by Flow to make at least one value mandatory\n\n switch (args.length) {\n case 1:\n return _range(0, args[0], 1);\n case 2:\n return _range(args[0], args[1], 1);\n case 3:\n return _range(args[0], args[1], args[2]);\n\n default: {\n // istanbul ignore next -- @preserve\n throw new Error('invalid number of arguments');\n }\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, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O {\n const it = iter(iterable);\n let output = start;\n for (const [index, item] of enumerate(it)) {\n output = reducer(output, item, index);\n }\n return output;\n}\n\n/**\n * See reduce().\n */\nexport function reduce_<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined {\n const it = iter(iterable);\n const start = first(it);\n if (start === undefined) {\n return undefined;\n } else {\n return reduce(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"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/more-itertools.ts","../src/itertools.ts","../src/custom.ts","../src/builtins.ts"],"names":["keyToCmp","keyFn","a","b","ka","kb","identityPredicate","x","numberIdentity","primitiveIdentity","chunked","iterable","size","it","iter","chunk","take","flatten","iterableOfIterables","item","itake","n","count","s","pairwise","first","r1","r2","partition","predicate","good","bad","roundrobin","iters","iterables","map","index","result","heads","round","uniqueEverseen","seen","key","uniqueJustseen","last","SENTINEL","composeAnd","f1","f2","slicePredicate","start","stop","step","pred","definedStop","chain","compress","data","selectors","icompress","cycle","saved","element","dropwhile","value","groupby","currentValue","currentKey","targetKey","grouper","tgtKey","nextVal","d","izip","ifilter","imap","mapper","islice","stopOrStart","possiblyStop","i","enumerate","izip2","xs","ys","ixs","iys","y","izip3","zs","izs","z","izipLongest2","filler","filler_","izipMany","all","h","permutations","r","pool","indices","range","cycles","poolgetter","cleanExit","j","p","q","takewhile","zipLongest2","izipLongest","zipLongest","zipMany","isDefined","icompact","compact","compactObject","obj","value_","find","flatmap","every","some","any","contains","haystack","needle","filter","max","reduce2","min","range_","counter","startOrStop","definitelyStop","reduce","reducer","reduce3","output","sorted","reverse","sum","zip","zip3"],"mappings":"AAIO,SAASA,EAAYC,EAAyC,CACjE,MAAO,CAACC,EAAMC,IAAS,CACnB,IAAMC,EAAKH,EAAMC,CAAC,EACZG,EAAKJ,EAAME,CAAC,EAElB,OAAI,OAAOC,GAAO,WAAa,OAAOC,GAAO,UAClCD,IAAOC,EAAK,EAAI,CAACD,GAAMC,EAAK,GAAK,EACjC,OAAOD,GAAO,UAAY,OAAOC,GAAO,SACxCD,EAAKC,EACL,OAAOD,GAAO,UAAY,OAAOC,GAAO,SACxCD,IAAOC,EAAK,EAAID,EAAKC,EAAK,GAAK,EAE/B,EAEf,CACJ,CAEO,SAASC,EAAkBC,EAAqB,CACnD,MAAO,CAAC,CAACA,CACb,CAEO,SAASC,EAAeD,EAAoB,CAE/C,GAAI,OAAOA,GAAM,SACb,MAAM,IAAI,MAAM,wBAAwB,EAE5C,OAAOA,CACX,CAIO,SAASE,EAAkBF,EAAuB,CAErD,GAAI,OAAOA,GAAM,UAAY,OAAOA,GAAM,UAAY,OAAOA,GAAM,UAC/D,MAAM,IAAI,MAAM,kEAAkE,EAEtF,OAAOA,CACX,CCxBO,SAAUG,EAAWC,EAAuBC,EAA6B,CAC5E,GAAIA,EAAO,EACP,MAAM,IAAI,MAAM,uBAAuBA,GAAM,EAGjD,IAAMC,EAAKC,EAAKH,CAAQ,EACxB,OAAS,CACL,IAAMI,EAAQC,EAAKJ,EAAMC,CAAE,EAI3B,GAHIE,EAAM,OAAS,IACf,MAAMA,GAENA,EAAM,OAASH,EACf,OAGZ,CASO,SAAUK,EAAWC,EAAyD,CACjF,QAAWP,KAAYO,EACnB,QAAWC,KAAQR,EACf,MAAMQ,CAGlB,CAmBO,SAAUC,EAASC,EAAWV,EAAoC,CACrE,IAAME,EAA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7E,OAAO,MAAM,KAAKX,EAAKU,EAAIC,CAAE,CAAC,CAClC,CAKO,SAAS4D,GAAiB7D,EAAkBC,EAAkBK,EAAuC,CACxG,OAAO,MAAM,KAAKD,EAAML,EAAIC,EAAIK,CAAE,CAAC,CACvC","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 { all, enumerate, iter, range } from './builtins';\nimport { flatten } from './more-itertools';\nimport type { Predicate, Primitive } from './types';\nimport { primitiveIdentity } from './utils';\n\nconst SENTINEL = Symbol();\n\nfunction composeAnd(f1: (v1: number) => boolean, f2: (v2: number) => boolean): (v3: number) => boolean {\n return (n: number) => f1(n) && f2(n);\n}\n\nfunction slicePredicate(start: number, stop: number | null, step: number) {\n // istanbul ignore if -- @preserve\n if (start < 0) throw new Error('start cannot be negative');\n // istanbul ignore if -- @preserve\n if (stop !== null && stop < 0) throw new Error('stop cannot be negative');\n // istanbul ignore if -- @preserve\n if (step < 0) throw new Error('step cannot be negative');\n\n let pred = (n: number) => n >= start;\n\n if (stop !== null) {\n const definedStop = stop;\n pred = composeAnd(pred, (n: number) => n < definedStop);\n }\n\n if (step > 1) {\n pred = composeAnd(pred, (n: number) => (n - start) % step === 0);\n }\n\n return pred;\n}\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 for (const value of it) {\n if (!predicate(value)) {\n yield value;\n break;\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 const pred = slicePredicate(start, stop, step);\n for (const [i, value] of enumerate(iterable)) {\n if (pred(i)) {\n yield 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 (all(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 for (const value of iterable) {\n if (!predicate(value)) return;\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 { imap } from './itertools';\nimport { flatten } from './more-itertools';\nimport type { Predicate } from './types';\n\nfunction isDefined<T>(x: T): boolean {\n return x !== undefined;\n}\n\n/**\n * Returns an iterable, filtering out any `undefined` values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3])\n * [1, 2, 3]\n */\nexport function* icompact<T>(iterable: Iterable<T | null | undefined>): Iterable<T> {\n for (const item of iterable) {\n if (item != null) {\n yield item;\n }\n }\n}\n\n/**\n * 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 undefined values from the given object. Returns a new object.\n *\n * >>> compactObject({ a: 1, b: undefined, c: 0 })\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 * 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 if (keyFn === undefined) {\n for (const value of iterable) {\n return value;\n }\n return undefined;\n } else {\n for (const value of iterable) {\n if (keyFn(value)) {\n return value;\n }\n }\n return undefined;\n }\n}\n\n/**\n * Almost an alias of find(). The key difference is that if an empty\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","import { first } from './custom';\nimport { 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 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 any 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 * any([]) // => false\n * any([0]) // => false\n * any([0, 1, null, undefined]) // => true\n *\n * Examples with using a key function:\n *\n * any([1, 4, 5], n => n % 2 === 0) // => true\n * any([{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 any(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 = first(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"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function k(t){return(e,r)=>{let n=t(e),i=t(r);return typeof n=="boolean"&&typeof i=="boolean"?n===i?0:!n&&i?-1:1:typeof n=="number"&&typeof i=="number"?n-i:typeof n=="string"&&typeof i=="string"?n===i?0:n<i?-1:1:-1}}function I(t){return!!t}function x(t){if(typeof t!="number")throw new Error("Inputs must be numbers");return t}function T(t){if(typeof t!="string"&&typeof t!="number"&&typeof t!="boolean")throw new Error("Please provide a key function that can establish object identity");return t}function*Q(t,e){if(e<1)throw new Error(`Invalid chunk size: ${e}`);let r=a(t);for(;;){let n=V(e,r);if(n.length>0&&(yield n),n.length<e)return}}function*s(t){for(let e of t)for(let r of e)yield r}function*O(t,e){let r=a(e),n=t;for(;n-- >0;){let i=r.next();if(!i.done)yield i.value;else return}}function*U(t){let e=a(t),r=e.next();if(r.done)return;let n=r.value;for(let i of e)yield[n,i],n=i}function W(t,e){let r=[],n=[];for(let i of t)e(i)?r.push(i):n.push(i);return[r,n]}function*X(...t){let e=m(t,a);for(;e.length>0;){let r=0;for(;r<e.length;){let i=e[r].next();i.done?e.splice(r,1):(yield i.value,r++)}}}function*Y(...t){let e=m(t,a);for(;e.length>0;){let r=0,n=[];for(;r<e.length;){let o=e[r].next();o.done?e.splice(r,1):(n.push(o.value),r++)}n.length>0&&(yield n)}}function V(t,e){return Array.from(O(t,e))}function*Z(t,e=T){let r=new Set;for(let n of t){let i=e(n);r.has(i)||(r.add(i),yield n)}}function*F(t,e=T){let r;for(let n of t){let i=e(n);i!==r&&(yield n,r=i)}}var K=Symbol();function E(t,e){return r=>t(r)&&e(r)}function ee(t,e,r){if(t<0)throw new Error("start cannot be negative");if(e!==null&&e<0)throw new Error("stop cannot be negative");if(r<0)throw new Error("step cannot be negative");let n=i=>i>=t;if(e!==null){let i=e;n=E(n,o=>o<i)}return r>1&&(n=E(n,i=>(i-t)%r===0)),n}function te(...t){return s(t)}function*y(t=0,e=1){let r=t;for(;;)yield r,r+=e}function re(t,e){return Array.from(N(t,e))}function*ne(t){let e=[];for(let r of t)yield r,e.push(r);for(;e.length>0;)for(let r of e)yield r}function*ie(t,e){let r=a(t);for(let n of r)if(!e(n)){yield n;break}for(let n of r)yield n}function*oe(t,e=T){let r=a(t),n,i=K,o=i,l=function*(c){for(;i===c;){yield n;let f=r.next();if(f.done)return;n=f.value,i=e(n)}};for(;;){for(;i===o;){let u=r.next();if(u.done){i=K;return}n=u.value,i=e(n)}o=i,yield[i,l(o)]}}function*N(t,e){for(let[r,n]of d(t,e))n&&(yield r)}function*v(t,e){for(let r of t)e(r)&&(yield r)}function*p(t,e){for(let r of t)yield e(r)}function*ae(t,e,r,n=1){let i,o;r!==void 0?(i=e,o=r):(i=0,o=e);let l=ee(i,o,n);for(let[u,c]of w(t))l(u)&&(yield c)}function*L(t,e){let r=a(t),n=a(e);for(;;){let i=r.next(),o=n.next();if(!i.done&&!o.done)yield[i.value,o.value];else return}}function*g(t,e,r){let n=a(t),i=a(e),o=a(r);for(;;){let l=n.next(),u=i.next(),c=o.next();if(!l.done&&!u.done&&!c.done)yield[l.value,u.value,c.value];else return}}var d=L;function*j(t,e,r){let n=r,i=a(t),o=a(e);for(;;){let l=i.next(),u=o.next();if(l.done&&u.done)return;yield[l.done?n:l.value,u.done?n:u.value]}}function*q(...t){let e=t.map(a);for(;;){let r=e.map(n=>n.next());if(P(r,n=>!n.done))yield r.map(n=>n.value);else return}}function*le(t,e){let r=Array.from(t),n=r.length,i=e===void 0?n:e;if(i>n)return;let o=Array.from(b(n)),l=Array.from(b(n,n-i,-1)),u=c=>r[c];for(yield o.slice(0,i).map(u);n>0;){let c=!0;for(let f of b(i-1,-1,-1))if(l[f]-=1,l[f]===0)o=o.slice(0,f).concat(o.slice(f+1)).concat(o.slice(f,f+1)),l[f]=n-f;else{let D=l[f],[B,H]=[o[o.length-D],o[f]];o[f]=B,o[o.length-D]=H,yield o.slice(0,i).map(u),c=!1;break}if(c)return}}function*h(t,e){for(let r of t){if(!e(r))return;yield r}}function ue(t,e,r){return Array.from(j(t,e,r))}var fe=j,ce=ue;function Te(...t){return Array.from(q(...t))}function se(t){return t!==void 0}function*_(t){for(let e of t)e!=null&&(yield e)}function be(t){return Array.from(_(t))}function pe(t){let e={};for(let[r,n]of Object.entries(t)){let i=n;i!=null&&(e[r]=i)}return e}function C(t,e){if(e===void 0){for(let r of t)return r;return}else{for(let r of t)if(e(r))return r;return}}function z(t,e){return C(t,e!=null?e:se)}function me(t,e){return s(p(t,e))}function R(t,e=I){for(let r of t)if(!e(r))return!1;return!0}function S(t,e=I){for(let r of t)if(e(r))return!0;return!1}var P=R,G=S;function de(t,e){return G(t,r=>r===e)}function*w(t,e=0){let r=e;for(let n of t)yield[r++,n]}function Ie(t,e){return Array.from(v(t,e))}function a(t){return t[Symbol.iterator]()}function m(t,e){return Array.from(p(t,e))}function xe(t,e=x){return A(t,(r,n)=>e(r)>e(n)?r:n)}function ye(t,e=x){return A(t,(r,n)=>e(r)<e(n)?r:n)}function M(t,e,r){let n=y(t,r),i=r>=0?o=>o<e:o=>o>e;return h(n,i)}function b(t,e,r=1){return e!==void 0?M(t,e,r):M(0,t,r)}function J(t,e,r){return r===void 0?A(t,e):$(t,e,r)}function $(t,e,r){let n=r,i=0;for(let o of t)n=e(n,o,i++);return n}function A(t,e){let r=a(t),n=z(r);if(n!==void 0)return $(r,e,n)}function ve(t,e=T,r=!1){let n=Array.from(t);return n.sort(k(e)),r&&n.reverse(),n}function ge(t){return J(t,(e,r)=>e+r,0)}function he(t,e){return Array.from(d(t,e))}function Pe(t,e,r){return Array.from(g(t,e,r))}export{P as all,G as any,te as chain,Q as chunked,be as compact,pe as compactObject,re as compress,de as contains,y as count,ne as cycle,ie as dropwhile,w as enumerate,R as every,Ie as filter,C as find,z as first,me as flatmap,s as flatten,oe as groupby,Y as heads,_ as icompact,N as icompress,v as ifilter,p as imap,ae as islice,O as itake,a as iter,d as izip,L as izip2,g as izip3,fe as izipLongest,q as izipMany,m as map,xe as max,ye as min,U as pairwise,W as partition,le as permutations,b as range,J as reduce,X as roundrobin,S as some,ve as sorted,ge as sum,V as take,h as takewhile,Z as uniqueEverseen,F as uniqueJustseen,he as zip,Pe as zip3,ce as zipLongest,Te as zipMany};
|
|
2
2
|
// istanbul ignore else -- @preserve
|
|
3
3
|
// istanbul ignore if -- @preserve
|
|
4
|
-
// istanbul ignore next -- @preserve
|
|
5
4
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/more-itertools.ts","../src/itertools.ts","../src/custom.ts","../src/builtins.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 const it = iter(iterable);\n const r1 = it.next();\n if (r1.done) {\n return;\n }\n\n let chunk = [r1.value];\n\n for (const item of it) {\n chunk.push(item);\n\n if (chunk.length === size) {\n yield chunk;\n chunk = [];\n }\n }\n\n // Yield the remainder, if there is any\n if (chunk.length > 0) {\n yield chunk;\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>(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 { all, enumerate, iter, range } from './builtins';\nimport { flatten } from './more-itertools';\nimport type { Predicate, Primitive } from './types';\nimport { primitiveIdentity } from './utils';\n\nconst SENTINEL = Symbol();\n\nfunction composeAnd(f1: (v1: number) => boolean, f2: (v2: number) => boolean): (v3: number) => boolean {\n return (n: number) => f1(n) && f2(n);\n}\n\nfunction slicePredicate(start: number, stop: number | null, step: number) {\n // istanbul ignore if -- @preserve\n if (start < 0) throw new Error('start cannot be negative');\n // istanbul ignore if -- @preserve\n if (stop !== null && stop < 0) throw new Error('stop cannot be negative');\n // istanbul ignore if -- @preserve\n if (step < 0) throw new Error('step cannot be negative');\n\n let pred = (n: number) => n >= start;\n\n if (stop !== null) {\n const definedStop = stop;\n pred = composeAnd(pred, (n: number) => n < definedStop);\n }\n\n if (step > 1) {\n pred = composeAnd(pred, (n: number) => (n - start) % step === 0);\n }\n\n return pred;\n}\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 for (const value of it) {\n if (!predicate(value)) {\n yield value;\n break;\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>(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 const pred = slicePredicate(start, stop, step);\n for (const [i, value] of enumerate(iterable)) {\n if (pred(i)) {\n yield 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 (all(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 for (const value of iterable) {\n if (!predicate(value)) return;\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 { imap } from './itertools';\nimport { flatten } from './more-itertools';\nimport type { Predicate } from './types';\n\nfunction isDefined<T>(x: T): boolean {\n return x !== undefined;\n}\n\n/**\n * Returns an iterable, filtering out any `undefined` values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3])\n * [1, 2, 3]\n */\nexport function* icompact<T>(iterable: Iterable<T | null | undefined>): Iterable<T> {\n for (const item of iterable) {\n if (item != null) {\n yield item;\n }\n }\n}\n\n/**\n * 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 undefined values from the given object. Returns a new object.\n *\n * >>> compactObject({ a: 1, b: undefined, c: 0 })\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 * Returns the first item in the iterable for which the predicate holds, if\n * any. If no such item exists, `undefined` is returned. The default\n * predicate is any defined value.\n */\nexport function find<T>(iterable: Iterable<T>, keyFn?: Predicate<T>): T | undefined {\n const fn = keyFn || isDefined;\n for (const value of iterable) {\n if (fn(value)) {\n return value;\n }\n }\n return undefined;\n}\n\n/**\n * Returns the first item in the iterable for which the predicate holds, if\n * any. If no such item exists, `undefined` is returned. The default\n * predicate is any defined value.\n */\nexport const first = find;\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","import { first } from './custom';\nimport { 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 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 all<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 any 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 * any([]) // => false\n * any([0]) // => false\n * any([0, 1, null, undefined]) // => true\n *\n * Examples with using a key function:\n *\n * any([1, 4, 5], n => n % 2 === 0) // => true\n * any([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false\n *\n */\nexport function any<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 * 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 any(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>(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 reduce_(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 reduce_(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 */\nexport function range(a: number, ...rest: number[]): Iterable<number> {\n const args = [a, ...rest]; // \"a\" was only used by Flow to make at least one value mandatory\n\n switch (args.length) {\n case 1:\n return _range(0, args[0], 1);\n case 2:\n return _range(args[0], args[1], 1);\n case 3:\n return _range(args[0], args[1], args[2]);\n\n default: {\n // istanbul ignore next -- @preserve\n throw new Error('invalid number of arguments');\n }\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, O>(iterable: Iterable<T>, reducer: (agg: O, item: T, index: number) => O, start: O): O {\n const it = iter(iterable);\n let output = start;\n for (const [index, item] of enumerate(it)) {\n output = reducer(output, item, index);\n }\n return output;\n}\n\n/**\n * See reduce().\n */\nexport function reduce_<T>(iterable: Iterable<T>, reducer: (agg: T, item: T, index: number) => T): T | undefined {\n const it = iter(iterable);\n const start = first(it);\n if (start === undefined) {\n return undefined;\n } else {\n return reduce(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"],"mappings":"AAIO,SAASA,EAAYC,EAAyC,CACjE,MAAO,CAACC,EAAMC,IAAS,CACnB,IAAMC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,CACjD,CACJ,CACJ,CAuBO,SAASC,EAAarC,EAAuBsC,EAAgD5B,EAAa,CAC7G,IAAM6B,EAAKvB,EAAKhB,CAAQ,EACpBwC,EAAS9B,EACb,OAAW,CAACC,EAAOR,CAAI,IAAKM,EAAU8B,CAAE,EACpCC,EAASF,EAAQE,EAAQrC,EAAMQ,CAAK,EAExC,OAAO6B,CACX,CAKO,SAASlB,EAAWtB,EAAuBsC,EAA+D,CAC7G,IAAMC,EAAKvB,EAAKhB,CAAQ,EAClBU,EAAQ+B,EAAMF,CAAE,EACtB,GAAI7B,IAAU,OAGV,OAAO2B,EAAOE,EAAID,EAAS5B,CAAK,CAExC,CAeO,SAASgC,GACZ1C,EACAC,EAAgC0C,EAChCC,EAAU,GACP,CACH,IAAMC,EAAS,MAAM,KAAK7C,CAAQ,EAClC,OAAA6C,EAAO,KAAKC,EAAS7C,CAAK,CAAC,EAEvB2C,GACAC,EAAO,QAAQ,EAGZA,CACX,CAMO,SAASE,GAAI/C,EAAoC,CACpD,OAAOqC,EAAOrC,EAAU,CAACQ,EAAGe,IAAMf,EAAIe,EAAG,CAAC,CAC9C,CAKO,SAASyB,GAAYC,EAAkBC,EAAmC,CAC7E,OAAO,MAAM,KAAKC,EAAKF,EAAIC,CAAE,CAAC,CAClC,CAKO,SAASE,GAAiBH,EAAkBC,EAAkBG,EAAuC,CACxG,OAAO,MAAM,KAAKC,EAAML,EAAIC,EAAIG,CAAE,CAAC,CACvC","names":["keyToCmp","keyFn","a","b","ka","kb","identityPredicate","x","numberIdentity","primitiveIdentity","chunked","iterable","size","it","iter","r1","chunk","item","flatten","iterableOfIterables","itake","n","iterable","it","iter","count","s","pairwise","first","r1","r2","partition","predicate","good","bad","item","roundrobin","iters","iterables","map","index","result","heads","round","take","uniqueEverseen","keyFn","primitiveIdentity","seen","key","uniqueJustseen","last","SENTINEL","composeAnd","f1","f2","n","slicePredicate","start","stop","step","pred","definedStop","chain","iterables","flatten","count","compress","data","selectors","icompress","cycle","iterable","saved","element","dropwhile","predicate","it","iter","value","groupby","keyFn","primitiveIdentity","currentValue","currentKey","targetKey","grouper","tgtKey","nextVal","d","s","izip","ifilter","imap","mapper","islice","stopOrStart","possiblyStop","i","enumerate","izip2","xs","ys","ixs","iys","x","y","izip3","zs","izs","z","izipLongest2","filler","filler_","izipMany","iters","iterables","iter","heads","xs","all","h","permutations","iterable","pool","x","indices","range","cycles","poolgetter","i","cleanExit","j","p","q","takewhile","iterable","predicate","value","zipLongest2","xs","ys","filler","izipLongest2","izipLongest","izipLongest2","zipLongest","zipLongest2","zipMany","iters","izipMany","isDefined","x","icompact","iterable","item","compact","compactObject","obj","result","key","value_","value","find","keyFn","fn","first","flatmap","mapper","flatten","imap","all","iterable","keyFn","identityPredicate","item","any","contains","haystack","needle","x","enumerate","start","index","value","filter","predicate","ifilter","iter","map","mapper","imap","max","numberIdentity","reduce_","y","min","_range","stop","step","counter","count","pred","n","takewhile","range","a","rest","args","reduce","reducer","it","output","first","sorted","primitiveIdentity","reverse","result","keyToCmp","sum","zip","xs","ys","izip","zip3","zs","izip3"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/more-itertools.ts","../src/itertools.ts","../src/custom.ts","../src/builtins.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 { all, enumerate, iter, range } from './builtins';\nimport { flatten } from './more-itertools';\nimport type { Predicate, Primitive } from './types';\nimport { primitiveIdentity } from './utils';\n\nconst SENTINEL = Symbol();\n\nfunction composeAnd(f1: (v1: number) => boolean, f2: (v2: number) => boolean): (v3: number) => boolean {\n return (n: number) => f1(n) && f2(n);\n}\n\nfunction slicePredicate(start: number, stop: number | null, step: number) {\n // istanbul ignore if -- @preserve\n if (start < 0) throw new Error('start cannot be negative');\n // istanbul ignore if -- @preserve\n if (stop !== null && stop < 0) throw new Error('stop cannot be negative');\n // istanbul ignore if -- @preserve\n if (step < 0) throw new Error('step cannot be negative');\n\n let pred = (n: number) => n >= start;\n\n if (stop !== null) {\n const definedStop = stop;\n pred = composeAnd(pred, (n: number) => n < definedStop);\n }\n\n if (step > 1) {\n pred = composeAnd(pred, (n: number) => (n - start) % step === 0);\n }\n\n return pred;\n}\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 for (const value of it) {\n if (!predicate(value)) {\n yield value;\n break;\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 const pred = slicePredicate(start, stop, step);\n for (const [i, value] of enumerate(iterable)) {\n if (pred(i)) {\n yield 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 (all(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 for (const value of iterable) {\n if (!predicate(value)) return;\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 { imap } from './itertools';\nimport { flatten } from './more-itertools';\nimport type { Predicate } from './types';\n\nfunction isDefined<T>(x: T): boolean {\n return x !== undefined;\n}\n\n/**\n * Returns an iterable, filtering out any `undefined` values from the iterable.\n *\n * >>> compact([1, 2, undefined, 3])\n * [1, 2, 3]\n */\nexport function* icompact<T>(iterable: Iterable<T | null | undefined>): Iterable<T> {\n for (const item of iterable) {\n if (item != null) {\n yield item;\n }\n }\n}\n\n/**\n * 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 undefined values from the given object. Returns a new object.\n *\n * >>> compactObject({ a: 1, b: undefined, c: 0 })\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 * 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 if (keyFn === undefined) {\n for (const value of iterable) {\n return value;\n }\n return undefined;\n } else {\n for (const value of iterable) {\n if (keyFn(value)) {\n return value;\n }\n }\n return undefined;\n }\n}\n\n/**\n * Almost an alias of find(). The key difference is that if an empty\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","import { first } from './custom';\nimport { 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 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 any 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 * any([]) // => false\n * any([0]) // => false\n * any([0, 1, null, undefined]) // => true\n *\n * Examples with using a key function:\n *\n * any([1, 4, 5], n => n % 2 === 0) // => true\n * any([{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 any(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 = first(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"],"mappings":"AAIO,SAASA,EAAYC,EAAyC,CACjE,MAAO,CAACC,EAAMC,IAAS,CACnB,IAAMC,EAAKH,EAAMC,CAAC,EACZG,EAAKJ,EAAME,CAAC,EAElB,OAAI,OAAOC,GAAO,WAAa,OAAOC,GAAO,UAClCD,IAAOC,EAAK,EAAI,CAACD,GAAMC,EAAK,GAAK,EACjC,OAAOD,GAAO,UAAY,OAAOC,GAAO,SACxCD,EAAKC,EACL,OAAOD,GAAO,UAAY,OAAOC,GAAO,SACxCD,IAAOC,EAAK,EAAID,EAAKC,EAAK,GAAK,EAE/B,EAEf,CACJ,CAEO,SAASC,EAAkBC,EAAqB,CACnD,MAAO,CAAC,CAACA,CACb,CAEO,SAASC,EAAeD,EAAoB,CAE/C,GAAI,OAAOA,GAAM,SACb,MAAM,IAAI,MAAM,wBAAwB,EAE5C,OAAOA,CACX,CAIO,SAASE,EAAkBF,EAAuB,CAErD,GAAI,OAAOA,GAAM,UAAY,OAAOA,GAAM,UAAY,OAAOA,GAAM,UAC/D,MAAM,IAAI,MAAM,kEAAkE,EAEtF,OAAOA,CACX,CCxBO,SAAUG,EAAWC,EAAuBC,EAA6B,CAC5E,GAAIA,EAAO,EACP,MAAM,IAAI,MAAM,uBAAuBA,GAAM,EAGjD,IAAMC,EAAKC,EAAKH,CAAQ,EACxB,OAAS,CACL,IAAMI,EAAQC,EAAKJ,EAAMC,CAAE,EAI3B,GAHIE,EAAM,OAAS,IACf,MAAMA,GAENA,EAAM,OAASH,EACf,OAGZ,CASO,SAAUK,EAAWC,EAAyD,CACjF,QAAWP,KAAYO,EACnB,QAAWC,KAAQR,EACf,MAAMQ,CAGlB,CAmBO,SAAUC,EAASC,EAAWC,EAAoC,CACrE,IAAMC,EAAKC,E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,EAAO,EAAqB,CAC5F,OAAIQ,IAAmB,OACZV,EAAOS,EAA4BC,EAAgBR,CAAI,EAEvDF,EAAO,EAAGS,EAA2BP,CAAI,CAExD,CAyBO,SAASS,EACZtC,EACAuC,EACA3B,EACmB,CACnB,OAAIA,IAAU,OACHY,EAAQxB,EAAUuC,CAAgD,EAElEC,EAAQxC,EAAUuC,EAAkD3B,CAAK,CAExF,CAEA,SAAS4B,EAAcxC,EAAuBuC,EAAgD3B,EAAa,CACvG,IAAI6B,EAAS7B,EACTC,EAAQ,EACZ,QAAWV,KAAQH,EACfyC,EAASF,EAAQE,EAAQtC,EAAMU,GAAO,EAE1C,OAAO4B,CACX,CAEA,SAASjB,EAAWxB,EAAuBuC,EAA+D,CACtG,IAAMG,EAAKxB,EAAKlB,CAAQ,EAClBY,EAAQ+B,EAAMD,CAAE,EACtB,GAAI9B,IAAU,OAGV,OAAO4B,EAAQE,EAAIH,EAAS3B,CAAK,CAEzC,CAeO,SAASgC,GACZ5C,EACAC,EAAgC4C,EAChCC,EAAU,GACP,CACH,IAAMC,EAAS,MAAM,KAAK/C,CAAQ,EAClC,OAAA+C,EAAO,KAAKC,EAAS/C,CAAK,CAAC,EAEvB6C,GACAC,EAAO,QAAQ,EAGZA,CACX,CAMO,SAASE,GAAIjD,EAAoC,CACpD,OAAOsC,EAAOtC,EAAU,CAACU,EAAGe,IAAMf,EAAIe,EAAG,CAAC,CAC9C,CAKO,SAASyB,GAAYC,EAAkBC,EAAmC,CAC7E,OAAO,MAAM,KAAKC,EAAKF,EAAIC,CAAE,CAAC,CAClC,CAKO,SAASE,GAAiBH,EAAkBC,EAAkBG,EAAuC,CACxG,OAAO,MAAM,KAAKC,EAAML,EAAIC,EAAIG,CAAE,CAAC,CACvC","names":["keyToCmp","keyFn","a","b","ka","kb","identityPredicate","x","numberIdentity","primitiveIdentity","chunked","iterable","size","it","iter","chunk","take","flatten","iterableOfIterables","item","itake","n","iterable","it","iter","count","s","pairwise","first","r1","r2","partition","predicate","good","bad","item","roundrobin","iters","iterables","map","index","result","heads","round","take","uniqueEverseen","keyFn","primitiveIdentity","seen","key","uniqueJustseen","last","SENTINEL","composeAnd","f1","f2","n","slicePredicate","start","stop","step","pred","definedStop","chain","iterables","flatten","count","compress","data","selectors","icompress","cycle","iterable","saved","element","dropwhile","predicate","it","iter","value","groupby","keyFn","primitiveIdentity","currentValue","currentKey","targetKey","grouper","tgtKey","nextVal","d","s","izip","ifilter","imap","mapper","islice","stopOrStart","possiblyStop","i","enumerate","izip2","xs","ys","ixs","iys","x","y","izip3","zs","izs","z","izipLongest2","filler","filler_","izipMany","iters","iterables","iter","heads","xs","all","h","permutations","iterable","r","pool","x","indices","range","cycles","poolgetter","i","cleanExit","j","p","q","takewhile","iterable","predicate","value","zipLongest2","xs","ys","filler","izipLongest2","izipLongest","izipLongest2","zipLongest","zipLongest2","zipMany","iters","izipMany","isDefined","x","icompact","iterable","item","compact","compactObject","obj","result","key","value_","value","find","keyFn","first","flatmap","mapper","flatten","imap","every","iterable","keyFn","identityPredicate","item","some","all","any","contains","haystack","needle","x","enumerate","start","index","value","filter","predicate","ifilter","iter","map","mapper","imap","max","numberIdentity","reduce2","y","min","range_","stop","step","counter","count","pred","n","takewhile","range","startOrStop","definitelyStop","reduce","reducer","reduce3","output","it","first","sorted","primitiveIdentity","reverse","result","keyToCmp","sum","zip","xs","ys","izip","zip3","zs","izip3"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itertools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A JavaScript port of Python's awesome itertools standard library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -51,13 +51,14 @@
|
|
|
51
51
|
"@types/jest": "^29.5.0",
|
|
52
52
|
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
53
53
|
"@typescript-eslint/parser": "^5.57.1",
|
|
54
|
-
"@vitest/coverage-istanbul": "^0.
|
|
54
|
+
"@vitest/coverage-istanbul": "^0.29.8",
|
|
55
55
|
"eslint": "^8.38.0",
|
|
56
|
+
"fast-check": "^3.8.0",
|
|
56
57
|
"in-publish": "^2.0.1",
|
|
57
58
|
"prettier": "^2.8.7",
|
|
58
59
|
"tsup": "^6.7.0",
|
|
59
60
|
"typescript": "^4.3.5",
|
|
60
|
-
"vitest": "^0.
|
|
61
|
+
"vitest": "^0.29.8"
|
|
61
62
|
},
|
|
62
63
|
"githubUrl": "https://github.com/nvie/itertools",
|
|
63
64
|
"sideEffects": false
|