itertools 2.5.0-0 → 2.5.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 +188 -141
- package/dist/index.cjs +10 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -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,30 @@ 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
|
-
<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
|
|
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
88
|
|
|
89
89
|
Returns true when every of the items in iterable are truthy. An optional key
|
|
90
90
|
function can be used to define what truthiness means for this specific
|
|
@@ -106,7 +106,7 @@ every([2, 4, 6], (n) => n % 2 === 0); // => true
|
|
|
106
106
|
every([2, 4, 5], (n) => n % 2 === 0); // => false
|
|
107
107
|
```
|
|
108
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
|
|
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")
|
|
110
110
|
|
|
111
111
|
Returns true when some of the items in iterable are truthy. An optional key
|
|
112
112
|
function can be used to define what truthiness means for this specific
|
|
@@ -124,10 +124,10 @@ Examples with using a key function:
|
|
|
124
124
|
|
|
125
125
|
```ts
|
|
126
126
|
some([1, 4, 5], (n) => n % 2 === 0); // => true
|
|
127
|
-
some([{ name:
|
|
127
|
+
some([{ name: "Bob" }, { name: "Alice" }], (person) => person.name.startsWith("C")); // => false
|
|
128
128
|
```
|
|
129
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
|
|
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")
|
|
131
131
|
|
|
132
132
|
Returns true when some of the items in the iterable are equal to the target
|
|
133
133
|
object.
|
|
@@ -135,13 +135,13 @@ object.
|
|
|
135
135
|
Examples:
|
|
136
136
|
|
|
137
137
|
```ts
|
|
138
|
-
contains([],
|
|
138
|
+
contains([], "whatever"); // => false
|
|
139
139
|
contains([3], 42); // => false
|
|
140
140
|
contains([3], 3); // => true
|
|
141
141
|
contains([0, 1, 2], 2); // => true
|
|
142
142
|
```
|
|
143
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
|
|
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")
|
|
145
145
|
|
|
146
146
|
Returns an iterable of enumeration pairs. Iterable must be a sequence, an
|
|
147
147
|
iterator, or some other object which supports iteration. The elements produced
|
|
@@ -151,28 +151,28 @@ the values obtained from iterating over given iterable.
|
|
|
151
151
|
Example:
|
|
152
152
|
|
|
153
153
|
```ts
|
|
154
|
-
import { enumerate } from
|
|
154
|
+
import { enumerate } from "itertools";
|
|
155
155
|
|
|
156
|
-
console.log([...enumerate([
|
|
156
|
+
console.log([...enumerate(["hello", "world"])]);
|
|
157
157
|
// [0, 'hello'], [1, 'world']]
|
|
158
158
|
```
|
|
159
159
|
|
|
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
|
|
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")
|
|
161
161
|
|
|
162
162
|
Eager version of [ifilter](#ifilter).
|
|
163
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
|
|
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")
|
|
165
165
|
|
|
166
166
|
Returns an iterator object for the given iterable. This can be used to
|
|
167
167
|
manually get an iterator for any iterable datastructure. The purpose and main
|
|
168
168
|
use case of this function is to get a single iterator (a thing with state,
|
|
169
169
|
think of it as a "cursor") which can only be consumed once.
|
|
170
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
|
|
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")
|
|
172
172
|
|
|
173
173
|
Eager version of [imap](#imap).
|
|
174
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
|
|
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")
|
|
176
176
|
|
|
177
177
|
Return the largest item in an iterable. Only works for numbers, as ordering is
|
|
178
178
|
pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
@@ -184,7 +184,7 @@ If the iterable is empty, `undefined` is returned.
|
|
|
184
184
|
If multiple items are maximal, the function returns either one of them, but
|
|
185
185
|
which one is not defined.
|
|
186
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
|
|
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")
|
|
188
188
|
|
|
189
189
|
Return the smallest item in an iterable. Only works for numbers, as ordering
|
|
190
190
|
is pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
@@ -196,8 +196,8 @@ If the iterable is empty, `undefined` is returned.
|
|
|
196
196
|
If multiple items are minimal, the function returns either one of them, but
|
|
197
197
|
which one is not defined.
|
|
198
198
|
|
|
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
|
|
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")
|
|
201
201
|
|
|
202
202
|
Returns an iterator producing all the numbers in the given range one by one,
|
|
203
203
|
starting from `start` (default 0), as long as `i < stop`, in increments of
|
|
@@ -222,8 +222,8 @@ the stop condition `n > stop` is satisfied.
|
|
|
222
222
|
The produced range will be empty if the first value to produce already does not
|
|
223
223
|
meet the value constraint.
|
|
224
224
|
|
|
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
|
|
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
|
|
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")
|
|
227
227
|
|
|
228
228
|
Apply function of two arguments cumulatively to the items of sequence, from
|
|
229
229
|
left to right, so as to reduce the sequence to a single value. For example:
|
|
@@ -249,114 +249,161 @@ it calculates
|
|
|
249
249
|
|
|
250
250
|
((((1+2)+3)+4)+5)
|
|
251
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
|
|
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")
|
|
253
253
|
|
|
254
254
|
Return a new sorted list from the items in iterable.
|
|
255
255
|
|
|
256
256
|
Has two optional arguments:
|
|
257
257
|
|
|
258
|
-
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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.
|
|
262
262
|
|
|
263
|
-
-
|
|
264
|
-
|
|
263
|
+
- `reverse` is a boolean value. If `true`, then the list elements are sorted
|
|
264
|
+
as if each comparison were reversed.
|
|
265
265
|
|
|
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
|
|
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")
|
|
267
267
|
|
|
268
268
|
Sums the items of an iterable from left to right and returns the total. The
|
|
269
269
|
sum will defaults to 0 if the iterable is empty.
|
|
270
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
|
|
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
|
|
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")
|
|
273
273
|
|
|
274
274
|
Eager version of [izip](#izip) / [izip3](#izip3).
|
|
275
275
|
|
|
276
276
|
### Ports of itertools
|
|
277
277
|
|
|
278
|
-
-
|
|
279
|
-
-
|
|
280
|
-
-
|
|
281
|
-
-
|
|
282
|
-
-
|
|
283
|
-
-
|
|
284
|
-
-
|
|
285
|
-
-
|
|
286
|
-
-
|
|
287
|
-
-
|
|
288
|
-
-
|
|
289
|
-
-
|
|
290
|
-
-
|
|
291
|
-
-
|
|
292
|
-
-
|
|
293
|
-
-
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
+
- [igroupby](#igroupby)
|
|
287
|
+
- [imap](#imap)
|
|
288
|
+
- [indexBy](#indexBy)
|
|
289
|
+
- [islice](#islice)
|
|
290
|
+
- [izip](#izip)
|
|
291
|
+
- [izip3](#izip3)
|
|
292
|
+
- [izipLongest](#izipLongest)
|
|
293
|
+
- [izipMany](#izipMany)
|
|
294
|
+
- [permutations](#permutations)
|
|
295
|
+
- [repeat](#repeat)
|
|
296
|
+
- [takewhile](#takewhile)
|
|
297
|
+
- [zipLongest](#zipLongest)
|
|
298
|
+
- [zipMany](#zipMany)
|
|
299
|
+
|
|
300
|
+
<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
301
|
|
|
300
302
|
Returns an iterator that returns elements from the first iterable until it is
|
|
301
303
|
exhausted, then proceeds to the next iterable, until all of the iterables are
|
|
302
304
|
exhausted. Used for treating consecutive sequences as a single sequence.
|
|
303
305
|
|
|
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
|
|
306
|
+
<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
307
|
|
|
306
308
|
Eager version of [icompress](#icompress).
|
|
307
309
|
|
|
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
|
|
310
|
+
<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
311
|
|
|
310
312
|
Returns an iterator that counts up values starting with number `start` (default
|
|
311
313
|
0), incrementing by `step`. To decrement, use a negative step number.
|
|
312
314
|
|
|
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
|
|
315
|
+
<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
316
|
|
|
315
317
|
Returns an iterator producing elements from the iterable and saving a copy of
|
|
316
318
|
each. When the iterable is exhausted, return elements from the saved copy.
|
|
317
319
|
Repeats indefinitely.
|
|
318
320
|
|
|
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
|
|
321
|
+
<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
322
|
|
|
321
323
|
Returns an iterator that drops elements from the iterable as long as the
|
|
322
324
|
predicate is true; afterwards, returns every remaining element. **Note:** the
|
|
323
325
|
iterator does not produce any output until the predicate first becomes false.
|
|
324
326
|
|
|
325
|
-
<a name="
|
|
327
|
+
<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")
|
|
328
|
+
|
|
329
|
+
Groups elements of the iterable into a record based on the key function. Each
|
|
330
|
+
key maps to an array of all elements that share the same key.
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
const users = [
|
|
334
|
+
{ name: "Alice", department: "Engineering" },
|
|
335
|
+
{ name: "Bob", department: "Sales" },
|
|
336
|
+
{ name: "Charlie", department: "Engineering" },
|
|
337
|
+
];
|
|
338
|
+
|
|
339
|
+
groupBy(users, (user) => user.department);
|
|
340
|
+
// {
|
|
341
|
+
// 'Engineering': [
|
|
342
|
+
// { name: 'Alice', department: 'Engineering' },
|
|
343
|
+
// { name: 'Charlie', department: 'Engineering' }
|
|
344
|
+
// ],
|
|
345
|
+
// 'Sales': [
|
|
346
|
+
// { name: 'Bob', department: 'Sales' }
|
|
347
|
+
// ]
|
|
348
|
+
// }
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
<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")
|
|
352
|
+
|
|
353
|
+
Returns an iterator that filters elements from data returning only those that
|
|
354
|
+
have a corresponding element in selectors that evaluates to `true`. Stops when
|
|
355
|
+
either the data or selectors iterables has been exhausted.
|
|
356
|
+
|
|
357
|
+
<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")
|
|
358
|
+
|
|
359
|
+
Returns an iterator that filters elements from iterable returning only those
|
|
360
|
+
for which the predicate is true.
|
|
361
|
+
|
|
362
|
+
<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
363
|
|
|
327
364
|
Make an Iterable that returns consecutive keys and groups from the iterable.
|
|
328
365
|
The key is a function computing a key value for each element. If not specified,
|
|
329
366
|
key defaults to an identity function and returns the element unchanged.
|
|
330
367
|
Generally, the iterable needs to already be sorted on the same key function.
|
|
331
368
|
|
|
332
|
-
The operation of `
|
|
369
|
+
The operation of `igroupby()` is similar to the `uniq` filter in Unix. It
|
|
333
370
|
generates a break or new group every time the value of the key function changes
|
|
334
371
|
(which is why it is usually necessary to have sorted the data using the same
|
|
335
372
|
key function). That behavior differs from `SQL`’s `GROUP BY` which aggregates
|
|
336
373
|
common elements regardless of their input order.
|
|
337
374
|
|
|
338
375
|
The returned group is itself an iterator that shares the underlying iterable
|
|
339
|
-
with `
|
|
376
|
+
with `igroupby()`. Because the source is shared, when the `igroupby()` object is
|
|
340
377
|
advanced, the previous group is no longer visible. So, if that data is needed
|
|
341
378
|
later, it should be stored as an array.
|
|
342
379
|
|
|
343
|
-
<a name="
|
|
380
|
+
<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
381
|
|
|
345
|
-
Returns an iterator that
|
|
346
|
-
|
|
347
|
-
either the data or selectors iterables has been exhausted.
|
|
382
|
+
Returns an iterator that computes the given mapper function using arguments
|
|
383
|
+
from each of the iterables.
|
|
348
384
|
|
|
349
|
-
<a name="
|
|
385
|
+
<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")
|
|
350
386
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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')
|
|
387
|
+
Creates an index (record) from the iterable where each key maps to the last
|
|
388
|
+
element that produced that key. If multiple elements produce the same key, only
|
|
389
|
+
the last one is kept.
|
|
355
390
|
|
|
356
|
-
|
|
357
|
-
|
|
391
|
+
```ts
|
|
392
|
+
const users = [
|
|
393
|
+
{ id: 1, name: "Alice" },
|
|
394
|
+
{ id: 2, name: "Bob" },
|
|
395
|
+
{ id: 3, name: "Charlie" },
|
|
396
|
+
];
|
|
397
|
+
|
|
398
|
+
indexBy(users, (user) => user.id);
|
|
399
|
+
// {
|
|
400
|
+
// 1: { id: 1, name: 'Alice' },
|
|
401
|
+
// 2: { id: 2, name: 'Bob' },
|
|
402
|
+
// 3: { id: 3, name: 'Charlie' }
|
|
403
|
+
// }
|
|
404
|
+
```
|
|
358
405
|
|
|
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
|
|
406
|
+
<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
407
|
|
|
361
408
|
Returns an iterator that returns selected elements from the iterable. If
|
|
362
409
|
`start` is non-zero, then elements from the iterable are skipped until start is
|
|
@@ -366,27 +413,27 @@ then iteration continues until the iterator reached that index, otherwise, the
|
|
|
366
413
|
iterable will be fully exhausted. `islice()` does not support negative values
|
|
367
414
|
for `start`, `stop`, or `step`.
|
|
368
415
|
|
|
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
|
|
416
|
+
<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 />
|
|
417
|
+
<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
418
|
|
|
372
419
|
Returns an iterator that aggregates elements from each of the iterables. Used
|
|
373
420
|
for lock-step iteration over several iterables at a time. When iterating over
|
|
374
421
|
two iterables, use `izip2`. When iterating over three iterables, use `izip3`,
|
|
375
422
|
etc. `izip` is an alias for `izip2`.
|
|
376
423
|
|
|
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
|
|
424
|
+
<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 />
|
|
425
|
+
<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
426
|
|
|
380
427
|
Returns an iterator that aggregates elements from each of the iterables. If the
|
|
381
428
|
iterables are of uneven length, missing values are filled-in with fillvalue.
|
|
382
429
|
Iteration continues until the longest iterable is exhausted.
|
|
383
430
|
|
|
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
|
|
431
|
+
<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
432
|
|
|
386
433
|
Like the other izips (`izip`, `izip3`, etc), but generalized to take an
|
|
387
434
|
unlimited amount of input iterables. Think `izip(*iterables)` in Python.
|
|
388
435
|
|
|
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
|
|
436
|
+
<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
437
|
|
|
391
438
|
Return successive `r`-length permutations of elements in the iterable.
|
|
392
439
|
|
|
@@ -400,41 +447,41 @@ Elements are treated as unique based on their position, not on their value. So
|
|
|
400
447
|
if the input elements are unique, there will be no repeat values in each
|
|
401
448
|
permutation.
|
|
402
449
|
|
|
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
|
|
450
|
+
<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
451
|
|
|
405
452
|
Returns an iterator that produces values over and over again. Runs
|
|
406
453
|
indefinitely unless the times argument is specified.
|
|
407
454
|
|
|
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
|
|
455
|
+
<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
456
|
|
|
410
457
|
Returns an iterator that produces elements from the iterable as long as the
|
|
411
458
|
predicate is true.
|
|
412
459
|
|
|
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
|
|
460
|
+
<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 />
|
|
461
|
+
<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
462
|
|
|
416
463
|
Eager version of [izipLongest](#izipLongest) and friends.
|
|
417
464
|
|
|
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
|
|
465
|
+
<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
466
|
|
|
420
467
|
Eager version of [izipMany](#izipMany).
|
|
421
468
|
|
|
422
469
|
### Ports of more-itertools
|
|
423
470
|
|
|
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
|
|
471
|
+
- [chunked](#chunked)
|
|
472
|
+
- [flatten](#flatten)
|
|
473
|
+
- [intersperse](#intersperse)
|
|
474
|
+
- [itake](#itake)
|
|
475
|
+
- [pairwise](#pairwise)
|
|
476
|
+
- [partition](#partition)
|
|
477
|
+
- [roundrobin](#roundrobin)
|
|
478
|
+
- [heads](#heads)
|
|
479
|
+
- [take](#take)
|
|
480
|
+
- [uniqueEverseen](#uniqueEverseen)
|
|
481
|
+
- [uniqueJustseen](#uniqueJustseen)
|
|
482
|
+
- [dupes](#dupes)
|
|
483
|
+
|
|
484
|
+
<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
485
|
|
|
439
486
|
Break iterable into lists of length `size`:
|
|
440
487
|
|
|
@@ -447,26 +494,26 @@ list will be shorter:
|
|
|
447
494
|
>>> [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]
|
|
448
495
|
[[1, 2, 3], [4, 5, 6], [7, 8]]
|
|
449
496
|
|
|
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
|
|
497
|
+
<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
498
|
|
|
452
499
|
Return an iterator flattening one level of nesting in a list of lists:
|
|
453
500
|
|
|
454
501
|
>>> [...flatten([[0, 1], [2, 3]])]
|
|
455
502
|
[0, 1, 2, 3]
|
|
456
503
|
|
|
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
|
|
504
|
+
<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
505
|
|
|
459
506
|
Intersperse filler element `value` among the items in `iterable`.
|
|
460
507
|
|
|
461
508
|
>>> [...intersperse(-1, range(1, 5))]
|
|
462
509
|
[1, -1, 2, -1, 3, -1, 4]
|
|
463
510
|
|
|
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
|
|
511
|
+
<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
512
|
|
|
466
513
|
Returns an iterable containing only the first `n` elements of the given
|
|
467
514
|
iterable.
|
|
468
515
|
|
|
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
|
|
516
|
+
<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
517
|
|
|
471
518
|
Returns an iterator of paired items, overlapping, from the original. When the
|
|
472
519
|
input iterable has a finite number of items `n`, the outputted iterable will
|
|
@@ -475,7 +522,7 @@ have `n - 1` items.
|
|
|
475
522
|
>>> pairwise([8, 2, 0, 7])
|
|
476
523
|
[(8, 2), (2, 0), (0, 7)]
|
|
477
524
|
|
|
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
|
|
525
|
+
<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
526
|
|
|
480
527
|
Returns a 2-tuple of arrays. Splits the elements in the input iterable into
|
|
481
528
|
either of the two arrays. Will fully exhaust the input iterable. The first
|
|
@@ -489,7 +536,7 @@ array contains all items that match the predicate, the second the rest:
|
|
|
489
536
|
>>> evens
|
|
490
537
|
[0, 2, 4, 6, 8]
|
|
491
538
|
|
|
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
|
|
539
|
+
<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
540
|
|
|
494
541
|
Yields the next item from each iterable in turn, alternating between them.
|
|
495
542
|
Continues until all items are exhausted.
|
|
@@ -497,18 +544,18 @@ Continues until all items are exhausted.
|
|
|
497
544
|
>>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
498
545
|
[1, 4, 5, 2, 6, 3, 7, 8]
|
|
499
546
|
|
|
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
|
|
547
|
+
<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
548
|
|
|
502
549
|
Like `roundrobin()`, but will group the output per "round".
|
|
503
550
|
|
|
504
551
|
>>> [...heads([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
505
552
|
[[1, 4, 5], [2, 6], [3, 7], [8]]
|
|
506
553
|
|
|
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
|
|
554
|
+
<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
555
|
|
|
509
556
|
Eager version of [itake](#itake).
|
|
510
557
|
|
|
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
|
|
558
|
+
<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
559
|
|
|
513
560
|
Yield unique elements, preserving order.
|
|
514
561
|
|
|
@@ -517,7 +564,7 @@ Yield unique elements, preserving order.
|
|
|
517
564
|
>>> [...uniqueEverseen('AbBCcAB', s => s.toLowerCase())]
|
|
518
565
|
['A', 'b', 'C']
|
|
519
566
|
|
|
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
|
|
567
|
+
<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
568
|
|
|
522
569
|
Yields elements in order, ignoring serial duplicates.
|
|
523
570
|
|
|
@@ -526,7 +573,7 @@ Yields elements in order, ignoring serial duplicates.
|
|
|
526
573
|
>>> [...uniqueJustseen('AbBCcAB', s => s.toLowerCase())]
|
|
527
574
|
['A', 'b', 'C', 'A', 'B']
|
|
528
575
|
|
|
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
|
|
576
|
+
<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
577
|
|
|
531
578
|
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
579
|
|
|
@@ -537,31 +584,31 @@ Yield only elements from the input that occur more than once. Needs to consume t
|
|
|
537
584
|
|
|
538
585
|
### Additions
|
|
539
586
|
|
|
540
|
-
-
|
|
541
|
-
-
|
|
542
|
-
-
|
|
543
|
-
-
|
|
544
|
-
-
|
|
545
|
-
-
|
|
587
|
+
- [compact](#compact)
|
|
588
|
+
- [compactObject](#compactObject)
|
|
589
|
+
- [find](#find)
|
|
590
|
+
- [first](#first)
|
|
591
|
+
- [flatmap](#flatmap)
|
|
592
|
+
- [icompact](#icompact)
|
|
546
593
|
|
|
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
|
|
594
|
+
<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
595
|
|
|
549
596
|
Eager version of [icompact](#icompact).
|
|
550
597
|
|
|
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
|
|
598
|
+
<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
599
|
|
|
553
600
|
Removes all "nullish" values from the given object. Returns a new object.
|
|
554
601
|
|
|
555
602
|
>>> compactObject({ a: 1, b: undefined, c: 0, d: null })
|
|
556
603
|
{ a: 1, c: 0, d: null }
|
|
557
604
|
|
|
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
|
|
605
|
+
<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
606
|
|
|
560
607
|
Returns the first item in the iterable for which the predicate holds, if any.
|
|
561
608
|
If no such item exists, `undefined` is returned. If no default predicate is
|
|
562
609
|
given, the first value from the iterable is returned.
|
|
563
610
|
|
|
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
|
|
611
|
+
<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
612
|
|
|
566
613
|
Almost the same as `find()`, except when no explicit predicate function is
|
|
567
614
|
given. `find()` will always return the first value in the iterable, whereas
|
|
@@ -569,7 +616,7 @@ given. `find()` will always return the first value in the iterable, whereas
|
|
|
569
616
|
|
|
570
617
|
Prefer using `find()`, as its behavior is more intuitive and predictable.
|
|
571
618
|
|
|
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
|
|
619
|
+
<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
620
|
|
|
574
621
|
Returns 0 or more values for every value in the given iterable. Technically,
|
|
575
622
|
it's just calling map(), followed by flatten(), but it's a very useful
|
|
@@ -583,7 +630,7 @@ For example, to return all numbers `n` in the input iterable `n` times:
|
|
|
583
630
|
>>> [...flatmap([0, 1, 2, 3, 4], repeatN)]
|
|
584
631
|
[1, 2, 2, 3, 3, 3, 4, 4, 4, 4] // note: no 0
|
|
585
632
|
|
|
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
|
|
633
|
+
<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
634
|
|
|
588
635
|
Returns an iterable, filtering out any "nullish" values from the input
|
|
589
636
|
iterable.
|