itertools 1.7.1 → 2.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 +1 -1
- package/dist/index.d.mts +433 -0
- package/dist/index.d.ts +433 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +46 -9
- package/CHANGELOG.md +0 -97
- package/builtins.d.ts +0 -18
- package/builtins.js +0 -467
- package/builtins.js.flow +0 -294
- package/custom.d.ts +0 -7
- package/custom.js +0 -186
- package/custom.js.flow +0 -82
- package/index.d.ts +0 -52
- package/index.js +0 -307
- package/index.js.flow +0 -57
- package/itertools.d.ts +0 -52
- package/itertools.js +0 -1287
- package/itertools.js.flow +0 -423
- package/more-itertools.d.ts +0 -13
- package/more-itertools.js +0 -739
- package/more-itertools.js.flow +0 -261
- package/types.d.ts +0 -3
- package/types.js +0 -1
- package/types.js.flow +0 -5
- package/utils.d.ts +0 -8
- package/utils.js +0 -48
- package/utils.js.flow +0 -42
package/more-itertools.js
DELETED
|
@@ -1,739 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _regeneratorRuntime2 = require("@babel/runtime/regenerator");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.chunked = chunked;
|
|
9
|
-
exports.flatten = flatten;
|
|
10
|
-
exports.intersperse = intersperse;
|
|
11
|
-
exports.itake = itake;
|
|
12
|
-
exports.pairwise = pairwise;
|
|
13
|
-
exports.partition = partition;
|
|
14
|
-
exports.roundrobin = roundrobin;
|
|
15
|
-
exports.heads = heads;
|
|
16
|
-
exports.take = take;
|
|
17
|
-
exports.uniqueEverseen = uniqueEverseen;
|
|
18
|
-
exports.uniqueJustseen = uniqueJustseen;
|
|
19
|
-
|
|
20
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
21
|
-
|
|
22
|
-
var _builtins = require("./builtins");
|
|
23
|
-
|
|
24
|
-
var _itertools = require("./itertools");
|
|
25
|
-
|
|
26
|
-
var _utils = require("./utils");
|
|
27
|
-
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
29
|
-
|
|
30
|
-
var _marked = /*#__PURE__*/_regeneratorRuntime2.mark(chunked),
|
|
31
|
-
_marked2 = /*#__PURE__*/_regeneratorRuntime2.mark(flatten),
|
|
32
|
-
_marked3 = /*#__PURE__*/_regeneratorRuntime2.mark(itake),
|
|
33
|
-
_marked4 = /*#__PURE__*/_regeneratorRuntime2.mark(pairwise),
|
|
34
|
-
_marked5 = /*#__PURE__*/_regeneratorRuntime2.mark(roundrobin),
|
|
35
|
-
_marked6 = /*#__PURE__*/_regeneratorRuntime2.mark(heads),
|
|
36
|
-
_marked7 = /*#__PURE__*/_regeneratorRuntime2.mark(uniqueEverseen),
|
|
37
|
-
_marked8 = /*#__PURE__*/_regeneratorRuntime2.mark(uniqueJustseen);
|
|
38
|
-
|
|
39
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
40
|
-
|
|
41
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
42
|
-
|
|
43
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Break iterable into lists of length `size`:
|
|
47
|
-
*
|
|
48
|
-
* [...chunked([1, 2, 3, 4, 5, 6], 3)]
|
|
49
|
-
* // [[1, 2, 3], [4, 5, 6]]
|
|
50
|
-
*
|
|
51
|
-
* If the length of iterable is not evenly divisible by `size`, the last returned
|
|
52
|
-
* list will be shorter:
|
|
53
|
-
*
|
|
54
|
-
* [...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]
|
|
55
|
-
* // [[1, 2, 3], [4, 5, 6], [7, 8]]
|
|
56
|
-
*/
|
|
57
|
-
function chunked(iterable, size) {
|
|
58
|
-
var it, r1, chunk, _iterator, _step, item;
|
|
59
|
-
|
|
60
|
-
return _regenerator["default"].wrap(function chunked$(_context) {
|
|
61
|
-
while (1) {
|
|
62
|
-
switch (_context.prev = _context.next) {
|
|
63
|
-
case 0:
|
|
64
|
-
it = (0, _builtins.iter)(iterable);
|
|
65
|
-
r1 = it.next();
|
|
66
|
-
|
|
67
|
-
if (!r1.done) {
|
|
68
|
-
_context.next = 4;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return _context.abrupt("return");
|
|
73
|
-
|
|
74
|
-
case 4:
|
|
75
|
-
chunk = [r1.value];
|
|
76
|
-
_iterator = _createForOfIteratorHelper(it);
|
|
77
|
-
_context.prev = 6;
|
|
78
|
-
|
|
79
|
-
_iterator.s();
|
|
80
|
-
|
|
81
|
-
case 8:
|
|
82
|
-
if ((_step = _iterator.n()).done) {
|
|
83
|
-
_context.next = 17;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
item = _step.value;
|
|
88
|
-
chunk.push(item);
|
|
89
|
-
|
|
90
|
-
if (!(chunk.length === size)) {
|
|
91
|
-
_context.next = 15;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
_context.next = 14;
|
|
96
|
-
return chunk;
|
|
97
|
-
|
|
98
|
-
case 14:
|
|
99
|
-
chunk = [];
|
|
100
|
-
|
|
101
|
-
case 15:
|
|
102
|
-
_context.next = 8;
|
|
103
|
-
break;
|
|
104
|
-
|
|
105
|
-
case 17:
|
|
106
|
-
_context.next = 22;
|
|
107
|
-
break;
|
|
108
|
-
|
|
109
|
-
case 19:
|
|
110
|
-
_context.prev = 19;
|
|
111
|
-
_context.t0 = _context["catch"](6);
|
|
112
|
-
|
|
113
|
-
_iterator.e(_context.t0);
|
|
114
|
-
|
|
115
|
-
case 22:
|
|
116
|
-
_context.prev = 22;
|
|
117
|
-
|
|
118
|
-
_iterator.f();
|
|
119
|
-
|
|
120
|
-
return _context.finish(22);
|
|
121
|
-
|
|
122
|
-
case 25:
|
|
123
|
-
if (!(chunk.length > 0)) {
|
|
124
|
-
_context.next = 28;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
_context.next = 28;
|
|
129
|
-
return chunk;
|
|
130
|
-
|
|
131
|
-
case 28:
|
|
132
|
-
case "end":
|
|
133
|
-
return _context.stop();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}, _marked, null, [[6, 19, 22, 25]]);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Return an iterator flattening one level of nesting in a list of lists:
|
|
140
|
-
*
|
|
141
|
-
* [...flatten([[0, 1], [2, 3]])]
|
|
142
|
-
* // [0, 1, 2, 3]
|
|
143
|
-
*
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
function flatten(iterableOfIterables) {
|
|
148
|
-
var _iterator2, _step2, iterable, _iterator3, _step3, item;
|
|
149
|
-
|
|
150
|
-
return _regenerator["default"].wrap(function flatten$(_context2) {
|
|
151
|
-
while (1) {
|
|
152
|
-
switch (_context2.prev = _context2.next) {
|
|
153
|
-
case 0:
|
|
154
|
-
_iterator2 = _createForOfIteratorHelper(iterableOfIterables);
|
|
155
|
-
_context2.prev = 1;
|
|
156
|
-
|
|
157
|
-
_iterator2.s();
|
|
158
|
-
|
|
159
|
-
case 3:
|
|
160
|
-
if ((_step2 = _iterator2.n()).done) {
|
|
161
|
-
_context2.next = 24;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
iterable = _step2.value;
|
|
166
|
-
_iterator3 = _createForOfIteratorHelper(iterable);
|
|
167
|
-
_context2.prev = 6;
|
|
168
|
-
|
|
169
|
-
_iterator3.s();
|
|
170
|
-
|
|
171
|
-
case 8:
|
|
172
|
-
if ((_step3 = _iterator3.n()).done) {
|
|
173
|
-
_context2.next = 14;
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
item = _step3.value;
|
|
178
|
-
_context2.next = 12;
|
|
179
|
-
return item;
|
|
180
|
-
|
|
181
|
-
case 12:
|
|
182
|
-
_context2.next = 8;
|
|
183
|
-
break;
|
|
184
|
-
|
|
185
|
-
case 14:
|
|
186
|
-
_context2.next = 19;
|
|
187
|
-
break;
|
|
188
|
-
|
|
189
|
-
case 16:
|
|
190
|
-
_context2.prev = 16;
|
|
191
|
-
_context2.t0 = _context2["catch"](6);
|
|
192
|
-
|
|
193
|
-
_iterator3.e(_context2.t0);
|
|
194
|
-
|
|
195
|
-
case 19:
|
|
196
|
-
_context2.prev = 19;
|
|
197
|
-
|
|
198
|
-
_iterator3.f();
|
|
199
|
-
|
|
200
|
-
return _context2.finish(19);
|
|
201
|
-
|
|
202
|
-
case 22:
|
|
203
|
-
_context2.next = 3;
|
|
204
|
-
break;
|
|
205
|
-
|
|
206
|
-
case 24:
|
|
207
|
-
_context2.next = 29;
|
|
208
|
-
break;
|
|
209
|
-
|
|
210
|
-
case 26:
|
|
211
|
-
_context2.prev = 26;
|
|
212
|
-
_context2.t1 = _context2["catch"](1);
|
|
213
|
-
|
|
214
|
-
_iterator2.e(_context2.t1);
|
|
215
|
-
|
|
216
|
-
case 29:
|
|
217
|
-
_context2.prev = 29;
|
|
218
|
-
|
|
219
|
-
_iterator2.f();
|
|
220
|
-
|
|
221
|
-
return _context2.finish(29);
|
|
222
|
-
|
|
223
|
-
case 32:
|
|
224
|
-
case "end":
|
|
225
|
-
return _context2.stop();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}, _marked2, null, [[1, 26, 29, 32], [6, 16, 19, 22]]);
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Intersperse filler element `value` among the items in `iterable`.
|
|
232
|
-
*
|
|
233
|
-
* >>> [...intersperse(-1, range(1, 5))]
|
|
234
|
-
* [1, -1, 2, -1, 3, -1, 4]
|
|
235
|
-
*
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
function intersperse(value, iterable) {
|
|
240
|
-
var stream = flatten((0, _itertools.izip)((0, _itertools.repeat)(value), iterable));
|
|
241
|
-
take(1, stream); // eat away and discard the first value from the output
|
|
242
|
-
|
|
243
|
-
return stream;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Returns an iterable containing only the first `n` elements of the given
|
|
247
|
-
* iterable.
|
|
248
|
-
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
function itake(n, iterable) {
|
|
252
|
-
var it, count, s;
|
|
253
|
-
return _regenerator["default"].wrap(function itake$(_context3) {
|
|
254
|
-
while (1) {
|
|
255
|
-
switch (_context3.prev = _context3.next) {
|
|
256
|
-
case 0:
|
|
257
|
-
it = (0, _builtins.iter)(iterable);
|
|
258
|
-
count = n;
|
|
259
|
-
|
|
260
|
-
case 2:
|
|
261
|
-
if (!(count-- > 0)) {
|
|
262
|
-
_context3.next = 12;
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
s = it.next();
|
|
267
|
-
|
|
268
|
-
if (s.done) {
|
|
269
|
-
_context3.next = 9;
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
_context3.next = 7;
|
|
274
|
-
return s.value;
|
|
275
|
-
|
|
276
|
-
case 7:
|
|
277
|
-
_context3.next = 10;
|
|
278
|
-
break;
|
|
279
|
-
|
|
280
|
-
case 9:
|
|
281
|
-
return _context3.abrupt("return");
|
|
282
|
-
|
|
283
|
-
case 10:
|
|
284
|
-
_context3.next = 2;
|
|
285
|
-
break;
|
|
286
|
-
|
|
287
|
-
case 12:
|
|
288
|
-
case "end":
|
|
289
|
-
return _context3.stop();
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}, _marked3);
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Returns an iterator of paired items, overlapping, from the original. When
|
|
296
|
-
* the input iterable has a finite number of items `n`, the outputted iterable
|
|
297
|
-
* will have `n - 1` items.
|
|
298
|
-
*
|
|
299
|
-
* >>> pairwise([8, 2, 0, 7])
|
|
300
|
-
* [(8, 2), (2, 0), (0, 7)]
|
|
301
|
-
*
|
|
302
|
-
*/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
function pairwise(iterable) {
|
|
306
|
-
var it, r1, _iterator4, _step4, r2;
|
|
307
|
-
|
|
308
|
-
return _regenerator["default"].wrap(function pairwise$(_context4) {
|
|
309
|
-
while (1) {
|
|
310
|
-
switch (_context4.prev = _context4.next) {
|
|
311
|
-
case 0:
|
|
312
|
-
it = (0, _builtins.iter)(iterable);
|
|
313
|
-
r1 = it.next();
|
|
314
|
-
|
|
315
|
-
if (!r1.done) {
|
|
316
|
-
_context4.next = 4;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return _context4.abrupt("return");
|
|
321
|
-
|
|
322
|
-
case 4:
|
|
323
|
-
r1 = r1.value;
|
|
324
|
-
_iterator4 = _createForOfIteratorHelper(it);
|
|
325
|
-
_context4.prev = 6;
|
|
326
|
-
|
|
327
|
-
_iterator4.s();
|
|
328
|
-
|
|
329
|
-
case 8:
|
|
330
|
-
if ((_step4 = _iterator4.n()).done) {
|
|
331
|
-
_context4.next = 15;
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
r2 = _step4.value;
|
|
336
|
-
_context4.next = 12;
|
|
337
|
-
return [r1, r2];
|
|
338
|
-
|
|
339
|
-
case 12:
|
|
340
|
-
r1 = r2;
|
|
341
|
-
|
|
342
|
-
case 13:
|
|
343
|
-
_context4.next = 8;
|
|
344
|
-
break;
|
|
345
|
-
|
|
346
|
-
case 15:
|
|
347
|
-
_context4.next = 20;
|
|
348
|
-
break;
|
|
349
|
-
|
|
350
|
-
case 17:
|
|
351
|
-
_context4.prev = 17;
|
|
352
|
-
_context4.t0 = _context4["catch"](6);
|
|
353
|
-
|
|
354
|
-
_iterator4.e(_context4.t0);
|
|
355
|
-
|
|
356
|
-
case 20:
|
|
357
|
-
_context4.prev = 20;
|
|
358
|
-
|
|
359
|
-
_iterator4.f();
|
|
360
|
-
|
|
361
|
-
return _context4.finish(20);
|
|
362
|
-
|
|
363
|
-
case 23:
|
|
364
|
-
case "end":
|
|
365
|
-
return _context4.stop();
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}, _marked4, null, [[6, 17, 20, 23]]);
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Returns a 2-tuple of arrays. Splits the elements in the input iterable into
|
|
372
|
-
* either of the two arrays. Will fully exhaust the input iterable. The first
|
|
373
|
-
* array contains all items that match the predicate, the second the rest:
|
|
374
|
-
*
|
|
375
|
-
* >>> const isOdd = x => x % 2 !== 0;
|
|
376
|
-
* >>> const iterable = range(10);
|
|
377
|
-
* >>> const [odds, evens] = partition(iterable, isOdd);
|
|
378
|
-
* >>> odds
|
|
379
|
-
* [1, 3, 5, 7, 9]
|
|
380
|
-
* >>> evens
|
|
381
|
-
* [0, 2, 4, 6, 8]
|
|
382
|
-
*
|
|
383
|
-
*/
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
function partition(iterable, predicate) {
|
|
387
|
-
var good = [];
|
|
388
|
-
var bad = [];
|
|
389
|
-
|
|
390
|
-
var _iterator5 = _createForOfIteratorHelper(iterable),
|
|
391
|
-
_step5;
|
|
392
|
-
|
|
393
|
-
try {
|
|
394
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
395
|
-
var item = _step5.value;
|
|
396
|
-
|
|
397
|
-
if (predicate(item)) {
|
|
398
|
-
good.push(item);
|
|
399
|
-
} else {
|
|
400
|
-
bad.push(item);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
} catch (err) {
|
|
404
|
-
_iterator5.e(err);
|
|
405
|
-
} finally {
|
|
406
|
-
_iterator5.f();
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return [good, bad];
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Yields the next item from each iterable in turn, alternating between them.
|
|
413
|
-
* Continues until all items are exhausted.
|
|
414
|
-
*
|
|
415
|
-
* >>> [...roundrobin([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
416
|
-
* [1, 4, 5, 2, 6, 3, 7, 8]
|
|
417
|
-
*/
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
function roundrobin() {
|
|
421
|
-
var _len,
|
|
422
|
-
iters,
|
|
423
|
-
_key,
|
|
424
|
-
iterables,
|
|
425
|
-
index,
|
|
426
|
-
it,
|
|
427
|
-
result,
|
|
428
|
-
_args5 = arguments;
|
|
429
|
-
|
|
430
|
-
return _regenerator["default"].wrap(function roundrobin$(_context5) {
|
|
431
|
-
while (1) {
|
|
432
|
-
switch (_context5.prev = _context5.next) {
|
|
433
|
-
case 0:
|
|
434
|
-
for (_len = _args5.length, iters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
435
|
-
iters[_key] = _args5[_key];
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
// We'll only keep lazy versions of the input iterables in here that we'll
|
|
439
|
-
// slowly going to exhaust. Once an iterable is exhausted, it will be
|
|
440
|
-
// removed from this list. Once the entire list is empty, this algorithm
|
|
441
|
-
// ends.
|
|
442
|
-
iterables = (0, _builtins.map)(iters, _builtins.iter);
|
|
443
|
-
|
|
444
|
-
case 2:
|
|
445
|
-
if (!(iterables.length > 0)) {
|
|
446
|
-
_context5.next = 18;
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
index = 0;
|
|
451
|
-
|
|
452
|
-
case 4:
|
|
453
|
-
if (!(index < iterables.length)) {
|
|
454
|
-
_context5.next = 16;
|
|
455
|
-
break;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
it = iterables[index];
|
|
459
|
-
result = it.next();
|
|
460
|
-
|
|
461
|
-
if (result.done) {
|
|
462
|
-
_context5.next = 13;
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
_context5.next = 10;
|
|
467
|
-
return result.value;
|
|
468
|
-
|
|
469
|
-
case 10:
|
|
470
|
-
index++;
|
|
471
|
-
_context5.next = 14;
|
|
472
|
-
break;
|
|
473
|
-
|
|
474
|
-
case 13:
|
|
475
|
-
// This iterable is exhausted, make sure to remove it from the
|
|
476
|
-
// list of iterables. We'll splice the array from under our
|
|
477
|
-
// feet, and NOT advancing the index counter.
|
|
478
|
-
iterables.splice(index, 1); // intentional side-effect!
|
|
479
|
-
|
|
480
|
-
case 14:
|
|
481
|
-
_context5.next = 4;
|
|
482
|
-
break;
|
|
483
|
-
|
|
484
|
-
case 16:
|
|
485
|
-
_context5.next = 2;
|
|
486
|
-
break;
|
|
487
|
-
|
|
488
|
-
case 18:
|
|
489
|
-
case "end":
|
|
490
|
-
return _context5.stop();
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}, _marked5);
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Yields the heads of all of the given iterables. This is almost like
|
|
497
|
-
* `roundrobin()`, except that the yielded outputs are grouped in to the
|
|
498
|
-
* "rounds":
|
|
499
|
-
*
|
|
500
|
-
* >>> [...heads([1, 2, 3], [4], [5, 6, 7, 8])]
|
|
501
|
-
* [[1, 4, 5], [2, 6], [3, 7], [8]]
|
|
502
|
-
*
|
|
503
|
-
* This is also different from `zipLongest()`, since the number of items in
|
|
504
|
-
* each round can decrease over time, rather than being filled with a filler.
|
|
505
|
-
*/
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
function heads() {
|
|
509
|
-
var _len2,
|
|
510
|
-
iters,
|
|
511
|
-
_key2,
|
|
512
|
-
iterables,
|
|
513
|
-
index,
|
|
514
|
-
round,
|
|
515
|
-
it,
|
|
516
|
-
result,
|
|
517
|
-
_args6 = arguments;
|
|
518
|
-
|
|
519
|
-
return _regenerator["default"].wrap(function heads$(_context6) {
|
|
520
|
-
while (1) {
|
|
521
|
-
switch (_context6.prev = _context6.next) {
|
|
522
|
-
case 0:
|
|
523
|
-
for (_len2 = _args6.length, iters = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
524
|
-
iters[_key2] = _args6[_key2];
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
// We'll only keep lazy versions of the input iterables in here that we'll
|
|
528
|
-
// slowly going to exhaust. Once an iterable is exhausted, it will be
|
|
529
|
-
// removed from this list. Once the entire list is empty, this algorithm
|
|
530
|
-
// ends.
|
|
531
|
-
iterables = (0, _builtins.map)(iters, _builtins.iter);
|
|
532
|
-
|
|
533
|
-
case 2:
|
|
534
|
-
if (!(iterables.length > 0)) {
|
|
535
|
-
_context6.next = 11;
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
index = 0;
|
|
540
|
-
round = [];
|
|
541
|
-
|
|
542
|
-
while (index < iterables.length) {
|
|
543
|
-
it = iterables[index];
|
|
544
|
-
result = it.next();
|
|
545
|
-
|
|
546
|
-
if (!result.done) {
|
|
547
|
-
round.push(result.value);
|
|
548
|
-
index++;
|
|
549
|
-
} else {
|
|
550
|
-
// This iterable is exhausted, make sure to remove it from the
|
|
551
|
-
// list of iterables. We'll splice the array from under our
|
|
552
|
-
// feet, and NOT advancing the index counter.
|
|
553
|
-
iterables.splice(index, 1); // intentional side-effect!
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
if (!(round.length > 0)) {
|
|
558
|
-
_context6.next = 9;
|
|
559
|
-
break;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
_context6.next = 9;
|
|
563
|
-
return round;
|
|
564
|
-
|
|
565
|
-
case 9:
|
|
566
|
-
_context6.next = 2;
|
|
567
|
-
break;
|
|
568
|
-
|
|
569
|
-
case 11:
|
|
570
|
-
case "end":
|
|
571
|
-
return _context6.stop();
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}, _marked6);
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Non-lazy version of itake().
|
|
578
|
-
*/
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
function take(n, iterable) {
|
|
582
|
-
return Array.from(itake(n, iterable));
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Yield unique elements, preserving order.
|
|
586
|
-
*
|
|
587
|
-
* >>> [...uniqueEverseen('AAAABBBCCDAABBB')]
|
|
588
|
-
* ['A', 'B', 'C', 'D']
|
|
589
|
-
* >>> [...uniqueEverseen('AbBCcAB', s => s.toLowerCase())]
|
|
590
|
-
* ['A', 'b', 'C']
|
|
591
|
-
*
|
|
592
|
-
*/
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
function uniqueEverseen(iterable) {
|
|
596
|
-
var keyFn,
|
|
597
|
-
seen,
|
|
598
|
-
_iterator6,
|
|
599
|
-
_step6,
|
|
600
|
-
item,
|
|
601
|
-
key,
|
|
602
|
-
_args7 = arguments;
|
|
603
|
-
|
|
604
|
-
return _regenerator["default"].wrap(function uniqueEverseen$(_context7) {
|
|
605
|
-
while (1) {
|
|
606
|
-
switch (_context7.prev = _context7.next) {
|
|
607
|
-
case 0:
|
|
608
|
-
keyFn = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : _utils.primitiveIdentity;
|
|
609
|
-
seen = new Set();
|
|
610
|
-
_iterator6 = _createForOfIteratorHelper(iterable);
|
|
611
|
-
_context7.prev = 3;
|
|
612
|
-
|
|
613
|
-
_iterator6.s();
|
|
614
|
-
|
|
615
|
-
case 5:
|
|
616
|
-
if ((_step6 = _iterator6.n()).done) {
|
|
617
|
-
_context7.next = 14;
|
|
618
|
-
break;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
item = _step6.value;
|
|
622
|
-
key = keyFn(item);
|
|
623
|
-
|
|
624
|
-
if (seen.has(key)) {
|
|
625
|
-
_context7.next = 12;
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
seen.add(key);
|
|
630
|
-
_context7.next = 12;
|
|
631
|
-
return item;
|
|
632
|
-
|
|
633
|
-
case 12:
|
|
634
|
-
_context7.next = 5;
|
|
635
|
-
break;
|
|
636
|
-
|
|
637
|
-
case 14:
|
|
638
|
-
_context7.next = 19;
|
|
639
|
-
break;
|
|
640
|
-
|
|
641
|
-
case 16:
|
|
642
|
-
_context7.prev = 16;
|
|
643
|
-
_context7.t0 = _context7["catch"](3);
|
|
644
|
-
|
|
645
|
-
_iterator6.e(_context7.t0);
|
|
646
|
-
|
|
647
|
-
case 19:
|
|
648
|
-
_context7.prev = 19;
|
|
649
|
-
|
|
650
|
-
_iterator6.f();
|
|
651
|
-
|
|
652
|
-
return _context7.finish(19);
|
|
653
|
-
|
|
654
|
-
case 22:
|
|
655
|
-
case "end":
|
|
656
|
-
return _context7.stop();
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}, _marked7, null, [[3, 16, 19, 22]]);
|
|
660
|
-
}
|
|
661
|
-
/**
|
|
662
|
-
* Yields elements in order, ignoring serial duplicates.
|
|
663
|
-
*
|
|
664
|
-
* >>> [...uniqueJustseen('AAAABBBCCDAABBB')]
|
|
665
|
-
* ['A', 'B', 'C', 'D', 'A', 'B']
|
|
666
|
-
* >>> [...uniqueJustseen('AbBCcAB', s => s.toLowerCase())]
|
|
667
|
-
* ['A', 'b', 'C', 'A', 'B']
|
|
668
|
-
*
|
|
669
|
-
*/
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
function uniqueJustseen(iterable) {
|
|
673
|
-
var keyFn,
|
|
674
|
-
last,
|
|
675
|
-
_iterator7,
|
|
676
|
-
_step7,
|
|
677
|
-
item,
|
|
678
|
-
key,
|
|
679
|
-
_args8 = arguments;
|
|
680
|
-
|
|
681
|
-
return _regenerator["default"].wrap(function uniqueJustseen$(_context8) {
|
|
682
|
-
while (1) {
|
|
683
|
-
switch (_context8.prev = _context8.next) {
|
|
684
|
-
case 0:
|
|
685
|
-
keyFn = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : _utils.primitiveIdentity;
|
|
686
|
-
last = undefined;
|
|
687
|
-
_iterator7 = _createForOfIteratorHelper(iterable);
|
|
688
|
-
_context8.prev = 3;
|
|
689
|
-
|
|
690
|
-
_iterator7.s();
|
|
691
|
-
|
|
692
|
-
case 5:
|
|
693
|
-
if ((_step7 = _iterator7.n()).done) {
|
|
694
|
-
_context8.next = 14;
|
|
695
|
-
break;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
item = _step7.value;
|
|
699
|
-
key = keyFn(item);
|
|
700
|
-
|
|
701
|
-
if (!(key !== last)) {
|
|
702
|
-
_context8.next = 12;
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
_context8.next = 11;
|
|
707
|
-
return item;
|
|
708
|
-
|
|
709
|
-
case 11:
|
|
710
|
-
last = key;
|
|
711
|
-
|
|
712
|
-
case 12:
|
|
713
|
-
_context8.next = 5;
|
|
714
|
-
break;
|
|
715
|
-
|
|
716
|
-
case 14:
|
|
717
|
-
_context8.next = 19;
|
|
718
|
-
break;
|
|
719
|
-
|
|
720
|
-
case 16:
|
|
721
|
-
_context8.prev = 16;
|
|
722
|
-
_context8.t0 = _context8["catch"](3);
|
|
723
|
-
|
|
724
|
-
_iterator7.e(_context8.t0);
|
|
725
|
-
|
|
726
|
-
case 19:
|
|
727
|
-
_context8.prev = 19;
|
|
728
|
-
|
|
729
|
-
_iterator7.f();
|
|
730
|
-
|
|
731
|
-
return _context8.finish(19);
|
|
732
|
-
|
|
733
|
-
case 22:
|
|
734
|
-
case "end":
|
|
735
|
-
return _context8.stop();
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}, _marked8, null, [[3, 16, 19, 22]]);
|
|
739
|
-
}
|