itertools 2.5.0-0 → 2.6.0-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 +224 -146
- package/dist/index.cjs +18 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -1
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -45,15 +45,15 @@ function bodies can span multiple lines, in which case the following block will
|
|
|
45
45
|
remain aesthetically pleasing:
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
|
-
import { map } from
|
|
48
|
+
import { map } from "itertools";
|
|
49
49
|
|
|
50
50
|
const numbers = [1, 2, 3];
|
|
51
51
|
const squares = map(numbers, (n) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
//
|
|
53
|
+
// Do something wild with these numbers here
|
|
54
|
+
//
|
|
55
|
+
// ...
|
|
56
|
+
return n * n;
|
|
57
57
|
});
|
|
58
58
|
```
|
|
59
59
|
|
|
@@ -61,30 +61,31 @@ const squares = map(numbers, (n) => {
|
|
|
61
61
|
|
|
62
62
|
The `itertools` package consists of a few building blocks:
|
|
63
63
|
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
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)
|
|
68
68
|
|
|
69
69
|
### Ports of builtins
|
|
70
70
|
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
- [xrange](#xrange)
|
|
84
|
+
- [sum](#sum)
|
|
85
|
+
- [zip](#zip)
|
|
86
|
+
- [zip3](#zip3)
|
|
87
|
+
|
|
88
|
+
<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
|
|
|
89
90
|
Returns true when every of the items in iterable are truthy. An optional key
|
|
90
91
|
function can be used to define what truthiness means for this specific
|
|
@@ -106,7 +107,7 @@ every([2, 4, 6], (n) => n % 2 === 0); // => true
|
|
|
106
107
|
every([2, 4, 5], (n) => n % 2 === 0); // => false
|
|
107
108
|
```
|
|
108
109
|
|
|
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
|
|
110
|
+
<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")
|
|
110
111
|
|
|
111
112
|
Returns true when some of the items in iterable are truthy. An optional key
|
|
112
113
|
function can be used to define what truthiness means for this specific
|
|
@@ -124,10 +125,10 @@ Examples with using a key function:
|
|
|
124
125
|
|
|
125
126
|
```ts
|
|
126
127
|
some([1, 4, 5], (n) => n % 2 === 0); // => true
|
|
127
|
-
some([{ name:
|
|
128
|
+
some([{ name: "Bob" }, { name: "Alice" }], (person) => person.name.startsWith("C")); // => false
|
|
128
129
|
```
|
|
129
130
|
|
|
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
|
|
131
|
+
<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")
|
|
131
132
|
|
|
132
133
|
Returns true when some of the items in the iterable are equal to the target
|
|
133
134
|
object.
|
|
@@ -135,13 +136,13 @@ object.
|
|
|
135
136
|
Examples:
|
|
136
137
|
|
|
137
138
|
```ts
|
|
138
|
-
contains([],
|
|
139
|
+
contains([], "whatever"); // => false
|
|
139
140
|
contains([3], 42); // => false
|
|
140
141
|
contains([3], 3); // => true
|
|
141
142
|
contains([0, 1, 2], 2); // => true
|
|
142
143
|
```
|
|
143
144
|
|
|
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
|
|
145
|
+
<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")
|
|
145
146
|
|
|
146
147
|
Returns an iterable of enumeration pairs. Iterable must be a sequence, an
|
|
147
148
|
iterator, or some other object which supports iteration. The elements produced
|
|
@@ -151,28 +152,28 @@ the values obtained from iterating over given iterable.
|
|
|
151
152
|
Example:
|
|
152
153
|
|
|
153
154
|
```ts
|
|
154
|
-
import { enumerate } from
|
|
155
|
+
import { enumerate } from "itertools";
|
|
155
156
|
|
|
156
|
-
console.log([...enumerate([
|
|
157
|
+
console.log([...enumerate(["hello", "world"])]);
|
|
157
158
|
// [0, 'hello'], [1, 'world']]
|
|
158
159
|
```
|
|
159
160
|
|
|
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
|
|
161
|
+
<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")
|
|
161
162
|
|
|
162
163
|
Eager version of [ifilter](#ifilter).
|
|
163
164
|
|
|
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
|
|
165
|
+
<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")
|
|
165
166
|
|
|
166
167
|
Returns an iterator object for the given iterable. This can be used to
|
|
167
168
|
manually get an iterator for any iterable datastructure. The purpose and main
|
|
168
169
|
use case of this function is to get a single iterator (a thing with state,
|
|
169
170
|
think of it as a "cursor") which can only be consumed once.
|
|
170
171
|
|
|
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
|
|
172
|
+
<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")
|
|
172
173
|
|
|
173
174
|
Eager version of [imap](#imap).
|
|
174
175
|
|
|
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
|
|
176
|
+
<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")
|
|
176
177
|
|
|
177
178
|
Return the largest item in an iterable. Only works for numbers, as ordering is
|
|
178
179
|
pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
@@ -184,7 +185,7 @@ If the iterable is empty, `undefined` is returned.
|
|
|
184
185
|
If multiple items are maximal, the function returns either one of them, but
|
|
185
186
|
which one is not defined.
|
|
186
187
|
|
|
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
|
|
188
|
+
<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")
|
|
188
189
|
|
|
189
190
|
Return the smallest item in an iterable. Only works for numbers, as ordering
|
|
190
191
|
is pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
@@ -196,8 +197,8 @@ If the iterable is empty, `undefined` is returned.
|
|
|
196
197
|
If multiple items are minimal, the function returns either one of them, but
|
|
197
198
|
which one is not defined.
|
|
198
199
|
|
|
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
|
|
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
|
|
200
|
+
<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 />
|
|
201
|
+
<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")
|
|
201
202
|
|
|
202
203
|
Returns an iterator producing all the numbers in the given range one by one,
|
|
203
204
|
starting from `start` (default 0), as long as `i < stop`, in increments of
|
|
@@ -207,11 +208,12 @@ starting from `start` (default 0), as long as `i < stop`, in increments of
|
|
|
207
208
|
|
|
208
209
|
Various valid invocations:
|
|
209
210
|
|
|
210
|
-
range(5) //
|
|
211
|
-
range(0, 5) //
|
|
212
|
-
range(0, 5, 2) //
|
|
213
|
-
range(5, 0, -1) //
|
|
214
|
-
range(
|
|
211
|
+
range(5) // 0, 1, 2, 3, 4
|
|
212
|
+
range(0, 5) // 0, 1, 2, 3, 4
|
|
213
|
+
range(0, 5, 2) // 0, 2, 4
|
|
214
|
+
range(5, 0, -1) // 5, 4, 3, 2, 1
|
|
215
|
+
range(5, 0) // (empty)
|
|
216
|
+
range(-3) // (empty)
|
|
215
217
|
|
|
216
218
|
For a positive `step`, the iterator will keep producing values `n` as long as
|
|
217
219
|
the stop condition `n < stop` is satisfied.
|
|
@@ -222,8 +224,37 @@ the stop condition `n > stop` is satisfied.
|
|
|
222
224
|
The produced range will be empty if the first value to produce already does not
|
|
223
225
|
meet the value constraint.
|
|
224
226
|
|
|
225
|
-
<a name="
|
|
226
|
-
<a name="
|
|
227
|
+
<a name="xrange" href="#xrange">#</a> <b>xrange</b>(stop: <i>number</i>): <i>number[]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")<br />
|
|
228
|
+
<a name="xrange" href="#xrange">#</a> <b>xrange</b>(start: <i>number</i>, stop: <i>number</i>, step: <i>number</i> = 1): <i>number[]</i> [<>](https://github.com/nvie/itertools.js/blob/master/src/builtins.js "Source")
|
|
229
|
+
|
|
230
|
+
Returns an array with all the numbers in the given range, starting from
|
|
231
|
+
`start` (default 0), as long as `i < stop`, in increments of `step`
|
|
232
|
+
(default 1).
|
|
233
|
+
|
|
234
|
+
`xrange(5)` is a convenient shorthand for `Array.from(range(5))`.
|
|
235
|
+
|
|
236
|
+
Various valid invocations:
|
|
237
|
+
|
|
238
|
+
xrange(5) // [0, 1, 2, 3, 4]
|
|
239
|
+
xrange(2, 5) // [2, 3, 4]
|
|
240
|
+
xrange(0, 5, 2) // [0, 2, 4]
|
|
241
|
+
xrange(5, 0, -1) // [5, 4, 3, 2, 1]
|
|
242
|
+
xrange(5, 0) // []
|
|
243
|
+
|
|
244
|
+
For a positive `step`, the iterator will keep producing values `n` as long as
|
|
245
|
+
the stop condition `n < stop` is satisfied.
|
|
246
|
+
|
|
247
|
+
For a negative `step`, the iterator will keep producing values `n` as long as
|
|
248
|
+
the stop condition `n > stop` is satisfied.
|
|
249
|
+
|
|
250
|
+
The produced range will be empty if the first value to produce already does not
|
|
251
|
+
meet the value constraint.
|
|
252
|
+
|
|
253
|
+
Don't use this on large or infinite ranges, as it will allocate a large array
|
|
254
|
+
in memory.
|
|
255
|
+
|
|
256
|
+
<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 />
|
|
257
|
+
<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")
|
|
227
258
|
|
|
228
259
|
Apply function of two arguments cumulatively to the items of sequence, from
|
|
229
260
|
left to right, so as to reduce the sequence to a single value. For example:
|
|
@@ -249,114 +280,161 @@ it calculates
|
|
|
249
280
|
|
|
250
281
|
((((1+2)+3)+4)+5)
|
|
251
282
|
|
|
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
|
|
283
|
+
<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")
|
|
253
284
|
|
|
254
285
|
Return a new sorted list from the items in iterable.
|
|
255
286
|
|
|
256
287
|
Has two optional arguments:
|
|
257
288
|
|
|
258
|
-
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
289
|
+
- `keyFn` specifies a function of one argument providing a primitive identity
|
|
290
|
+
for each element in the iterable. that will be used to compare. The default
|
|
291
|
+
value is to use a default identity function that is only defined for
|
|
292
|
+
primitive types.
|
|
262
293
|
|
|
263
|
-
-
|
|
264
|
-
|
|
294
|
+
- `reverse` is a boolean value. If `true`, then the list elements are sorted
|
|
295
|
+
as if each comparison were reversed.
|
|
265
296
|
|
|
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
|
|
297
|
+
<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")
|
|
267
298
|
|
|
268
299
|
Sums the items of an iterable from left to right and returns the total. The
|
|
269
300
|
sum will defaults to 0 if the iterable is empty.
|
|
270
301
|
|
|
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
|
|
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
|
|
302
|
+
<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 />
|
|
303
|
+
<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")
|
|
273
304
|
|
|
274
305
|
Eager version of [izip](#izip) / [izip3](#izip3).
|
|
275
306
|
|
|
276
307
|
### Ports of itertools
|
|
277
308
|
|
|
278
|
-
-
|
|
279
|
-
-
|
|
280
|
-
-
|
|
281
|
-
-
|
|
282
|
-
-
|
|
283
|
-
-
|
|
284
|
-
-
|
|
285
|
-
-
|
|
286
|
-
-
|
|
287
|
-
-
|
|
288
|
-
-
|
|
289
|
-
-
|
|
290
|
-
-
|
|
291
|
-
-
|
|
292
|
-
-
|
|
293
|
-
-
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
297
|
-
|
|
298
|
-
|
|
309
|
+
- [chain](#chain)
|
|
310
|
+
- [compress](#compress)
|
|
311
|
+
- [count](#count)
|
|
312
|
+
- [cycle](#cycle)
|
|
313
|
+
- [dropwhile](#dropwhile)
|
|
314
|
+
- [groupBy](#groupBy)
|
|
315
|
+
- [icompress](#icompress)
|
|
316
|
+
- [ifilter](#ifilter)
|
|
317
|
+
- [igroupby](#igroupby)
|
|
318
|
+
- [imap](#imap)
|
|
319
|
+
- [indexBy](#indexBy)
|
|
320
|
+
- [islice](#islice)
|
|
321
|
+
- [izip](#izip)
|
|
322
|
+
- [izip3](#izip3)
|
|
323
|
+
- [izipLongest](#izipLongest)
|
|
324
|
+
- [izipMany](#izipMany)
|
|
325
|
+
- [permutations](#permutations)
|
|
326
|
+
- [repeat](#repeat)
|
|
327
|
+
- [takewhile](#takewhile)
|
|
328
|
+
- [zipLongest](#zipLongest)
|
|
329
|
+
- [zipMany](#zipMany)
|
|
330
|
+
|
|
331
|
+
<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")
|
|
299
332
|
|
|
300
333
|
Returns an iterator that returns elements from the first iterable until it is
|
|
301
334
|
exhausted, then proceeds to the next iterable, until all of the iterables are
|
|
302
335
|
exhausted. Used for treating consecutive sequences as a single sequence.
|
|
303
336
|
|
|
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
|
|
337
|
+
<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")
|
|
305
338
|
|
|
306
339
|
Eager version of [icompress](#icompress).
|
|
307
340
|
|
|
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
|
|
341
|
+
<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")
|
|
309
342
|
|
|
310
343
|
Returns an iterator that counts up values starting with number `start` (default
|
|
311
344
|
0), incrementing by `step`. To decrement, use a negative step number.
|
|
312
345
|
|
|
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
|
|
346
|
+
<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")
|
|
314
347
|
|
|
315
348
|
Returns an iterator producing elements from the iterable and saving a copy of
|
|
316
349
|
each. When the iterable is exhausted, return elements from the saved copy.
|
|
317
350
|
Repeats indefinitely.
|
|
318
351
|
|
|
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
|
|
352
|
+
<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")
|
|
320
353
|
|
|
321
354
|
Returns an iterator that drops elements from the iterable as long as the
|
|
322
355
|
predicate is true; afterwards, returns every remaining element. **Note:** the
|
|
323
356
|
iterator does not produce any output until the predicate first becomes false.
|
|
324
357
|
|
|
325
|
-
<a name="
|
|
358
|
+
<a name="groupBy" href="#groupBy">#</a> <b>groupBy</b>(iterable: <i>Iterable<T></i>, keyFn: <i>(item: T) => K</i>): <i>Record<K, T[]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
359
|
+
|
|
360
|
+
Groups elements of the iterable into a record based on the key function. Each
|
|
361
|
+
key maps to an array of all elements that share the same key.
|
|
362
|
+
|
|
363
|
+
```ts
|
|
364
|
+
const users = [
|
|
365
|
+
{ name: "Alice", department: "Engineering" },
|
|
366
|
+
{ name: "Bob", department: "Sales" },
|
|
367
|
+
{ name: "Charlie", department: "Engineering" },
|
|
368
|
+
];
|
|
369
|
+
|
|
370
|
+
groupBy(users, (user) => user.department);
|
|
371
|
+
// {
|
|
372
|
+
// 'Engineering': [
|
|
373
|
+
// { name: 'Alice', department: 'Engineering' },
|
|
374
|
+
// { name: 'Charlie', department: 'Engineering' }
|
|
375
|
+
// ],
|
|
376
|
+
// 'Sales': [
|
|
377
|
+
// { name: 'Bob', department: 'Sales' }
|
|
378
|
+
// ]
|
|
379
|
+
// }
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
<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")
|
|
383
|
+
|
|
384
|
+
Returns an iterator that filters elements from data returning only those that
|
|
385
|
+
have a corresponding element in selectors that evaluates to `true`. Stops when
|
|
386
|
+
either the data or selectors iterables has been exhausted.
|
|
387
|
+
|
|
388
|
+
<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")
|
|
389
|
+
|
|
390
|
+
Returns an iterator that filters elements from iterable returning only those
|
|
391
|
+
for which the predicate is true.
|
|
392
|
+
|
|
393
|
+
<a name="igroupby" href="#igroupby">#</a> <b>igroupby</b>(iterable: <i>Iterable<T></i>, keyFn: <i>(item: T) => Primitive</i>): <i>Iterable<[Primitive, Iterable<T>]></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
326
394
|
|
|
327
395
|
Make an Iterable that returns consecutive keys and groups from the iterable.
|
|
328
396
|
The key is a function computing a key value for each element. If not specified,
|
|
329
397
|
key defaults to an identity function and returns the element unchanged.
|
|
330
398
|
Generally, the iterable needs to already be sorted on the same key function.
|
|
331
399
|
|
|
332
|
-
The operation of `
|
|
400
|
+
The operation of `igroupby()` is similar to the `uniq` filter in Unix. It
|
|
333
401
|
generates a break or new group every time the value of the key function changes
|
|
334
402
|
(which is why it is usually necessary to have sorted the data using the same
|
|
335
403
|
key function). That behavior differs from `SQL`’s `GROUP BY` which aggregates
|
|
336
404
|
common elements regardless of their input order.
|
|
337
405
|
|
|
338
406
|
The returned group is itself an iterator that shares the underlying iterable
|
|
339
|
-
with `
|
|
407
|
+
with `igroupby()`. Because the source is shared, when the `igroupby()` object is
|
|
340
408
|
advanced, the previous group is no longer visible. So, if that data is needed
|
|
341
409
|
later, it should be stored as an array.
|
|
342
410
|
|
|
343
|
-
<a name="
|
|
411
|
+
<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")
|
|
344
412
|
|
|
345
|
-
Returns an iterator that
|
|
346
|
-
|
|
347
|
-
either the data or selectors iterables has been exhausted.
|
|
348
|
-
|
|
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')
|
|
413
|
+
Returns an iterator that computes the given mapper function using arguments
|
|
414
|
+
from each of the iterables.
|
|
350
415
|
|
|
351
|
-
|
|
352
|
-
for which the predicate is true.
|
|
416
|
+
<a name="indexBy" href="#indexBy">#</a> <b>indexBy</b>(iterable: <i>Iterable<T></i>, keyFn: <i>(item: T) => K</i>): <i>Record<K, T></i> [<>](https://github.com/nvie/itertools.js/blob/master/src/itertools.js "Source")
|
|
353
417
|
|
|
354
|
-
|
|
418
|
+
Creates an index (record) from the iterable where each key maps to the last
|
|
419
|
+
element that produced that key. If multiple elements produce the same key, only
|
|
420
|
+
the last one is kept.
|
|
355
421
|
|
|
356
|
-
|
|
357
|
-
|
|
422
|
+
```ts
|
|
423
|
+
const users = [
|
|
424
|
+
{ id: 1, name: "Alice" },
|
|
425
|
+
{ id: 2, name: "Bob" },
|
|
426
|
+
{ id: 3, name: "Charlie" },
|
|
427
|
+
];
|
|
428
|
+
|
|
429
|
+
indexBy(users, (user) => user.id);
|
|
430
|
+
// {
|
|
431
|
+
// 1: { id: 1, name: 'Alice' },
|
|
432
|
+
// 2: { id: 2, name: 'Bob' },
|
|
433
|
+
// 3: { id: 3, name: 'Charlie' }
|
|
434
|
+
// }
|
|
435
|
+
```
|
|
358
436
|
|
|
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
|
|
437
|
+
<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")
|
|
360
438
|
|
|
361
439
|
Returns an iterator that returns selected elements from the iterable. If
|
|
362
440
|
`start` is non-zero, then elements from the iterable are skipped until start is
|
|
@@ -366,27 +444,27 @@ then iteration continues until the iterator reached that index, otherwise, the
|
|
|
366
444
|
iterable will be fully exhausted. `islice()` does not support negative values
|
|
367
445
|
for `start`, `stop`, or `step`.
|
|
368
446
|
|
|
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
|
|
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
|
|
447
|
+
<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 />
|
|
448
|
+
<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")
|
|
371
449
|
|
|
372
450
|
Returns an iterator that aggregates elements from each of the iterables. Used
|
|
373
451
|
for lock-step iteration over several iterables at a time. When iterating over
|
|
374
452
|
two iterables, use `izip2`. When iterating over three iterables, use `izip3`,
|
|
375
453
|
etc. `izip` is an alias for `izip2`.
|
|
376
454
|
|
|
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
|
|
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
|
|
455
|
+
<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 />
|
|
456
|
+
<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")
|
|
379
457
|
|
|
380
458
|
Returns an iterator that aggregates elements from each of the iterables. If the
|
|
381
459
|
iterables are of uneven length, missing values are filled-in with fillvalue.
|
|
382
460
|
Iteration continues until the longest iterable is exhausted.
|
|
383
461
|
|
|
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
|
|
462
|
+
<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")
|
|
385
463
|
|
|
386
464
|
Like the other izips (`izip`, `izip3`, etc), but generalized to take an
|
|
387
465
|
unlimited amount of input iterables. Think `izip(*iterables)` in Python.
|
|
388
466
|
|
|
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
|
|
467
|
+
<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")
|
|
390
468
|
|
|
391
469
|
Return successive `r`-length permutations of elements in the iterable.
|
|
392
470
|
|
|
@@ -400,41 +478,41 @@ Elements are treated as unique based on their position, not on their value. So
|
|
|
400
478
|
if the input elements are unique, there will be no repeat values in each
|
|
401
479
|
permutation.
|
|
402
480
|
|
|
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
|
|
481
|
+
<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")
|
|
404
482
|
|
|
405
483
|
Returns an iterator that produces values over and over again. Runs
|
|
406
484
|
indefinitely unless the times argument is specified.
|
|
407
485
|
|
|
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
|
|
486
|
+
<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")
|
|
409
487
|
|
|
410
488
|
Returns an iterator that produces elements from the iterable as long as the
|
|
411
489
|
predicate is true.
|
|
412
490
|
|
|
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
|
|
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
|
|
491
|
+
<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 />
|
|
492
|
+
<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")
|
|
415
493
|
|
|
416
494
|
Eager version of [izipLongest](#izipLongest) and friends.
|
|
417
495
|
|
|
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
|
|
496
|
+
<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")
|
|
419
497
|
|
|
420
498
|
Eager version of [izipMany](#izipMany).
|
|
421
499
|
|
|
422
500
|
### Ports of more-itertools
|
|
423
501
|
|
|
424
|
-
-
|
|
425
|
-
-
|
|
426
|
-
-
|
|
427
|
-
-
|
|
428
|
-
-
|
|
429
|
-
-
|
|
430
|
-
-
|
|
431
|
-
-
|
|
432
|
-
-
|
|
433
|
-
-
|
|
434
|
-
-
|
|
435
|
-
-
|
|
436
|
-
|
|
437
|
-
<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
|
|
502
|
+
- [chunked](#chunked)
|
|
503
|
+
- [flatten](#flatten)
|
|
504
|
+
- [intersperse](#intersperse)
|
|
505
|
+
- [itake](#itake)
|
|
506
|
+
- [pairwise](#pairwise)
|
|
507
|
+
- [partition](#partition)
|
|
508
|
+
- [roundrobin](#roundrobin)
|
|
509
|
+
- [heads](#heads)
|
|
510
|
+
- [take](#take)
|
|
511
|
+
- [uniqueEverseen](#uniqueEverseen)
|
|
512
|
+
- [uniqueJustseen](#uniqueJustseen)
|
|
513
|
+
- [dupes](#dupes)
|
|
514
|
+
|
|
515
|
+
<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")
|
|
438
516
|
|
|
439
517
|
Break iterable into lists of length `size`:
|
|
440
518
|
|
|
@@ -447,26 +525,26 @@ list will be shorter:
|
|
|
447
525
|
>>> [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]
|
|
448
526
|
[[1, 2, 3], [4, 5, 6], [7, 8]]
|
|
449
527
|
|
|
450
|
-
<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
|
|
528
|
+
<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")
|
|
451
529
|
|
|
452
530
|
Return an iterator flattening one level of nesting in a list of lists:
|
|
453
531
|
|
|
454
532
|
>>> [...flatten([[0, 1], [2, 3]])]
|
|
455
533
|
[0, 1, 2, 3]
|
|
456
534
|
|
|
457
|
-
<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
|
|
535
|
+
<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")
|
|
458
536
|
|
|
459
537
|
Intersperse filler element `value` among the items in `iterable`.
|
|
460
538
|
|
|
461
539
|
>>> [...intersperse(-1, range(1, 5))]
|
|
462
540
|
[1, -1, 2, -1, 3, -1, 4]
|
|
463
541
|
|
|
464
|
-
<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
|
|
542
|
+
<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")
|
|
465
543
|
|
|
466
544
|
Returns an iterable containing only the first `n` elements of the given
|
|
467
545
|
iterable.
|
|
468
546
|
|
|
469
|
-
<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
|
|
547
|
+
<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")
|
|
470
548
|
|
|
471
549
|
Returns an iterator of paired items, overlapping, from the original. When the
|
|
472
550
|
input iterable has a finite number of items `n`, the outputted iterable will
|
|
@@ -475,7 +553,7 @@ have `n - 1` items.
|
|
|
475
553
|
>>> pairwise([8, 2, 0, 7])
|
|
476
554
|
[(8, 2), (2, 0), (0, 7)]
|
|
477
555
|
|
|
478
|
-
<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
|
|
556
|
+
<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")
|
|
479
557
|
|
|
480
558
|
Returns a 2-tuple of arrays. Splits the elements in the input iterable into
|
|
481
559
|
either of the two arrays. Will fully exhaust the input iterable. The first
|
|
@@ -489,7 +567,7 @@ array contains all items that match the predicate, the second the rest:
|
|
|
489
567
|
>>> evens
|
|
490
568
|
[0, 2, 4, 6, 8]
|
|
491
569
|
|
|
492
|
-
<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
|
|
570
|
+
<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")
|
|
493
571
|
|
|
494
572
|
Yields the next item from each iterable in turn, alternating between them.
|
|
495
573
|
Continues until all items are exhausted.
|
|
@@ -497,18 +575,18 @@ Continues until all items are exhausted.
|
|
|
497
575
|
>>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
498
576
|
[1, 4, 5, 2, 6, 3, 7, 8]
|
|
499
577
|
|
|
500
|
-
<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
|
|
578
|
+
<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")
|
|
501
579
|
|
|
502
580
|
Like `roundrobin()`, but will group the output per "round".
|
|
503
581
|
|
|
504
582
|
>>> [...heads([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
505
583
|
[[1, 4, 5], [2, 6], [3, 7], [8]]
|
|
506
584
|
|
|
507
|
-
<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
|
|
585
|
+
<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")
|
|
508
586
|
|
|
509
587
|
Eager version of [itake](#itake).
|
|
510
588
|
|
|
511
|
-
<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
|
|
589
|
+
<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")
|
|
512
590
|
|
|
513
591
|
Yield unique elements, preserving order.
|
|
514
592
|
|
|
@@ -517,7 +595,7 @@ Yield unique elements, preserving order.
|
|
|
517
595
|
>>> [...uniqueEverseen('AbBCcAB', s => s.toLowerCase())]
|
|
518
596
|
['A', 'b', 'C']
|
|
519
597
|
|
|
520
|
-
<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
|
|
598
|
+
<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")
|
|
521
599
|
|
|
522
600
|
Yields elements in order, ignoring serial duplicates.
|
|
523
601
|
|
|
@@ -526,7 +604,7 @@ Yields elements in order, ignoring serial duplicates.
|
|
|
526
604
|
>>> [...uniqueJustseen('AbBCcAB', s => s.toLowerCase())]
|
|
527
605
|
['A', 'b', 'C', 'A', 'B']
|
|
528
606
|
|
|
529
|
-
<a name="dupes" href="#dupes">#</a> <b>dupes</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
|
|
607
|
+
<a name="dupes" href="#dupes">#</a> <b>dupes</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")
|
|
530
608
|
|
|
531
609
|
Yield only elements from the input that occur more than once. Needs to consume the entire input before being able to produce the first result.
|
|
532
610
|
|
|
@@ -537,31 +615,31 @@ Yield only elements from the input that occur more than once. Needs to consume t
|
|
|
537
615
|
|
|
538
616
|
### Additions
|
|
539
617
|
|
|
540
|
-
-
|
|
541
|
-
-
|
|
542
|
-
-
|
|
543
|
-
-
|
|
544
|
-
-
|
|
545
|
-
-
|
|
618
|
+
- [compact](#compact)
|
|
619
|
+
- [compactObject](#compactObject)
|
|
620
|
+
- [find](#find)
|
|
621
|
+
- [first](#first)
|
|
622
|
+
- [flatmap](#flatmap)
|
|
623
|
+
- [icompact](#icompact)
|
|
546
624
|
|
|
547
|
-
<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
|
|
625
|
+
<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")
|
|
548
626
|
|
|
549
627
|
Eager version of [icompact](#icompact).
|
|
550
628
|
|
|
551
|
-
<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
|
|
629
|
+
<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")
|
|
552
630
|
|
|
553
631
|
Removes all "nullish" values from the given object. Returns a new object.
|
|
554
632
|
|
|
555
633
|
>>> compactObject({ a: 1, b: undefined, c: 0, d: null })
|
|
556
634
|
{ a: 1, c: 0, d: null }
|
|
557
635
|
|
|
558
|
-
<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
|
|
636
|
+
<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")
|
|
559
637
|
|
|
560
638
|
Returns the first item in the iterable for which the predicate holds, if any.
|
|
561
639
|
If no such item exists, `undefined` is returned. If no default predicate is
|
|
562
640
|
given, the first value from the iterable is returned.
|
|
563
641
|
|
|
564
|
-
<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
|
|
642
|
+
<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")
|
|
565
643
|
|
|
566
644
|
Almost the same as `find()`, except when no explicit predicate function is
|
|
567
645
|
given. `find()` will always return the first value in the iterable, whereas
|
|
@@ -569,7 +647,7 @@ given. `find()` will always return the first value in the iterable, whereas
|
|
|
569
647
|
|
|
570
648
|
Prefer using `find()`, as its behavior is more intuitive and predictable.
|
|
571
649
|
|
|
572
|
-
<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
|
|
650
|
+
<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")
|
|
573
651
|
|
|
574
652
|
Returns 0 or more values for every value in the given iterable. Technically,
|
|
575
653
|
it's just calling map(), followed by flatten(), but it's a very useful
|
|
@@ -583,7 +661,7 @@ For example, to return all numbers `n` in the input iterable `n` times:
|
|
|
583
661
|
>>> [...flatmap([0, 1, 2, 3, 4], repeatN)]
|
|
584
662
|
[1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0
|
|
585
663
|
|
|
586
|
-
<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
|
|
664
|
+
<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")
|
|
587
665
|
|
|
588
666
|
Returns an iterable, filtering out any "nullish" values from the input
|
|
589
667
|
iterable.
|