@sapphire/iterator-utilities 1.0.3-next.7b747c3e → 1.0.3-next.a3da0ab0
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/dist/cjs/lib/contains.cjs +2 -1
- package/dist/cjs/lib/contains.cjs.map +1 -1
- package/dist/cjs/lib/drop.cjs +6 -3
- package/dist/cjs/lib/drop.cjs.map +1 -1
- package/dist/cjs/lib/dropLast.cjs +2 -1
- package/dist/cjs/lib/dropLast.cjs.map +1 -1
- package/dist/cjs/lib/every.cjs +2 -1
- package/dist/cjs/lib/every.cjs.map +1 -1
- package/dist/cjs/lib/filter.cjs +2 -1
- package/dist/cjs/lib/filter.cjs.map +1 -1
- package/dist/cjs/lib/max.cjs +2 -1
- package/dist/cjs/lib/max.cjs.map +1 -1
- package/dist/cjs/lib/min.cjs +2 -1
- package/dist/cjs/lib/min.cjs.map +1 -1
- package/dist/cjs/lib/reduce.cjs +2 -1
- package/dist/cjs/lib/reduce.cjs.map +1 -1
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs +6 -3
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs.map +1 -1
- package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs +6 -3
- package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs.map +1 -1
- package/dist/cjs/lib/slice.cjs +2 -1
- package/dist/cjs/lib/slice.cjs.map +1 -1
- package/dist/cjs/lib/take.cjs +2 -1
- package/dist/cjs/lib/take.cjs.map +1 -1
- package/dist/cjs/lib/takeLast.cjs +4 -2
- package/dist/cjs/lib/takeLast.cjs.map +1 -1
- package/dist/cjs/lib/tee.cjs +2 -1
- package/dist/cjs/lib/tee.cjs.map +1 -1
- package/dist/cjs/lib/unzip.cjs +2 -1
- package/dist/cjs/lib/unzip.cjs.map +1 -1
- package/dist/cjs/lib/zip.cjs +2 -1
- package/dist/cjs/lib/zip.cjs.map +1 -1
- package/dist/esm/{chunk-PAWJFY3S.mjs → chunk-G5GHKT7C.mjs} +1 -1
- package/dist/esm/lib/append.mjs +1 -1
- package/dist/esm/lib/at.mjs +1 -1
- package/dist/esm/lib/average.mjs +1 -1
- package/dist/esm/lib/chain.mjs +1 -1
- package/dist/esm/lib/chunk.mjs +1 -1
- package/dist/esm/lib/compact.mjs +1 -1
- package/dist/esm/lib/compress.mjs +1 -1
- package/dist/esm/lib/contains.mjs +3 -2
- package/dist/esm/lib/contains.mjs.map +1 -1
- package/dist/esm/lib/count.mjs +1 -1
- package/dist/esm/lib/cycle.mjs +1 -1
- package/dist/esm/lib/difference.mjs +1 -1
- package/dist/esm/lib/drop.mjs +7 -4
- package/dist/esm/lib/drop.mjs.map +1 -1
- package/dist/esm/lib/dropLast.mjs +3 -2
- package/dist/esm/lib/dropLast.mjs.map +1 -1
- package/dist/esm/lib/dropWhile.mjs +1 -1
- package/dist/esm/lib/empty.mjs +1 -1
- package/dist/esm/lib/enumerate.mjs +1 -1
- package/dist/esm/lib/every.mjs +3 -2
- package/dist/esm/lib/every.mjs.map +1 -1
- package/dist/esm/lib/filter.mjs +3 -2
- package/dist/esm/lib/filter.mjs.map +1 -1
- package/dist/esm/lib/find.mjs +1 -1
- package/dist/esm/lib/findIndex.mjs +1 -1
- package/dist/esm/lib/first.mjs +1 -1
- package/dist/esm/lib/flat.mjs +1 -1
- package/dist/esm/lib/flatMap.mjs +1 -1
- package/dist/esm/lib/forEach.mjs +1 -1
- package/dist/esm/lib/from.mjs +1 -1
- package/dist/esm/lib/indexOf.mjs +1 -1
- package/dist/esm/lib/intersect.mjs +1 -1
- package/dist/esm/lib/isEmpty.mjs +1 -1
- package/dist/esm/lib/last.mjs +1 -1
- package/dist/esm/lib/map.mjs +1 -1
- package/dist/esm/lib/max.mjs +3 -2
- package/dist/esm/lib/max.mjs.map +1 -1
- package/dist/esm/lib/min.mjs +3 -2
- package/dist/esm/lib/min.mjs.map +1 -1
- package/dist/esm/lib/partition.mjs +1 -1
- package/dist/esm/lib/peekable.mjs +1 -1
- package/dist/esm/lib/prepend.mjs +1 -1
- package/dist/esm/lib/product.mjs +1 -1
- package/dist/esm/lib/range.mjs +1 -1
- package/dist/esm/lib/reduce.mjs +3 -2
- package/dist/esm/lib/reduce.mjs.map +1 -1
- package/dist/esm/lib/repeat.mjs +1 -1
- package/dist/esm/lib/reverse.mjs +1 -1
- package/dist/esm/lib/shared/_assertFunction.mjs +1 -1
- package/dist/esm/lib/shared/_assertNotNegative.mjs +1 -1
- package/dist/esm/lib/shared/_assertPositive.mjs +1 -1
- package/dist/esm/lib/shared/_makeIterableIterator.mjs +1 -1
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs +7 -4
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs.map +1 -1
- package/dist/esm/lib/shared/_toIntegerOrThrow.mjs +7 -4
- package/dist/esm/lib/shared/_toIntegerOrThrow.mjs.map +1 -1
- package/dist/esm/lib/shared/_toNumberOrThrow.mjs +1 -1
- package/dist/esm/lib/slice.mjs +3 -2
- package/dist/esm/lib/slice.mjs.map +1 -1
- package/dist/esm/lib/some.mjs +1 -1
- package/dist/esm/lib/sorted.mjs +1 -1
- package/dist/esm/lib/starMap.mjs +1 -1
- package/dist/esm/lib/sum.mjs +1 -1
- package/dist/esm/lib/take.mjs +3 -2
- package/dist/esm/lib/take.mjs.map +1 -1
- package/dist/esm/lib/takeLast.mjs +5 -3
- package/dist/esm/lib/takeLast.mjs.map +1 -1
- package/dist/esm/lib/tee.mjs +3 -2
- package/dist/esm/lib/tee.mjs.map +1 -1
- package/dist/esm/lib/toArray.mjs +1 -1
- package/dist/esm/lib/toIterableIterator.mjs +1 -1
- package/dist/esm/lib/union.mjs +1 -1
- package/dist/esm/lib/unique.mjs +1 -1
- package/dist/esm/lib/unzip.mjs +3 -2
- package/dist/esm/lib/unzip.mjs.map +1 -1
- package/dist/esm/lib/zip.mjs +3 -2
- package/dist/esm/lib/zip.mjs.map +1 -1
- package/dist/iife/index.global.js +46 -23
- package/dist/iife/index.global.js.map +1 -1
- package/package.json +4 -4
- /package/dist/esm/{chunk-PAWJFY3S.mjs.map → chunk-G5GHKT7C.mjs.map} +0 -0
package/dist/esm/lib/unzip.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
2
|
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
3
3
|
|
|
4
4
|
function unzip(iterable) {
|
|
@@ -12,7 +12,8 @@ function unzip(iterable) {
|
|
|
12
12
|
}
|
|
13
13
|
const size = firstResult.value.length;
|
|
14
14
|
const results = [];
|
|
15
|
-
for (let i = 0; i < size; i++)
|
|
15
|
+
for (let i = 0; i < size; i++)
|
|
16
|
+
results.push([firstResult.value[i]]);
|
|
16
17
|
for (const entries of resolvedIterable) {
|
|
17
18
|
if (!Array.isArray(entries)) {
|
|
18
19
|
throw new Error("Cannot unzip an iterable that does not yield an array");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/unzip.ts"],"names":[],"mappings":";;;;;AACA,SAAS,0BAA0B;AA0B5B,SAAS,MAAgD,UAAuE;AACtI,QAAM,mBAAmB,mBAAmB,QAAQ;AACpD,QAAM,cAAc,iBAAiB,KAAK;AAC1C,MAAI,YAAY,MAAM;AACrB,UAAM,IAAI,MAAM,gCAAgC;AAAA,EACjD;AAEA,MAAI,CAAC,MAAM,QAAQ,YAAY,KAAK,GAAG;AACtC,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACxE;AAEA,QAAM,OAAO,YAAY,MAAM;AAC/B,QAAM,UAAU,CAAC;AACjB,WAAS,IAAI,GAAG,IAAI,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/unzip.ts"],"names":[],"mappings":";;;;;AACA,SAAS,0BAA0B;AA0B5B,SAAS,MAAgD,UAAuE;AACtI,QAAM,mBAAmB,mBAAmB,QAAQ;AACpD,QAAM,cAAc,iBAAiB,KAAK;AAC1C,MAAI,YAAY,MAAM;AACrB,UAAM,IAAI,MAAM,gCAAgC;AAAA,EACjD;AAEA,MAAI,CAAC,MAAM,QAAQ,YAAY,KAAK,GAAG;AACtC,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACxE;AAEA,QAAM,OAAO,YAAY,MAAM;AAC/B,QAAM,UAAU,CAAC;AACjB,WAAS,IAAI,GAAG,IAAI,MAAM;AAAK,YAAQ,KAAK,CAAC,YAAY,MAAM,CAAC,CAAC,CAAC;AAClE,aAAW,WAAW,kBAAkB;AACvC,QAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;AAC5B,YAAM,IAAI,MAAM,uDAAuD;AAAA,IACxE;AAEA,QAAI,QAAQ,WAAW,MAAM;AAC5B,YAAM,IAAI,MAAM,gEAAgE;AAAA,IACjF;AAEA,aAAS,IAAI,GAAG,IAAI,MAAM,KAAK;AAC9B,cAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;AAAA,IAC3B;AAAA,EACD;AAEA,SAAO;AACR;AA7BgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an array for each element of the input iterable, transposing the input iterable. The opposite of {@linkcode zip}.\n *\n * @param iterable An iterable to unzip.\n * @returns An array of iterables that yield the values of the original iterable.\n *\n * @example\n * ```typescript\n * import { unzip } from '@sapphire/iterator-utilities';\n *\n * const iterable = [[1, 'a'], [2, 'b'], [3, 'c']];\n * const [numbers, letters] = unzip(iterable);\n *\n * console.log(numbers);\n * // Output: [1, 2, 3]\n *\n * console.log(letters);\n * // Output: ['a', 'b', 'c']\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterable.\n */\nexport function unzip<const ElementType extends readonly any[]>(iterable: IterableResolvable<ElementType>): UnzipIterable<ElementType> {\n\tconst resolvedIterable = toIterableIterator(iterable);\n\tconst firstResult = resolvedIterable.next();\n\tif (firstResult.done) {\n\t\tthrow new Error('Cannot unzip an empty iterable');\n\t}\n\n\tif (!Array.isArray(firstResult.value)) {\n\t\tthrow new Error('Cannot unzip an iterable that does not yield an array');\n\t}\n\n\tconst size = firstResult.value.length;\n\tconst results = [] as ElementType[][];\n\tfor (let i = 0; i < size; i++) results.push([firstResult.value[i]]);\n\tfor (const entries of resolvedIterable) {\n\t\tif (!Array.isArray(entries)) {\n\t\t\tthrow new Error('Cannot unzip an iterable that does not yield an array');\n\t\t}\n\n\t\tif (entries.length !== size) {\n\t\t\tthrow new Error('Cannot unzip an iterable that yields arrays of different sizes');\n\t\t}\n\n\t\tfor (let i = 0; i < size; i++) {\n\t\t\tresults[i].push(entries[i]);\n\t\t}\n\t}\n\n\treturn results as UnzipIterable<ElementType>;\n}\n\nexport type UnzipIterable<ElementType extends readonly any[]> = {\n\t-readonly [P in keyof ElementType]: ElementType[P][];\n};\n"]}
|
package/dist/esm/lib/zip.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
2
|
import { from } from './from.mjs';
|
|
3
3
|
|
|
4
4
|
function* zip(...iterables) {
|
|
@@ -7,7 +7,8 @@ function* zip(...iterables) {
|
|
|
7
7
|
const results = [];
|
|
8
8
|
for (const resolvedIterable of resolvedIterables) {
|
|
9
9
|
const result = resolvedIterable.next();
|
|
10
|
-
if (result.done)
|
|
10
|
+
if (result.done)
|
|
11
|
+
return;
|
|
11
12
|
results.push(result.value);
|
|
12
13
|
}
|
|
13
14
|
yield results;
|
package/dist/esm/lib/zip.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/zip.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAAqC;AAwBvC,UAAU,OAAmE,WAA+C;AAClI,QAAM,oBAAoB,UAAU,IAAI,CAAC,aAAa,KAAK,QAAQ,CAAC;AACpE,SAAO,MAAM;AACZ,UAAM,UAAU,CAAC;AACjB,eAAW,oBAAoB,mBAAmB;AACjD,YAAM,SAAS,iBAAiB,KAAK;AACrC,UAAI,OAAO
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/zip.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAAqC;AAwBvC,UAAU,OAAmE,WAA+C;AAClI,QAAM,oBAAoB,UAAU,IAAI,CAAC,aAAa,KAAK,QAAQ,CAAC;AACpE,SAAO,MAAM;AACZ,UAAM,UAAU,CAAC;AACjB,eAAW,oBAAoB,mBAAmB;AACjD,YAAM,SAAS,iBAAiB,KAAK;AACrC,UAAI,OAAO;AAAM;AAEjB,cAAQ,KAAK,OAAO,KAAK;AAAA,IAC1B;AAEA,UAAM;AAAA,EACP;AACD;AAbiB","sourcesContent":["import { from, type IterableResolvable } from './from';\n\n/**\n * Creates an iterable with the elements of the input iterables zipped together. The opposite of {@linkcode unzip}.\n *\n * @param iterables The iterables to zip together.\n * @returns A new iterable that yields the next value of each iterable in the list.\n *\n * @example\n * ```typescript\n * import { zip } from '@sapphire/iterator-utilities';\n *\n * const iterable1 = [1, 2, 3];\n * const iterable2 = ['a', 'b', 'c'];\n * const iterable3 = [true, false, true];\n *\n * console.log(zip(iterable1, iterable2, iterable3));\n * // Output: [\n * // \t[1, 'a', true],\n * // \t[2, 'b', false],\n * // \t[3, 'c', true]\n * // ]\n * ```\n */\nexport function* zip<const Iterables extends readonly IterableResolvable<any>[]>(...iterables: Iterables): ZipIterators<Iterables> {\n\tconst resolvedIterables = iterables.map((iterable) => from(iterable));\n\twhile (true) {\n\t\tconst results = [] as any[];\n\t\tfor (const resolvedIterable of resolvedIterables) {\n\t\t\tconst result = resolvedIterable.next();\n\t\t\tif (result.done) return;\n\n\t\t\tresults.push(result.value);\n\t\t}\n\n\t\tyield results as any;\n\t}\n}\n\nexport type ZipIterators<Iterators extends readonly IterableResolvable<any>[]> = IterableIterator<{\n\t-readonly [P in keyof Iterators]: Iterators[P] extends IterableResolvable<infer T> ? T : never;\n}>;\n"]}
|
|
@@ -100,9 +100,12 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
100
100
|
// src/lib/shared/_toIntegerOrInfinityOrThrow.ts
|
|
101
101
|
function toIntegerOrInfinityOrThrow(value) {
|
|
102
102
|
const number = toNumberOrThrow(value);
|
|
103
|
-
if (Number.isNaN(number) || number === 0)
|
|
104
|
-
|
|
105
|
-
if (number === Number.
|
|
103
|
+
if (Number.isNaN(number) || number === 0)
|
|
104
|
+
return 0;
|
|
105
|
+
if (number === Number.POSITIVE_INFINITY)
|
|
106
|
+
return Number.POSITIVE_INFINITY;
|
|
107
|
+
if (number === Number.NEGATIVE_INFINITY)
|
|
108
|
+
return Number.NEGATIVE_INFINITY;
|
|
106
109
|
return Math.trunc(number);
|
|
107
110
|
}
|
|
108
111
|
__name(toIntegerOrInfinityOrThrow, "toIntegerOrInfinityOrThrow");
|
|
@@ -111,10 +114,13 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
111
114
|
function drop(iterable, count2) {
|
|
112
115
|
count2 = assertNotNegative(toIntegerOrInfinityOrThrow(count2), count2);
|
|
113
116
|
const resolvedIterable = toIterableIterator(iterable);
|
|
114
|
-
if (count2 === 0)
|
|
115
|
-
|
|
117
|
+
if (count2 === 0)
|
|
118
|
+
return resolvedIterable;
|
|
119
|
+
if (count2 === Number.POSITIVE_INFINITY)
|
|
120
|
+
return empty();
|
|
116
121
|
for (let i = 0; i < count2; i++) {
|
|
117
|
-
if (resolvedIterable.next().done)
|
|
122
|
+
if (resolvedIterable.next().done)
|
|
123
|
+
break;
|
|
118
124
|
}
|
|
119
125
|
return resolvedIterable;
|
|
120
126
|
}
|
|
@@ -176,9 +182,12 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
176
182
|
// src/lib/shared/_toIntegerOrThrow.ts
|
|
177
183
|
function toIntegerOrThrow(value) {
|
|
178
184
|
const number = toNumberOrThrow(value);
|
|
179
|
-
if (Number.isNaN(number) || number === 0)
|
|
180
|
-
|
|
181
|
-
if (number === Number.
|
|
185
|
+
if (Number.isNaN(number) || number === 0)
|
|
186
|
+
return 0;
|
|
187
|
+
if (number === Number.POSITIVE_INFINITY)
|
|
188
|
+
throw new RangeError("+Infinity cannot be represented as an integer");
|
|
189
|
+
if (number === Number.NEGATIVE_INFINITY)
|
|
190
|
+
throw new RangeError("-Infinity cannot be represented as an integer");
|
|
182
191
|
return Math.trunc(number);
|
|
183
192
|
}
|
|
184
193
|
__name(toIntegerOrThrow, "toIntegerOrThrow");
|
|
@@ -205,7 +214,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
205
214
|
callbackFn = assertFunction(callbackFn);
|
|
206
215
|
let index = 0;
|
|
207
216
|
for (const value of toIterableIterator(iterable)) {
|
|
208
|
-
if (callbackFn(value, index++))
|
|
217
|
+
if (callbackFn(value, index++))
|
|
218
|
+
yield value;
|
|
209
219
|
}
|
|
210
220
|
}
|
|
211
221
|
__name(filter, "filter");
|
|
@@ -234,7 +244,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
234
244
|
// src/lib/contains.ts
|
|
235
245
|
function contains(iterable, value) {
|
|
236
246
|
for (const element of toIterableIterator(iterable)) {
|
|
237
|
-
if (element === value)
|
|
247
|
+
if (element === value)
|
|
248
|
+
return true;
|
|
238
249
|
}
|
|
239
250
|
return false;
|
|
240
251
|
}
|
|
@@ -276,7 +287,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
276
287
|
// src/lib/take.ts
|
|
277
288
|
function take(iterable, count2) {
|
|
278
289
|
count2 = assertNotNegative(toIntegerOrInfinityOrThrow(count2), count2);
|
|
279
|
-
if (count2 === 0)
|
|
290
|
+
if (count2 === 0)
|
|
291
|
+
return empty();
|
|
280
292
|
let i = 0;
|
|
281
293
|
const resolvedIterable = from(iterable);
|
|
282
294
|
return makeIterableIterator(
|
|
@@ -295,7 +307,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
295
307
|
function dropLast(iterable, count2) {
|
|
296
308
|
count2 = assertNotNegative(toIntegerOrInfinityOrThrow(count2), count2);
|
|
297
309
|
const array = toArray(iterable);
|
|
298
|
-
if (array.length <= count2)
|
|
310
|
+
if (array.length <= count2)
|
|
311
|
+
return empty();
|
|
299
312
|
return take(array.values(), array.length - count2);
|
|
300
313
|
}
|
|
301
314
|
__name(dropLast, "dropLast");
|
|
@@ -326,7 +339,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
326
339
|
callbackFn = assertFunction(callbackFn);
|
|
327
340
|
let index = 0;
|
|
328
341
|
for (const value of toIterableIterator(iterable)) {
|
|
329
|
-
if (!callbackFn(value, index++))
|
|
342
|
+
if (!callbackFn(value, index++))
|
|
343
|
+
return false;
|
|
330
344
|
}
|
|
331
345
|
return true;
|
|
332
346
|
}
|
|
@@ -420,7 +434,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
420
434
|
function max(iterable) {
|
|
421
435
|
let max2 = null;
|
|
422
436
|
for (const value of map(iterable, toNumberOrThrow)) {
|
|
423
|
-
if (max2 === null || value > max2)
|
|
437
|
+
if (max2 === null || value > max2)
|
|
438
|
+
max2 = value;
|
|
424
439
|
}
|
|
425
440
|
return max2;
|
|
426
441
|
}
|
|
@@ -430,7 +445,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
430
445
|
function min(iterable) {
|
|
431
446
|
let min2 = null;
|
|
432
447
|
for (const value of map(iterable, toNumberOrThrow)) {
|
|
433
|
-
if (min2 === null || value < min2)
|
|
448
|
+
if (min2 === null || value < min2)
|
|
449
|
+
min2 = value;
|
|
434
450
|
}
|
|
435
451
|
return min2;
|
|
436
452
|
}
|
|
@@ -532,7 +548,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
532
548
|
const resolvedIterable = toIterableIterator(iterable);
|
|
533
549
|
if (arguments.length < 3) {
|
|
534
550
|
const firstValue = resolvedIterable.next();
|
|
535
|
-
if (firstValue.done)
|
|
551
|
+
if (firstValue.done)
|
|
552
|
+
throw new TypeError("Reduce of empty iterator with no initial value");
|
|
536
553
|
index = 1;
|
|
537
554
|
accumulator = firstValue.value;
|
|
538
555
|
} else {
|
|
@@ -571,8 +588,10 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
571
588
|
// src/lib/takeLast.ts
|
|
572
589
|
function takeLast(iterable, count2) {
|
|
573
590
|
count2 = assertNotNegative(toIntegerOrInfinityOrThrow(count2), count2);
|
|
574
|
-
if (count2 === 0)
|
|
575
|
-
|
|
591
|
+
if (count2 === 0)
|
|
592
|
+
return empty();
|
|
593
|
+
if (count2 === Number.POSITIVE_INFINITY)
|
|
594
|
+
return toIterableIterator(iterable);
|
|
576
595
|
const array = toArray(iterable);
|
|
577
596
|
let i = Math.max(0, array.length - count2);
|
|
578
597
|
return makeIterableIterator(() => {
|
|
@@ -609,7 +628,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
609
628
|
}
|
|
610
629
|
return take(takeLast(iterable, -start), end - start);
|
|
611
630
|
}
|
|
612
|
-
if (start >= end)
|
|
631
|
+
if (start >= end)
|
|
632
|
+
return empty();
|
|
613
633
|
return end === Number.POSITIVE_INFINITY ? drop(iterable, start) : take(drop(iterable, start), end - start);
|
|
614
634
|
}
|
|
615
635
|
__name(slice, "slice");
|
|
@@ -655,7 +675,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
655
675
|
// src/lib/tee.ts
|
|
656
676
|
function tee(iterable, count2) {
|
|
657
677
|
count2 = assertNotNegative(toIntegerOrThrow(count2), count2);
|
|
658
|
-
if (count2 === 0)
|
|
678
|
+
if (count2 === 0)
|
|
679
|
+
return [];
|
|
659
680
|
const entries = [];
|
|
660
681
|
const indexes = toArray(repeat(0, count2));
|
|
661
682
|
const resolvedIterable = from(iterable);
|
|
@@ -709,7 +730,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
709
730
|
}
|
|
710
731
|
const size = firstResult.value.length;
|
|
711
732
|
const results = [];
|
|
712
|
-
for (let i = 0; i < size; i++)
|
|
733
|
+
for (let i = 0; i < size; i++)
|
|
734
|
+
results.push([firstResult.value[i]]);
|
|
713
735
|
for (const entries of resolvedIterable) {
|
|
714
736
|
if (!Array.isArray(entries)) {
|
|
715
737
|
throw new Error("Cannot unzip an iterable that does not yield an array");
|
|
@@ -732,7 +754,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
732
754
|
const results = [];
|
|
733
755
|
for (const resolvedIterable of resolvedIterables) {
|
|
734
756
|
const result = resolvedIterable.next();
|
|
735
|
-
if (result.done)
|
|
757
|
+
if (result.done)
|
|
758
|
+
return;
|
|
736
759
|
results.push(result.value);
|
|
737
760
|
}
|
|
738
761
|
yield results;
|