itertools 1.7.1 → 2.0.0-beta1
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 +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -5
- 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/builtins.js
DELETED
|
@@ -1,467 +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.all = all;
|
|
9
|
-
exports.any = any;
|
|
10
|
-
exports.contains = contains;
|
|
11
|
-
exports.enumerate = enumerate;
|
|
12
|
-
exports.filter = filter;
|
|
13
|
-
exports.iter = iter;
|
|
14
|
-
exports.map = map;
|
|
15
|
-
exports.max = max;
|
|
16
|
-
exports.min = min;
|
|
17
|
-
exports.range = range;
|
|
18
|
-
exports.reduce = reduce;
|
|
19
|
-
exports.reduce_ = reduce_;
|
|
20
|
-
exports.sorted = sorted;
|
|
21
|
-
exports.sum = sum;
|
|
22
|
-
exports.zip = zip;
|
|
23
|
-
exports.zip3 = zip3;
|
|
24
|
-
|
|
25
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
26
|
-
|
|
27
|
-
var _custom = require("./custom");
|
|
28
|
-
|
|
29
|
-
var _itertools = require("./itertools");
|
|
30
|
-
|
|
31
|
-
var _utils = require("./utils");
|
|
32
|
-
|
|
33
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
34
|
-
|
|
35
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
36
|
-
|
|
37
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
38
|
-
|
|
39
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
40
|
-
|
|
41
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
42
|
-
|
|
43
|
-
var _marked = /*#__PURE__*/_regeneratorRuntime2.mark(enumerate);
|
|
44
|
-
|
|
45
|
-
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(_e2) { throw _e2; }, 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(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
46
|
-
|
|
47
|
-
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); }
|
|
48
|
-
|
|
49
|
-
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; }
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Returns true when all of the items in iterable are truthy. An optional key
|
|
53
|
-
* function can be used to define what truthiness means for this specific
|
|
54
|
-
* collection.
|
|
55
|
-
*
|
|
56
|
-
* Examples:
|
|
57
|
-
*
|
|
58
|
-
* all([]) // => true
|
|
59
|
-
* all([0]) // => false
|
|
60
|
-
* all([0, 1, 2]) // => false
|
|
61
|
-
* all([1, 2, 3]) // => true
|
|
62
|
-
*
|
|
63
|
-
* Examples with using a key function:
|
|
64
|
-
*
|
|
65
|
-
* all([2, 4, 6], n => n % 2 === 0) // => true
|
|
66
|
-
* all([2, 4, 5], n => n % 2 === 0) // => false
|
|
67
|
-
*
|
|
68
|
-
*/
|
|
69
|
-
function all(iterable) {
|
|
70
|
-
var keyFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.identityPredicate;
|
|
71
|
-
|
|
72
|
-
var _iterator = _createForOfIteratorHelper(iterable),
|
|
73
|
-
_step;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
77
|
-
var item = _step.value;
|
|
78
|
-
|
|
79
|
-
if (!keyFn(item)) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
} catch (err) {
|
|
84
|
-
_iterator.e(err);
|
|
85
|
-
} finally {
|
|
86
|
-
_iterator.f();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns true when any of the items in iterable are truthy. An optional key
|
|
93
|
-
* function can be used to define what truthiness means for this specific
|
|
94
|
-
* collection.
|
|
95
|
-
*
|
|
96
|
-
* Examples:
|
|
97
|
-
*
|
|
98
|
-
* any([]) // => false
|
|
99
|
-
* any([0]) // => false
|
|
100
|
-
* any([0, 1, null, undefined]) // => true
|
|
101
|
-
*
|
|
102
|
-
* Examples with using a key function:
|
|
103
|
-
*
|
|
104
|
-
* any([1, 4, 5], n => n % 2 === 0) // => true
|
|
105
|
-
* any([{name: 'Bob'}, {name: 'Alice'}], person => person.name.startsWith('C')) // => false
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
function any(iterable) {
|
|
111
|
-
var keyFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.identityPredicate;
|
|
112
|
-
|
|
113
|
-
var _iterator2 = _createForOfIteratorHelper(iterable),
|
|
114
|
-
_step2;
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
118
|
-
var item = _step2.value;
|
|
119
|
-
|
|
120
|
-
if (keyFn(item)) {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
} catch (err) {
|
|
125
|
-
_iterator2.e(err);
|
|
126
|
-
} finally {
|
|
127
|
-
_iterator2.f();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Returns true when any of the items in the iterable are equal to the target object.
|
|
134
|
-
*
|
|
135
|
-
* Examples:
|
|
136
|
-
*
|
|
137
|
-
* contains([], 'whatever') // => false
|
|
138
|
-
* contains([3], 42) // => false
|
|
139
|
-
* contains([3], 3) // => true
|
|
140
|
-
* contains([0, 1, 2], 2) // => true
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
function contains(haystack, needle) {
|
|
146
|
-
return any(haystack, function (x) {
|
|
147
|
-
return x === needle;
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Returns an iterable of enumeration pairs. Iterable must be a sequence, an
|
|
152
|
-
* iterator, or some other object which supports iteration. The elements
|
|
153
|
-
* produced by returns a tuple containing a counter value (starting from 0 by
|
|
154
|
-
* default) and the values obtained from iterating over given iterable.
|
|
155
|
-
*
|
|
156
|
-
* Example:
|
|
157
|
-
*
|
|
158
|
-
* import { enumerate } from 'itertools';
|
|
159
|
-
*
|
|
160
|
-
* console.log([...enumerate(['hello', 'world'])]);
|
|
161
|
-
* // [0, 'hello'], [1, 'world']]
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
function enumerate(iterable) {
|
|
166
|
-
var start,
|
|
167
|
-
index,
|
|
168
|
-
_iterator3,
|
|
169
|
-
_step3,
|
|
170
|
-
value,
|
|
171
|
-
_args = arguments;
|
|
172
|
-
|
|
173
|
-
return _regenerator["default"].wrap(function enumerate$(_context) {
|
|
174
|
-
while (1) {
|
|
175
|
-
switch (_context.prev = _context.next) {
|
|
176
|
-
case 0:
|
|
177
|
-
start = _args.length > 1 && _args[1] !== undefined ? _args[1] : 0;
|
|
178
|
-
index = start;
|
|
179
|
-
_iterator3 = _createForOfIteratorHelper(iterable);
|
|
180
|
-
_context.prev = 3;
|
|
181
|
-
|
|
182
|
-
_iterator3.s();
|
|
183
|
-
|
|
184
|
-
case 5:
|
|
185
|
-
if ((_step3 = _iterator3.n()).done) {
|
|
186
|
-
_context.next = 11;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
value = _step3.value;
|
|
191
|
-
_context.next = 9;
|
|
192
|
-
return [index++, value];
|
|
193
|
-
|
|
194
|
-
case 9:
|
|
195
|
-
_context.next = 5;
|
|
196
|
-
break;
|
|
197
|
-
|
|
198
|
-
case 11:
|
|
199
|
-
_context.next = 16;
|
|
200
|
-
break;
|
|
201
|
-
|
|
202
|
-
case 13:
|
|
203
|
-
_context.prev = 13;
|
|
204
|
-
_context.t0 = _context["catch"](3);
|
|
205
|
-
|
|
206
|
-
_iterator3.e(_context.t0);
|
|
207
|
-
|
|
208
|
-
case 16:
|
|
209
|
-
_context.prev = 16;
|
|
210
|
-
|
|
211
|
-
_iterator3.f();
|
|
212
|
-
|
|
213
|
-
return _context.finish(16);
|
|
214
|
-
|
|
215
|
-
case 19:
|
|
216
|
-
case "end":
|
|
217
|
-
return _context.stop();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}, _marked, null, [[3, 13, 16, 19]]);
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Non-lazy version of ifilter().
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
function filter(iterable, predicate) {
|
|
228
|
-
return Array.from((0, _itertools.ifilter)(iterable, predicate));
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Returns an iterator object for the given iterable. This can be used to
|
|
232
|
-
* manually get an iterator for any iterable datastructure. The purpose and
|
|
233
|
-
* main use case of this function is to get a single iterator (a thing with
|
|
234
|
-
* state, think of it as a "cursor") which can only be consumed once.
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
function iter(iterable) {
|
|
239
|
-
// TODO: Not sure why Flow choked on this expression below, but at least we lock down the
|
|
240
|
-
// type transformation in the function signature this way.
|
|
241
|
-
// $FlowFixMe[incompatible-use]
|
|
242
|
-
return iterable[Symbol.iterator]();
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Non-lazy version of imap().
|
|
246
|
-
*/
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
function map(iterable, mapper) {
|
|
250
|
-
return Array.from((0, _itertools.imap)(iterable, mapper));
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Return the largest item in an iterable. Only works for numbers, as ordering
|
|
254
|
-
* is pretty poorly defined on any other data type in JS. The optional `keyFn`
|
|
255
|
-
* argument specifies a one-argument ordering function like that used for
|
|
256
|
-
* sorted().
|
|
257
|
-
*
|
|
258
|
-
* If the iterable is empty, `undefined` is returned.
|
|
259
|
-
*
|
|
260
|
-
* If multiple items are maximal, the function returns either one of them, but
|
|
261
|
-
* which one is not defined.
|
|
262
|
-
*/
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
function max(iterable) {
|
|
266
|
-
var keyFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.numberIdentity;
|
|
267
|
-
return reduce_(iterable, function (x, y) {
|
|
268
|
-
return keyFn(x) > keyFn(y) ? x : y;
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Return the smallest item in an iterable. Only works for numbers, as
|
|
273
|
-
* ordering is pretty poorly defined on any other data type in JS. The
|
|
274
|
-
* optional `keyFn` argument specifies a one-argument ordering function like
|
|
275
|
-
* that used for sorted().
|
|
276
|
-
*
|
|
277
|
-
* If the iterable is empty, `undefined` is returned.
|
|
278
|
-
*
|
|
279
|
-
* If multiple items are minimal, the function returns either one of them, but
|
|
280
|
-
* which one is not defined.
|
|
281
|
-
*/
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
function min(iterable) {
|
|
285
|
-
var keyFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.numberIdentity;
|
|
286
|
-
return reduce_(iterable, function (x, y) {
|
|
287
|
-
return keyFn(x) < keyFn(y) ? x : y;
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Internal helper for the range function
|
|
292
|
-
*/
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
function _range(start, stop, step) {
|
|
296
|
-
var counter = (0, _itertools.count)(start, step);
|
|
297
|
-
var pred = step >= 0 ? function (n) {
|
|
298
|
-
return n < stop;
|
|
299
|
-
} : function (n) {
|
|
300
|
-
return n > stop;
|
|
301
|
-
};
|
|
302
|
-
return (0, _itertools.takewhile)(counter, pred);
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Returns an iterator producing all the numbers in the given range one by one,
|
|
306
|
-
* starting from `start` (default 0), as long as `i < stop`, in increments of
|
|
307
|
-
* `step` (default 1).
|
|
308
|
-
*
|
|
309
|
-
* `range(a)` is a convenient shorthand for `range(0, a)`.
|
|
310
|
-
*
|
|
311
|
-
* Various valid invocations:
|
|
312
|
-
*
|
|
313
|
-
* range(5) // [0, 1, 2, 3, 4]
|
|
314
|
-
* range(2, 5) // [2, 3, 4]
|
|
315
|
-
* range(0, 5, 2) // [0, 2, 4]
|
|
316
|
-
* range(5, 0, -1) // [5, 4, 3, 2, 1]
|
|
317
|
-
* range(-3) // []
|
|
318
|
-
*
|
|
319
|
-
* For a positive `step`, the iterator will keep producing values `n` as long
|
|
320
|
-
* as the stop condition `n < stop` is satisfied.
|
|
321
|
-
*
|
|
322
|
-
* For a negative `step`, the iterator will keep producing values `n` as long
|
|
323
|
-
* as the stop condition `n > stop` is satisfied.
|
|
324
|
-
*
|
|
325
|
-
* The produced range will be empty if the first value to produce already does
|
|
326
|
-
* not meet the value constraint.
|
|
327
|
-
*/
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
function range(a) {
|
|
331
|
-
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
332
|
-
rest[_key - 1] = arguments[_key];
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
var args = [a].concat(rest); // "a" was only used by Flow to make at least one value mandatory
|
|
336
|
-
|
|
337
|
-
switch (args.length) {
|
|
338
|
-
case 1:
|
|
339
|
-
return _range(0, args[0], 1);
|
|
340
|
-
|
|
341
|
-
case 2:
|
|
342
|
-
return _range(args[0], args[1], 1);
|
|
343
|
-
|
|
344
|
-
case 3:
|
|
345
|
-
return _range(args[0], args[1], args[2]);
|
|
346
|
-
|
|
347
|
-
/* istanbul ignore next */
|
|
348
|
-
|
|
349
|
-
default:
|
|
350
|
-
throw new Error('invalid number of arguments');
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Apply function of two arguments cumulatively to the items of sequence, from
|
|
355
|
-
* left to right, so as to reduce the sequence to a single value. For example:
|
|
356
|
-
*
|
|
357
|
-
* reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)
|
|
358
|
-
*
|
|
359
|
-
* calculates
|
|
360
|
-
*
|
|
361
|
-
* (((((0+1)+2)+3)+4)+5)
|
|
362
|
-
*
|
|
363
|
-
* The left argument, `x`, is the accumulated value and the right argument,
|
|
364
|
-
* `y`, is the update value from the sequence.
|
|
365
|
-
*
|
|
366
|
-
* **Difference between `reduce()` and `reduce\_()`**: `reduce()` requires an
|
|
367
|
-
* explicit initializer, whereas `reduce_()` will automatically use the first
|
|
368
|
-
* item in the given iterable as the initializer. When using `reduce()`, the
|
|
369
|
-
* initializer value is placed before the items of the sequence in the
|
|
370
|
-
* calculation, and serves as a default when the sequence is empty. When using
|
|
371
|
-
* `reduce_()`, and the given iterable is empty, then no default value can be
|
|
372
|
-
* derived and `undefined` will be returned.
|
|
373
|
-
*/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
function reduce(iterable, reducer, start) {
|
|
377
|
-
var it = iter(iterable);
|
|
378
|
-
var output = start;
|
|
379
|
-
|
|
380
|
-
var _iterator4 = _createForOfIteratorHelper(enumerate(it)),
|
|
381
|
-
_step4;
|
|
382
|
-
|
|
383
|
-
try {
|
|
384
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
385
|
-
var _step4$value = _slicedToArray(_step4.value, 2),
|
|
386
|
-
index = _step4$value[0],
|
|
387
|
-
item = _step4$value[1];
|
|
388
|
-
|
|
389
|
-
output = reducer(output, item, index);
|
|
390
|
-
}
|
|
391
|
-
} catch (err) {
|
|
392
|
-
_iterator4.e(err);
|
|
393
|
-
} finally {
|
|
394
|
-
_iterator4.f();
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
return output;
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* See reduce().
|
|
401
|
-
*/
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
function reduce_(iterable, reducer) {
|
|
405
|
-
var it = iter(iterable);
|
|
406
|
-
var start = (0, _custom.first)(it);
|
|
407
|
-
|
|
408
|
-
if (start === undefined) {
|
|
409
|
-
return undefined;
|
|
410
|
-
} else {
|
|
411
|
-
return reduce(it, reducer, start);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Return a new sorted list from the items in iterable.
|
|
416
|
-
*
|
|
417
|
-
* Has two optional arguments:
|
|
418
|
-
*
|
|
419
|
-
* * `keyFn` specifies a function of one argument providing a primitive
|
|
420
|
-
* identity for each element in the iterable. that will be used to compare.
|
|
421
|
-
* The default value is to use a default identity function that is only
|
|
422
|
-
* defined for primitive types.
|
|
423
|
-
*
|
|
424
|
-
* * `reverse` is a boolean value. If `true`, then the list elements are
|
|
425
|
-
* sorted as if each comparison were reversed.
|
|
426
|
-
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
function sorted(iterable) {
|
|
430
|
-
var keyFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.primitiveIdentity;
|
|
431
|
-
var reverse = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
432
|
-
var result = Array.from(iterable);
|
|
433
|
-
result.sort((0, _utils.keyToCmp)(keyFn)); // sort in-place
|
|
434
|
-
|
|
435
|
-
if (reverse) {
|
|
436
|
-
result.reverse(); // reverse in-place
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
return result;
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Sums the items of an iterable from left to right and returns the total. The
|
|
443
|
-
* sum will defaults to 0 if the iterable is empty.
|
|
444
|
-
*/
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
function sum(iterable) {
|
|
448
|
-
return reduce(iterable, function (x, y) {
|
|
449
|
-
return x + y;
|
|
450
|
-
}, 0);
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* See izip.
|
|
454
|
-
*/
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
function zip(xs, ys) {
|
|
458
|
-
return Array.from((0, _itertools.izip)(xs, ys));
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* See izip3.
|
|
462
|
-
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
function zip3(xs, ys, zs) {
|
|
466
|
-
return Array.from((0, _itertools.izip3)(xs, ys, zs));
|
|
467
|
-
}
|