itertools 2.0.0 → 2.1.1
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 +214 -257
- package/dist/index.d.mts +36 -15
- package/dist/index.d.ts +42 -21
- 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];
|
|
@@ -22,13 +21,12 @@ Usage example:
|
|
|
22
21
|
4 'there'
|
|
23
22
|
```
|
|
24
23
|
|
|
25
|
-
|
|
26
24
|
## About argument order
|
|
27
25
|
|
|
28
|
-
In Python, many of the itertools take a function as an argument.
|
|
26
|
+
In Python, many of the itertools take a function as an argument. In the JS
|
|
29
27
|
port of these we initially kept these orderings the same to stick closely to
|
|
30
28
|
the Python functions, but in practice, it turns out to be more pragmatic to
|
|
31
|
-
flip them, so the function gets to be the second param.
|
|
29
|
+
flip them, so the function gets to be the second param. Example:
|
|
32
30
|
|
|
33
31
|
In Python:
|
|
34
32
|
|
|
@@ -46,18 +44,16 @@ The rationale for this flipping of argument order is because in practice, the
|
|
|
46
44
|
function bodies can span multiple lines, in which case the following block will
|
|
47
45
|
remaing aesthetically pleasing:
|
|
48
46
|
|
|
49
|
-
```
|
|
47
|
+
```ts
|
|
50
48
|
import { map } from 'itertools';
|
|
51
49
|
|
|
52
50
|
const numbers = [1, 2, 3];
|
|
53
|
-
const squares = map(numbers, n => {
|
|
54
|
-
|
|
51
|
+
const squares = map(numbers, (n) => {
|
|
55
52
|
//
|
|
56
53
|
// Do something wild with these numbers here
|
|
57
54
|
//
|
|
58
55
|
// ...
|
|
59
56
|
return n * n;
|
|
60
|
-
|
|
61
57
|
});
|
|
62
58
|
```
|
|
63
59
|
|
|
@@ -65,129 +61,121 @@ const squares = map(numbers, n => {
|
|
|
65
61
|
|
|
66
62
|
The `itertools` package consists of a few building blocks:
|
|
67
63
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
- [Ports of builtins](#ports-of-builtins)
|
|
65
|
+
- [Ports of itertools](#ports-of-itertools)
|
|
66
|
+
- [Ports of more-itertools](#ports-of-more-itertools)
|
|
67
|
+
- [Additions](#additions)
|
|
73
68
|
|
|
74
69
|
### Ports of builtins
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
Returns true when all of the items in iterable are truthy. An optional key
|
|
71
|
+
- [every](#every)
|
|
72
|
+
- [some](#some)
|
|
73
|
+
- [contains](#contains)
|
|
74
|
+
- [enumerate](#enumerate)
|
|
75
|
+
- [filter](#filter)
|
|
76
|
+
- [iter](#iter)
|
|
77
|
+
- [map](#map)
|
|
78
|
+
- [max](#max)
|
|
79
|
+
- [min](#min)
|
|
80
|
+
- [range](#range)
|
|
81
|
+
- [reduce](#reduce)
|
|
82
|
+
- [sorted](#sorted)
|
|
83
|
+
- [sum](#sum)
|
|
84
|
+
- [zip](#zip)
|
|
85
|
+
- [zip3](#zip3)
|
|
86
|
+
|
|
87
|
+
<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')
|
|
88
|
+
|
|
89
|
+
Returns true when every of the items in iterable are truthy. An optional key
|
|
96
90
|
function can be used to define what truthiness means for this specific
|
|
97
91
|
collection.
|
|
98
92
|
|
|
99
93
|
Examples:
|
|
100
94
|
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
```ts
|
|
96
|
+
every([]); // => true
|
|
97
|
+
every([0]); // => false
|
|
98
|
+
every([0, 1, 2]); // => false
|
|
99
|
+
every([1, 2, 3]); // => true
|
|
106
100
|
```
|
|
107
101
|
|
|
108
102
|
Examples with using a key function:
|
|
109
103
|
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
```ts
|
|
105
|
+
every([2, 4, 6], (n) => n % 2 === 0); // => true
|
|
106
|
+
every([2, 4, 5], (n) => n % 2 === 0); // => false
|
|
113
107
|
```
|
|
114
108
|
|
|
109
|
+
<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')
|
|
115
110
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
Returns true when any of the items in iterable are truthy. An optional key
|
|
111
|
+
Returns true when some of the items in iterable are truthy. An optional key
|
|
119
112
|
function can be used to define what truthiness means for this specific
|
|
120
113
|
collection.
|
|
121
114
|
|
|
122
115
|
Examples:
|
|
123
116
|
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
117
|
+
```ts
|
|
118
|
+
some([]); // => false
|
|
119
|
+
some([0]); // => false
|
|
120
|
+
some([0, 1, null, undefined]); // => true
|
|
128
121
|
```
|
|
129
122
|
|
|
130
123
|
Examples with using a key function:
|
|
131
124
|
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
|
|
125
|
+
```ts
|
|
126
|
+
some([1, 4, 5], (n) => n % 2 === 0); // => true
|
|
127
|
+
some([{ name: 'Bob' }, { name: 'Alice' }], (person) => person.name.startsWith('C')); // => false
|
|
135
128
|
```
|
|
136
129
|
|
|
130
|
+
<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')
|
|
137
131
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
Returns true when any of the items in the iterable are equal to the target
|
|
132
|
+
Returns true when some of the items in the iterable are equal to the target
|
|
141
133
|
object.
|
|
142
134
|
|
|
143
135
|
Examples:
|
|
144
136
|
|
|
145
|
-
```
|
|
146
|
-
contains([], 'whatever')
|
|
147
|
-
contains([3], 42)
|
|
148
|
-
contains([3], 3)
|
|
149
|
-
contains([0, 1, 2], 2)
|
|
137
|
+
```ts
|
|
138
|
+
contains([], 'whatever'); // => false
|
|
139
|
+
contains([3], 42); // => false
|
|
140
|
+
contains([3], 3); // => true
|
|
141
|
+
contains([0, 1, 2], 2); // => true
|
|
150
142
|
```
|
|
151
143
|
|
|
144
|
+
<a name="enumerate" href="#enumerate">#</a> <b>enumerate</b>(iterable: <i>Iterable<T></i>, start: <i>number = 0</i>): <i>Iterable<[number, T]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
152
145
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
Returns an iterable of enumeration pairs. Iterable must be a sequence, an
|
|
156
|
-
iterator, or some other object which supports iteration. The elements produced
|
|
146
|
+
Returns an iterable of enumeration pairs. Iterable must be a sequence, an
|
|
147
|
+
iterator, or some other object which supports iteration. The elements produced
|
|
157
148
|
by returns a tuple containing a counter value (starting from 0 by default) and
|
|
158
149
|
the values obtained from iterating over given iterable.
|
|
159
150
|
|
|
160
151
|
Example:
|
|
161
152
|
|
|
162
|
-
```
|
|
153
|
+
```ts
|
|
163
154
|
import { enumerate } from 'itertools';
|
|
164
155
|
|
|
165
156
|
console.log([...enumerate(['hello', 'world'])]);
|
|
166
157
|
// [0, 'hello'], [1, 'world']]
|
|
167
158
|
```
|
|
168
159
|
|
|
169
|
-
<a name="filter" href="#filter">#</a> <b>filter</b>(iterable: <i>Iterable<T></i>, predicate: <i>Predicate<T></i>): <i>
|
|
160
|
+
<a name="filter" href="#filter">#</a> <b>filter</b>(iterable: <i>Iterable<T></i>, predicate: <i>Predicate<T></i>): <i>T[]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
170
161
|
|
|
171
|
-
|
|
162
|
+
Eager version of [ifilter](#ifilter).
|
|
172
163
|
|
|
164
|
+
<a name="iter" href="#iter">#</a> <b>iter</b>(iterable: <i>Iterable<T></i>): <i>Iterator<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
173
165
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Returns an iterator object for the given iterable. This can be used to
|
|
177
|
-
manually get an iterator for any iterable datastructure. The purpose and main
|
|
166
|
+
Returns an iterator object for the given iterable. This can be used to
|
|
167
|
+
manually get an iterator for any iterable datastructure. The purpose and main
|
|
178
168
|
use case of this function is to get a single iterator (a thing with state,
|
|
179
169
|
think of it as a "cursor") which can only be consumed once.
|
|
180
170
|
|
|
171
|
+
<a name="map" href="#map">#</a> <b>map</b>(iterable: _Iterable<T>_, mapper: _(item: T) => V_): _V[]_ [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
181
172
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Non-lazy version of [imap](#imap).
|
|
173
|
+
Eager version of [imap](#imap).
|
|
185
174
|
|
|
175
|
+
<a name="max" href="#max">#</a> <b>max</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>(item: T) => number</i>): <i>T | undefined</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
186
176
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
Return the largest item in an iterable. Only works for numbers, as ordering is
|
|
190
|
-
pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
177
|
+
Return the largest item in an iterable. Only works for numbers, as ordering is
|
|
178
|
+
pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
191
179
|
argument specifies a one-argument ordering function like that used for
|
|
192
180
|
[sorted](#sorted).
|
|
193
181
|
|
|
@@ -196,11 +184,10 @@ If the iterable is empty, `undefined` is returned.
|
|
|
196
184
|
If multiple items are maximal, the function returns either one of them, but
|
|
197
185
|
which one is not defined.
|
|
198
186
|
|
|
187
|
+
<a name="min" href="#min">#</a> <b>min</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>(item: T) => number</i>): <i>T | undefined</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
199
188
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
Return the smallest item in an iterable. Only works for numbers, as ordering
|
|
203
|
-
is pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
189
|
+
Return the smallest item in an iterable. Only works for numbers, as ordering
|
|
190
|
+
is pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
204
191
|
argument specifies a one-argument ordering function like that used for
|
|
205
192
|
[sorted](#sorted).
|
|
206
193
|
|
|
@@ -209,9 +196,8 @@ If the iterable is empty, `undefined` is returned.
|
|
|
209
196
|
If multiple items are minimal, the function returns either one of them, but
|
|
210
197
|
which one is not defined.
|
|
211
198
|
|
|
212
|
-
|
|
213
|
-
<a name="range" href="#range">#</a> <b>range</b>(start: <i>number</i>): <i>Iterable<number></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js
|
|
214
|
-
<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")
|
|
199
|
+
<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 />
|
|
200
|
+
<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
201
|
|
|
216
202
|
Returns an iterator producing all the numbers in the given range one by one,
|
|
217
203
|
starting from `start` (default 0), as long as `i < stop`, in increments of
|
|
@@ -236,112 +222,107 @@ the stop condition `n > stop` is satisfied.
|
|
|
236
222
|
The produced range will be empty if the first value to produce already does not
|
|
237
223
|
meet the value constraint.
|
|
238
224
|
|
|
239
|
-
|
|
240
|
-
<a name="reduce" href="#reduce">#</a> <b>reduce</b>(iterable: <i>Iterable<T></i>, reducer: <i>(
|
|
241
|
-
<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")
|
|
225
|
+
<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 />
|
|
226
|
+
<a name="reduce" href="#reduce">#</a> <b>reduce</b>(iterable: <i>Iterable<T></i>, reducer: <i>(T, T, number) => T</i>): <i>T | undefined</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
242
227
|
|
|
243
228
|
Apply function of two arguments cumulatively to the items of sequence, from
|
|
244
|
-
left to right, so as to reduce the sequence to a single value.
|
|
229
|
+
left to right, so as to reduce the sequence to a single value. For example:
|
|
245
230
|
|
|
246
|
-
|
|
231
|
+
```ts
|
|
232
|
+
reduce([1, 2, 3, 4, 5], (total, x) => total + x, 0);
|
|
233
|
+
```
|
|
247
234
|
|
|
248
235
|
calculates
|
|
249
236
|
|
|
250
237
|
(((((0+1)+2)+3)+4)+5)
|
|
251
238
|
|
|
252
|
-
The left argument, `
|
|
253
|
-
is the update value from the sequence.
|
|
239
|
+
The left argument, `total`, is the accumulated value and the right argument,
|
|
240
|
+
`x`, is the update value from the sequence.
|
|
254
241
|
|
|
255
|
-
|
|
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.
|
|
242
|
+
Without an explicit initializer arg:
|
|
262
243
|
|
|
244
|
+
```ts
|
|
245
|
+
reduce([1, 2, 3, 4, 5], (total, x) => total + x);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
it calculates
|
|
263
249
|
|
|
264
|
-
|
|
250
|
+
((((1+2)+3)+4)+5)
|
|
251
|
+
|
|
252
|
+
<a name="sorted" href="#sorted">#</a> <b>sorted</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>(item: T) => Primitive</i></i>, reverse?: <i>boolean</i>): <i>T[]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
265
253
|
|
|
266
254
|
Return a new sorted list from the items in iterable.
|
|
267
255
|
|
|
268
256
|
Has two optional arguments:
|
|
269
257
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
* `reverse` is a boolean value. If `true`, then the list elements are sorted
|
|
276
|
-
as if each comparison were reversed.
|
|
258
|
+
- `keyFn` specifies a function of one argument providing a primitive identity
|
|
259
|
+
for each element in the iterable. that will be used to compare. The default
|
|
260
|
+
value is to use a default identity function that is only defined for
|
|
261
|
+
primitive types.
|
|
277
262
|
|
|
263
|
+
- `reverse` is a boolean value. If `true`, then the list elements are sorted
|
|
264
|
+
as if each comparison were reversed.
|
|
278
265
|
|
|
279
|
-
<a name="sum" href="#sum">#</a> <b>sum</b>(iterable: <i>Iterable<number></i>): <i>number</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js
|
|
266
|
+
<a name="sum" href="#sum">#</a> <b>sum</b>(iterable: <i>Iterable<number></i>): <i>number</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
280
267
|
|
|
281
|
-
Sums the items of an iterable from left to right and returns the total.
|
|
268
|
+
Sums the items of an iterable from left to right and returns the total. The
|
|
282
269
|
sum will defaults to 0 if the iterable is empty.
|
|
283
270
|
|
|
271
|
+
<a name="zip" href="#zip">#</a> <b>zip</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>): <i>[T1, T2][]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')<br />
|
|
272
|
+
<a name="zip3" href="#zip3">#</a> <b>zip3</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, zs: <i>Iterable<T3></i>): <i>[T1, T2, T3][]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js 'Source')
|
|
284
273
|
|
|
285
|
-
|
|
286
|
-
<a name="zip3" href="#zip3">#</a> <b>zip3</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, zs: <i>Iterable<T3></i>): <i>Array<[T1, T2, T3]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")
|
|
287
|
-
|
|
288
|
-
Non-lazy version of [izip](#izip) / [izip3](#izip3).
|
|
289
|
-
|
|
274
|
+
Eager version of [izip](#izip) / [izip3](#izip3).
|
|
290
275
|
|
|
291
276
|
### Ports of itertools
|
|
292
277
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
<a name="chain" href="#chain">#</a> <b>chain</b>(...iterables: <i>
|
|
278
|
+
- [chain](#chain)
|
|
279
|
+
- [compress](#compress)
|
|
280
|
+
- [count](#count)
|
|
281
|
+
- [cycle](#cycle)
|
|
282
|
+
- [dropwhile](#dropwhile)
|
|
283
|
+
- [groupby](#groupby)
|
|
284
|
+
- [icompress](#icompress)
|
|
285
|
+
- [ifilter](#ifilter)
|
|
286
|
+
- [imap](#imap)
|
|
287
|
+
- [islice](#islice)
|
|
288
|
+
- [izip](#izip)
|
|
289
|
+
- [izip3](#izip3)
|
|
290
|
+
- [izipLongest](#izipLongest)
|
|
291
|
+
- [izipMany](#izipMany)
|
|
292
|
+
- [permutations](#permutations)
|
|
293
|
+
- [repeat](#repeat)
|
|
294
|
+
- [takewhile](#takewhile)
|
|
295
|
+
- [zipLongest](#zipLongest)
|
|
296
|
+
- [zipMany](#zipMany)
|
|
297
|
+
|
|
298
|
+
<a name="chain" href="#chain">#</a> <b>chain</b>(...iterables: <i>Iterable<T>[]</i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
314
299
|
|
|
315
300
|
Returns an iterator that returns elements from the first iterable until it is
|
|
316
301
|
exhausted, then proceeds to the next iterable, until all of the iterables are
|
|
317
|
-
exhausted.
|
|
318
|
-
|
|
302
|
+
exhausted. Used for treating consecutive sequences as a single sequence.
|
|
319
303
|
|
|
320
|
-
<a name="compress" href="#compress">#</a> <b>compress</b>(iterable: <i>Iterable<T></i>, selectors: <i>Iterable<boolean></i>): <i>
|
|
304
|
+
<a name="compress" href="#compress">#</a> <b>compress</b>(iterable: <i>Iterable<T></i>, selectors: <i>Iterable<boolean></i>): <i>T[]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
321
305
|
|
|
322
|
-
|
|
306
|
+
Eager version of [icompress](#icompress).
|
|
323
307
|
|
|
324
|
-
|
|
325
|
-
<a name="count" href="#count">#</a> <b>count</b>(start: <i>number</i>, step: <i>number</i>): <i>Iterable<number></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
308
|
+
<a name="count" href="#count">#</a> <b>count</b>(start: <i>number</i>, step: <i>number</i>): <i>Iterable<number></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
326
309
|
|
|
327
310
|
Returns an iterator that counts up values starting with number `start` (default
|
|
328
|
-
0), incrementing by `step`.
|
|
329
|
-
|
|
311
|
+
0), incrementing by `step`. To decrement, use a negative step number.
|
|
330
312
|
|
|
331
|
-
<a name="cycle" href="#cycle">#</a> <b>cycle</b>(iterable: <i>Iterable<T></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js
|
|
313
|
+
<a name="cycle" href="#cycle">#</a> <b>cycle</b>(iterable: <i>Iterable<T></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
332
314
|
|
|
333
315
|
Returns an iterator producing elements from the iterable and saving a copy of
|
|
334
|
-
each.
|
|
316
|
+
each. When the iterable is exhausted, return elements from the saved copy.
|
|
335
317
|
Repeats indefinitely.
|
|
336
318
|
|
|
337
|
-
|
|
338
|
-
<a name="dropwhile" href="#dropwhile">#</a> <b>dropwhile</b>(iterable: <i>Iterable<T></i>, predicate: <i>T => bool</i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
319
|
+
<a name="dropwhile" href="#dropwhile">#</a> <b>dropwhile</b>(iterable: <i>Iterable<T></i>, predicate: <i>(item: T) => boolean</i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
339
320
|
|
|
340
321
|
Returns an iterator that drops elements from the iterable as long as the
|
|
341
|
-
predicate is true; afterwards, returns every remaining element.
|
|
322
|
+
predicate is true; afterwards, returns every remaining element. **Note:** the
|
|
342
323
|
iterator does not produce any output until the predicate first becomes false.
|
|
343
324
|
|
|
344
|
-
<a name="groupby" href="#groupby">#</a> <b>groupby</b>(iterable: <i>Iterable<T></i>, keyFcn: <i>T => Primitive</i>): <i>Iterable<[Primitive, Iterable<T>]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js
|
|
325
|
+
<a name="groupby" href="#groupby">#</a> <b>groupby</b>(iterable: <i>Iterable<T></i>, keyFcn: <i>(item: T) => Primitive</i>): <i>Iterable<[Primitive, Iterable<T>]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
345
326
|
|
|
346
327
|
Make an Iterable that returns consecutive keys and groups from the iterable.
|
|
347
328
|
The key is a function computing a key value for each element. If not specified,
|
|
@@ -357,116 +338,102 @@ common elements regardless of their input order.
|
|
|
357
338
|
The returned group is itself an iterator that shares the underlying iterable
|
|
358
339
|
with `groupby()`. Because the source is shared, when the `groupby()` object is
|
|
359
340
|
advanced, the previous group is no longer visible. So, if that data is needed
|
|
360
|
-
later, it should be stored as an
|
|
341
|
+
later, it should be stored as an array.
|
|
361
342
|
|
|
362
|
-
|
|
363
|
-
<a name="icompress" href="#icompress">#</a> <b>icompress</b>(iterable: <i>Iterable<T></i>, selectors: <i>Iterable<boolean></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
343
|
+
<a name="icompress" href="#icompress">#</a> <b>icompress</b>(iterable: <i>Iterable<T></i>, selectors: <i>Iterable<boolean></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
364
344
|
|
|
365
345
|
Returns an iterator that filters elements from data returning only those that
|
|
366
|
-
have a corresponding element in selectors that evaluates to `true`.
|
|
346
|
+
have a corresponding element in selectors that evaluates to `true`. Stops when
|
|
367
347
|
either the data or selectors iterables has been exhausted.
|
|
368
348
|
|
|
369
|
-
|
|
370
|
-
<a name="ifilter" href="#ifilter">#</a> <b>ifilter</b>(iterable: <i>Iterable<T></i>, predicate: <i>Predicate<T></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
349
|
+
<a name="ifilter" href="#ifilter">#</a> <b>ifilter</b>(iterable: <i>Iterable<T></i>, predicate: <i>Predicate<T></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
371
350
|
|
|
372
351
|
Returns an iterator that filters elements from iterable returning only those
|
|
373
352
|
for which the predicate is true.
|
|
374
353
|
|
|
375
|
-
<a name="imap" href="#imap">#</a> <b>imap</b>(iterable: <i>Iterable<T></i>, mapper: <i>T => V</i>): <i>Iterable<V></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js
|
|
354
|
+
<a name="imap" href="#imap">#</a> <b>imap</b>(iterable: <i>Iterable<T></i>, mapper: <i>(item: T) => V</i>): <i>Iterable<V></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
376
355
|
|
|
377
356
|
Returns an iterator that computes the given mapper function using arguments
|
|
378
357
|
from each of the iterables.
|
|
379
358
|
|
|
359
|
+
<a name="islice" href="#islice">#</a> <b>islice</b>(iterable: <i>Iterable<T></i>[start: <i>number</i>], stop: <i>number</i>[, step: <i>number</i>]): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
380
360
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
Returns an iterator that returns selected elements from the iterable. If
|
|
361
|
+
Returns an iterator that returns selected elements from the iterable. If
|
|
384
362
|
`start` is non-zero, then elements from the iterable are skipped until start is
|
|
385
|
-
reached.
|
|
386
|
-
1).
|
|
363
|
+
reached. Then, elements are returned by making steps of `step` (defaults to
|
|
364
|
+
1). If set to higher than 1, items will be skipped. If `stop` is provided,
|
|
387
365
|
then iteration continues until the iterator reached that index, otherwise, the
|
|
388
|
-
iterable will be fully exhausted.
|
|
366
|
+
iterable will be fully exhausted. `islice()` does not support negative values
|
|
389
367
|
for `start`, `stop`, or `step`.
|
|
390
368
|
|
|
369
|
+
<a name="izip" href="#izip">#</a> <b>izip</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>): <i>Iterable<[T1, T2]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')<br />
|
|
370
|
+
<a name="izip3" href="#izip3">#</a> <b>izip3</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, zs: <i>Iterable<T3></i>): <i>Iterable<[T1, T2, T3]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
391
371
|
|
|
392
|
-
|
|
393
|
-
|
|
372
|
+
Returns an iterator that aggregates elements from each of the iterables. Used
|
|
373
|
+
for lock-step iteration over several iterables at a time. When iterating over
|
|
374
|
+
two iterables, use `izip2`. When iterating over three iterables, use `izip3`,
|
|
375
|
+
etc. `izip` is an alias for `izip2`.
|
|
394
376
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
two iterables, use `izip2`. When iterating over three iterables, use `izip3`,
|
|
398
|
-
etc. `izip` is an alias for `izip2`.
|
|
377
|
+
<a name="izipLongest" href="izipLongest">#</a> <b>izipLongest</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, filler?: <i>D</i>): <i>Iterable<[T1 | D, T2 | D]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')<br />
|
|
378
|
+
<a name="izipLongest3" href="izipLongest3">#</a> <b>izipLongest3</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, zs: <i>Iterable<T3></i>, filler?: <i>D</i>): <i>Iterable<[T1 | D, T2 | D, T3 | D]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
399
379
|
|
|
400
|
-
|
|
401
|
-
<a name="izipLongest" href="izipLongest">#</a> <b>izipLongest</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, filler?: <i>D</i>): <i>Iterable<[T1 | D, T2 | D]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")<br />
|
|
402
|
-
<a name="izipLongest3" href="izipLongest3">#</a> <b>izipLongest3</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, zs: <i>Iterable<T3></i>, filler?: <i>D</i>): <i>Iterable<[T1 | D, T2 | D, T3 | D]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
403
|
-
|
|
404
|
-
Returns an iterator that aggregates elements from each of the iterables. If the
|
|
380
|
+
Returns an iterator that aggregates elements from each of the iterables. If the
|
|
405
381
|
iterables are of uneven length, missing values are filled-in with fillvalue.
|
|
406
382
|
Iteration continues until the longest iterable is exhausted.
|
|
407
383
|
|
|
408
|
-
|
|
409
|
-
<a name="izipMany" href="#izipMany">#</a> <b>izipMany</b>(...iters: <i>Array<Iterable<T>></i>): <i>Iterable<Array<T>></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
384
|
+
<a name="izipMany" href="#izipMany">#</a> <b>izipMany</b>(...iters: <i>Iterable<T>[]</i>): <i>Iterable<T[]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
410
385
|
|
|
411
386
|
Like the other izips (`izip`, `izip3`, etc), but generalized to take an
|
|
412
|
-
unlimited amount of input iterables.
|
|
413
|
-
|
|
414
|
-
**Note:** Due to Flow type system limitations, you can only "generially" zip
|
|
415
|
-
iterables with homogeneous types, so you cannot mix types like `<A, B>` like
|
|
416
|
-
you can with `izip`().
|
|
387
|
+
unlimited amount of input iterables. Think `izip(*iterables)` in Python.
|
|
417
388
|
|
|
418
|
-
|
|
419
|
-
<a name="permutations" href="#permutations">#</a> <b>permutations</b>(iterable: <i>Iterable<T></i>, r: number = undefined): <i>Iterable<Array<T>></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
389
|
+
<a name="permutations" href="#permutations">#</a> <b>permutations</b>(iterable: <i>Iterable<T></i>, r: number = undefined): <i>Iterable<T[]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
420
390
|
|
|
421
391
|
Return successive `r`-length permutations of elements in the iterable.
|
|
422
392
|
|
|
423
393
|
If `r` is not specified, then `r` defaults to the length of the iterable and
|
|
424
394
|
all possible full-length permutations are generated.
|
|
425
395
|
|
|
426
|
-
Permutations are emitted in lexicographic sort order.
|
|
396
|
+
Permutations are emitted in lexicographic sort order. So, if the input
|
|
427
397
|
iterable is sorted, the permutation tuples will be produced in sorted order.
|
|
428
398
|
|
|
429
|
-
Elements are treated as unique based on their position, not on their value.
|
|
399
|
+
Elements are treated as unique based on their position, not on their value. So
|
|
430
400
|
if the input elements are unique, there will be no repeat values in each
|
|
431
401
|
permutation.
|
|
432
402
|
|
|
403
|
+
<a name="repeat" href="#repeat">#</a> <b>repeat</b>(thing: <i>T</i>, times: number = undefined): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
433
404
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
Returns an iterator that produces values over and over again. Runs
|
|
405
|
+
Returns an iterator that produces values over and over again. Runs
|
|
437
406
|
indefinitely unless the times argument is specified.
|
|
438
407
|
|
|
439
|
-
|
|
440
|
-
<a name="takewhile" href="#takewhile">#</a> <b>takewhile</b>(iterable: <i>Iterable<T></i>, predicate: <i>T => bool</i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
408
|
+
<a name="takewhile" href="#takewhile">#</a> <b>takewhile</b>(iterable: <i>Iterable<T></i>, predicate: <i>(item: T) => boolean</i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
441
409
|
|
|
442
410
|
Returns an iterator that produces elements from the iterable as long as the
|
|
443
411
|
predicate is true.
|
|
444
412
|
|
|
445
|
-
<a name="zipLongest" href="zipLongest">#</a> <b>zipLongest</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, filler?: <i>D</i>): <i>
|
|
446
|
-
<a name="zipLongest3" href="zipLongest3">#</a> <b>zipLongest3</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, zs: <i>Iterable<T3></i>, filler?: <i>D</i>): <i>
|
|
413
|
+
<a name="zipLongest" href="zipLongest">#</a> <b>zipLongest</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, filler?: <i>D</i>): <i>[T1 | D, T2 | D][]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')<br />
|
|
414
|
+
<a name="zipLongest3" href="zipLongest3">#</a> <b>zipLongest3</b>(xs: <i>Iterable<T1></i>, ys: <i>Iterable<T2></i>, zs: <i>Iterable<T3></i>, filler?: <i>D</i>): <i>[T1 | D, T2 | D, T3 | D][]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
447
415
|
|
|
448
|
-
|
|
416
|
+
Eager version of [izipLongest](#izipLongest) and friends.
|
|
449
417
|
|
|
450
|
-
<a name="zipMany" href="#zipMany">#</a> <b>zipMany</b>(...iters: <i>
|
|
451
|
-
|
|
452
|
-
Non-lazy version of [izipMany](#izipMany).
|
|
418
|
+
<a name="zipMany" href="#zipMany">#</a> <b>zipMany</b>(...iters: <i>Iterable<T>[]</i>): <i>T[][]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js 'Source')
|
|
453
419
|
|
|
420
|
+
Eager version of [izipMany](#izipMany).
|
|
454
421
|
|
|
455
422
|
### Ports of more-itertools
|
|
456
423
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
424
|
+
- [chunked](#chunked)
|
|
425
|
+
- [flatten](#flatten)
|
|
426
|
+
- [intersperse](#intersperse)
|
|
427
|
+
- [itake](#itake)
|
|
428
|
+
- [pairwise](#pairwise)
|
|
429
|
+
- [partition](#partition)
|
|
430
|
+
- [roundrobin](#roundrobin)
|
|
431
|
+
- [heads](#heads)
|
|
432
|
+
- [take](#take)
|
|
433
|
+
- [uniqueEverseen](#uniqueEverseen)
|
|
434
|
+
- [uniqueJustseen](#uniqueJustseen)
|
|
468
435
|
|
|
469
|
-
<a name="chunked" href="#chunked">#</a> <b>chunked</b>(iterable: <i>Iterable<T></i>, size: <i>number</i>): <i>Iterable<
|
|
436
|
+
<a name="chunked" href="#chunked">#</a> <b>chunked</b>(iterable: <i>Iterable<T></i>, size: <i>number</i>): <i>Iterable<T[]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
470
437
|
|
|
471
438
|
Break iterable into lists of length `size`:
|
|
472
439
|
|
|
@@ -479,43 +446,38 @@ list will be shorter:
|
|
|
479
446
|
>>> [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]
|
|
480
447
|
[[1, 2, 3], [4, 5, 6], [7, 8]]
|
|
481
448
|
|
|
482
|
-
|
|
483
|
-
<a name="flatten" href="#flatten">#</a> <b>flatten</b>(iterableOfIterables: <i>Iterable<Iterable<T>></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js "Source")
|
|
449
|
+
<a name="flatten" href="#flatten">#</a> <b>flatten</b>(iterableOfIterables: <i>Iterable<Iterable<T>></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
484
450
|
|
|
485
451
|
Return an iterator flattening one level of nesting in a list of lists:
|
|
486
452
|
|
|
487
453
|
>>> [...flatten([[0, 1], [2, 3]])]
|
|
488
454
|
[0, 1, 2, 3]
|
|
489
455
|
|
|
490
|
-
|
|
491
|
-
<a name="intersperse" href="#intersperse">#</a> <b>intersperse</b>(value: T, iterable: <i>Iterable<T></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js "Source")
|
|
456
|
+
<a name="intersperse" href="#intersperse">#</a> <b>intersperse</b>(value: T, iterable: <i>Iterable<T></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
492
457
|
|
|
493
458
|
Intersperse filler element `value` among the items in `iterable`.
|
|
494
459
|
|
|
495
460
|
>>> [...intersperse(-1, range(1, 5))]
|
|
496
461
|
[1, -1, 2, -1, 3, -1, 4]
|
|
497
462
|
|
|
498
|
-
|
|
499
|
-
<a name="itake" href="#itake">#</a> <b>itake</b>(n: <i>number</i>, iterable: <i>Iterable<T></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js "Source")
|
|
463
|
+
<a name="itake" href="#itake">#</a> <b>itake</b>(n: <i>number</i>, iterable: <i>Iterable<T></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
500
464
|
|
|
501
465
|
Returns an iterable containing only the first `n` elements of the given
|
|
502
466
|
iterable.
|
|
503
467
|
|
|
468
|
+
<a name="pairwise" href="#pairwise">#</a> <b>pairwise</b>(iterable: <i>Iterable<T></i>): <i>Iterable<[T, T]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
504
469
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
Returns an iterator of paired items, overlapping, from the original. When the
|
|
470
|
+
Returns an iterator of paired items, overlapping, from the original. When the
|
|
508
471
|
input iterable has a finite number of items `n`, the outputted iterable will
|
|
509
472
|
have `n - 1` items.
|
|
510
473
|
|
|
511
474
|
>>> pairwise([8, 2, 0, 7])
|
|
512
475
|
[(8, 2), (2, 0), (0, 7)]
|
|
513
476
|
|
|
477
|
+
<a name="partition" href="#partition">#</a> <b>partition</b>(iterable: <i>Iterable<T></i>, predicate: <i>Predicate<T></i>): <i>[T[], T[]]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
514
478
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
Returns a 2-tuple of arrays. Splits the elements in the input iterable into
|
|
518
|
-
either of the two arrays. Will fully exhaust the input iterable. The first
|
|
479
|
+
Returns a 2-tuple of arrays. Splits the elements in the input iterable into
|
|
480
|
+
either of the two arrays. Will fully exhaust the input iterable. The first
|
|
519
481
|
array contains all items that match the predicate, the second the rest:
|
|
520
482
|
|
|
521
483
|
>>> const isOdd = x => x % 2 !== 0;
|
|
@@ -526,8 +488,7 @@ array contains all items that match the predicate, the second the rest:
|
|
|
526
488
|
>>> evens
|
|
527
489
|
[0, 2, 4, 6, 8]
|
|
528
490
|
|
|
529
|
-
|
|
530
|
-
<a name="roundrobin" href="#roundrobin">#</a> <b>roundrobin</b>(...iterables: <i>Array<Iterable<T>></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js "Source")
|
|
491
|
+
<a name="roundrobin" href="#roundrobin">#</a> <b>roundrobin</b>(...iterables: <i>Iterable<T>[]</i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
531
492
|
|
|
532
493
|
Yields the next item from each iterable in turn, alternating between them.
|
|
533
494
|
Continues until all items are exhausted.
|
|
@@ -535,21 +496,18 @@ Continues until all items are exhausted.
|
|
|
535
496
|
>>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
536
497
|
[1, 4, 5, 2, 6, 3, 7, 8]
|
|
537
498
|
|
|
538
|
-
|
|
539
|
-
<a name="heads" href="#heads">#</a> <b>heads</b>(...iterables: <i>Array<Iterable<T>></i>): <i>Iterable<Array<T>></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js "Source")
|
|
499
|
+
<a name="heads" href="#heads">#</a> <b>heads</b>(...iterables: <i>Iterable<T>[]</i>): <i>Iterable<T[]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
540
500
|
|
|
541
501
|
Like `roundrobin()`, but will group the output per "round".
|
|
542
502
|
|
|
543
503
|
>>> [...heads([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
544
504
|
[[1, 4, 5], [2, 6], [3, 7], [8]]
|
|
545
505
|
|
|
506
|
+
<a name="take" href="#take">#</a> <b>take</b>(n: <i>number</i>, iterable: <i>Iterable<T></i>): <i>T[]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
546
507
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
Non-lazy version of [itake](#itake).
|
|
508
|
+
Eager version of [itake](#itake).
|
|
550
509
|
|
|
551
|
-
|
|
552
|
-
<a name="uniqueEverseen" href="#uniqueEverseen">#</a> <b>uniqueEverseen</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>T => Primitive</i></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js "Source")
|
|
510
|
+
<a name="uniqueEverseen" href="#uniqueEverseen">#</a> <b>uniqueEverseen</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>(item: T) => Primitive</i></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
553
511
|
|
|
554
512
|
Yield unique elements, preserving order.
|
|
555
513
|
|
|
@@ -558,8 +516,7 @@ Yield unique elements, preserving order.
|
|
|
558
516
|
>>> [...uniqueEverseen('AbBCcAB', s => s.toLowerCase())]
|
|
559
517
|
['A', 'b', 'C']
|
|
560
518
|
|
|
561
|
-
|
|
562
|
-
<a name="uniqueJustseen" href="#uniqueJustseen">#</a> <b>uniqueJustseen</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>T => Primitive</i></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js "Source")
|
|
519
|
+
<a name="uniqueJustseen" href="#uniqueJustseen">#</a> <b>uniqueJustseen</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>(item: T) => Primitive</i></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/more-itertools.js 'Source')
|
|
563
520
|
|
|
564
521
|
Yields elements in order, ignoring serial duplicates.
|
|
565
522
|
|
|
@@ -568,43 +525,46 @@ Yields elements in order, ignoring serial duplicates.
|
|
|
568
525
|
>>> [...uniqueJustseen('AbBCcAB', s => s.toLowerCase())]
|
|
569
526
|
['A', 'b', 'C', 'A', 'B']
|
|
570
527
|
|
|
571
|
-
|
|
572
528
|
### Additions
|
|
573
529
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
<a name="compact" href="#compact">#</a> <b>compact</b>(iterable: <i>Iterable<T></i>): <i>Array<$NonMaybeType<T>></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js "Source")
|
|
581
|
-
|
|
582
|
-
Non-lazy version of [icompact](#icompact).
|
|
530
|
+
- [compact](#compact)
|
|
531
|
+
- [compactObject](#compactObject)
|
|
532
|
+
- [find](#find)
|
|
533
|
+
- [first](#first)
|
|
534
|
+
- [flatmap](#flatmap)
|
|
535
|
+
- [icompact](#icompact)
|
|
583
536
|
|
|
537
|
+
<a name="compact" href="#compact">#</a> <b>compact</b>(iterable: <i>Iterable<T | null | undefined></i>): <i>T[]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js 'Source')
|
|
584
538
|
|
|
585
|
-
|
|
539
|
+
Eager version of [icompact](#icompact).
|
|
586
540
|
|
|
587
|
-
>
|
|
541
|
+
<a name="compactObject" href="#compactObject">#</a> <b>compactObject</b>(obj: <i>Record<K, V | null | undefined></i>): <i>Record<K, V></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js 'Source')
|
|
588
542
|
|
|
589
|
-
Removes all
|
|
543
|
+
Removes all "nullish" values from the given object. Returns a new object.
|
|
590
544
|
|
|
591
545
|
>>> compactObject({ a: 1, b: undefined, c: 0, d: null })
|
|
592
546
|
{ a: 1, c: 0, d: null }
|
|
593
547
|
|
|
594
|
-
|
|
595
|
-
<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")
|
|
548
|
+
<a name="find" href="#find">#</a> <b>find</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>Predicate<T></i>): <i>T | undefined</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js 'Source')
|
|
596
549
|
|
|
597
550
|
Returns the first item in the iterable for which the predicate holds, if any.
|
|
598
|
-
If no such item exists, `undefined` is returned.
|
|
599
|
-
|
|
551
|
+
If no such item exists, `undefined` is returned. If no default predicate is
|
|
552
|
+
given, the first value from the iterable is returned.
|
|
553
|
+
|
|
554
|
+
<a name="first" href="#first">#</a> <b>first</b>(iterable: <i>Iterable<T></i>, keyFn?: <i>Predicate<T></i>): <i>T | undefined</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js 'Source')
|
|
555
|
+
|
|
556
|
+
Almost the same as `find()`, except when no explicit predicate function is
|
|
557
|
+
given. `find()` will always return the first value in the iterable, whereas
|
|
558
|
+
`first()` will return the first non-`undefined` value in the iterable.
|
|
600
559
|
|
|
560
|
+
Prefer using `find()`, as its behavior is more intuitive and predictable.
|
|
601
561
|
|
|
602
|
-
<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
|
|
562
|
+
<a name="flatmap" href="#flatmap">#</a> <b>flatmap</b>(iterable: <i>Iterable<T></i>, mapper: <i>(item: T) => Iterable<S></i>): <i>Iterable<S></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js 'Source')
|
|
603
563
|
|
|
604
|
-
Returns 0 or more values for every value in the given iterable.
|
|
564
|
+
Returns 0 or more values for every value in the given iterable. Technically,
|
|
605
565
|
it's just calling map(), followed by flatten(), but it's a very useful
|
|
606
566
|
operation if you want to map over a structure, but not have a 1:1 input-output
|
|
607
|
-
mapping.
|
|
567
|
+
mapping. Instead, if you want to potentially return 0 or more values per input
|
|
608
568
|
element, use flatmap():
|
|
609
569
|
|
|
610
570
|
For example, to return all numbers `n` in the input iterable `n` times:
|
|
@@ -613,13 +573,10 @@ For example, to return all numbers `n` in the input iterable `n` times:
|
|
|
613
573
|
>>> [...flatmap([0, 1, 2, 3, 4], repeatN)]
|
|
614
574
|
[1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0
|
|
615
575
|
|
|
576
|
+
<a name="icompact" href="#icompact">#</a> <b>icompact</b>(iterable: <i>Iterable<T | null | undefined></i>): <i>Iterable<T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/custom.js 'Source')
|
|
616
577
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
Returns an iterable, filtering out any `undefined` values from the input
|
|
620
|
-
iterable. This function is useful to convert a list of `Maybe<T>`'s to a list
|
|
621
|
-
of `T`'s, discarding all the undefined values:
|
|
578
|
+
Returns an iterable, filtering out any "nullish" values from the input
|
|
579
|
+
iterable.
|
|
622
580
|
|
|
623
581
|
>>> compact([1, 2, undefined, 3])
|
|
624
582
|
[1, 2, 3]
|
|
625
|
-
|