@sapphire/iterator-utilities 1.0.3-next.cd7e6b59 → 1.0.3-next.db356eb0
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/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/append.cjs +1 -1
- package/dist/cjs/lib/append.cjs.map +1 -1
- package/dist/cjs/lib/at.cjs +1 -1
- package/dist/cjs/lib/at.cjs.map +1 -1
- package/dist/cjs/lib/average.cjs +1 -1
- package/dist/cjs/lib/average.cjs.map +1 -1
- package/dist/cjs/lib/chain.cjs +1 -1
- package/dist/cjs/lib/chain.cjs.map +1 -1
- package/dist/cjs/lib/chunk.cjs +1 -1
- package/dist/cjs/lib/chunk.cjs.map +1 -1
- package/dist/cjs/lib/compact.cjs +1 -1
- package/dist/cjs/lib/compact.cjs.map +1 -1
- package/dist/cjs/lib/compress.cjs +1 -1
- package/dist/cjs/lib/compress.cjs.map +1 -1
- package/dist/cjs/lib/contains.cjs +2 -3
- package/dist/cjs/lib/contains.cjs.map +1 -1
- package/dist/cjs/lib/count.cjs +1 -1
- package/dist/cjs/lib/count.cjs.map +1 -1
- package/dist/cjs/lib/cycle.cjs +1 -1
- package/dist/cjs/lib/cycle.cjs.map +1 -1
- package/dist/cjs/lib/difference.cjs +1 -1
- package/dist/cjs/lib/difference.cjs.map +1 -1
- package/dist/cjs/lib/drop.cjs +4 -7
- package/dist/cjs/lib/drop.cjs.map +1 -1
- package/dist/cjs/lib/dropLast.cjs +2 -3
- package/dist/cjs/lib/dropLast.cjs.map +1 -1
- package/dist/cjs/lib/dropWhile.cjs +1 -1
- package/dist/cjs/lib/dropWhile.cjs.map +1 -1
- package/dist/cjs/lib/empty.cjs +1 -1
- package/dist/cjs/lib/empty.cjs.map +1 -1
- package/dist/cjs/lib/enumerate.cjs +1 -1
- package/dist/cjs/lib/enumerate.cjs.map +1 -1
- package/dist/cjs/lib/every.cjs +2 -3
- package/dist/cjs/lib/every.cjs.map +1 -1
- package/dist/cjs/lib/filter.cjs +2 -3
- package/dist/cjs/lib/filter.cjs.map +1 -1
- package/dist/cjs/lib/find.cjs +1 -1
- package/dist/cjs/lib/find.cjs.map +1 -1
- package/dist/cjs/lib/findIndex.cjs +1 -1
- package/dist/cjs/lib/findIndex.cjs.map +1 -1
- package/dist/cjs/lib/first.cjs +1 -1
- package/dist/cjs/lib/first.cjs.map +1 -1
- package/dist/cjs/lib/flat.cjs +1 -1
- package/dist/cjs/lib/flat.cjs.map +1 -1
- package/dist/cjs/lib/flatMap.cjs +1 -1
- package/dist/cjs/lib/flatMap.cjs.map +1 -1
- package/dist/cjs/lib/forEach.cjs +1 -1
- package/dist/cjs/lib/forEach.cjs.map +1 -1
- package/dist/cjs/lib/from.cjs +1 -1
- package/dist/cjs/lib/from.cjs.map +1 -1
- package/dist/cjs/lib/indexOf.cjs +1 -1
- package/dist/cjs/lib/indexOf.cjs.map +1 -1
- package/dist/cjs/lib/intersect.cjs +1 -1
- package/dist/cjs/lib/intersect.cjs.map +1 -1
- package/dist/cjs/lib/isEmpty.cjs +1 -1
- package/dist/cjs/lib/isEmpty.cjs.map +1 -1
- package/dist/cjs/lib/last.cjs +1 -1
- package/dist/cjs/lib/last.cjs.map +1 -1
- package/dist/cjs/lib/map.cjs +1 -1
- package/dist/cjs/lib/map.cjs.map +1 -1
- package/dist/cjs/lib/max.cjs +2 -3
- package/dist/cjs/lib/max.cjs.map +1 -1
- package/dist/cjs/lib/min.cjs +2 -3
- package/dist/cjs/lib/min.cjs.map +1 -1
- package/dist/cjs/lib/partition.cjs +1 -1
- package/dist/cjs/lib/partition.cjs.map +1 -1
- package/dist/cjs/lib/peekable.cjs +1 -1
- package/dist/cjs/lib/peekable.cjs.map +1 -1
- package/dist/cjs/lib/prepend.cjs +1 -1
- package/dist/cjs/lib/prepend.cjs.map +1 -1
- package/dist/cjs/lib/product.cjs +1 -1
- package/dist/cjs/lib/product.cjs.map +1 -1
- package/dist/cjs/lib/range.cjs +1 -1
- package/dist/cjs/lib/range.cjs.map +1 -1
- package/dist/cjs/lib/reduce.cjs +2 -3
- package/dist/cjs/lib/reduce.cjs.map +1 -1
- package/dist/cjs/lib/repeat.cjs +1 -1
- package/dist/cjs/lib/repeat.cjs.map +1 -1
- package/dist/cjs/lib/reverse.cjs +1 -1
- package/dist/cjs/lib/reverse.cjs.map +1 -1
- package/dist/cjs/lib/shared/_assertFunction.cjs +1 -1
- package/dist/cjs/lib/shared/_assertFunction.cjs.map +1 -1
- package/dist/cjs/lib/shared/_assertNotNegative.cjs +1 -1
- package/dist/cjs/lib/shared/_assertNotNegative.cjs.map +1 -1
- package/dist/cjs/lib/shared/_assertPositive.cjs +1 -1
- package/dist/cjs/lib/shared/_assertPositive.cjs.map +1 -1
- package/dist/cjs/lib/shared/_makeIterableIterator.cjs +1 -1
- package/dist/cjs/lib/shared/_makeIterableIterator.cjs.map +1 -1
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs +4 -7
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs.map +1 -1
- package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs +4 -7
- package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs.map +1 -1
- package/dist/cjs/lib/shared/_toNumberOrThrow.cjs +1 -1
- package/dist/cjs/lib/shared/_toNumberOrThrow.cjs.map +1 -1
- package/dist/cjs/lib/slice.cjs +2 -3
- package/dist/cjs/lib/slice.cjs.map +1 -1
- package/dist/cjs/lib/some.cjs +1 -1
- package/dist/cjs/lib/some.cjs.map +1 -1
- package/dist/cjs/lib/sorted.cjs +1 -1
- package/dist/cjs/lib/sorted.cjs.map +1 -1
- package/dist/cjs/lib/starMap.cjs +1 -1
- package/dist/cjs/lib/starMap.cjs.map +1 -1
- package/dist/cjs/lib/sum.cjs +1 -1
- package/dist/cjs/lib/sum.cjs.map +1 -1
- package/dist/cjs/lib/take.cjs +2 -3
- package/dist/cjs/lib/take.cjs.map +1 -1
- package/dist/cjs/lib/takeLast.cjs +3 -5
- package/dist/cjs/lib/takeLast.cjs.map +1 -1
- package/dist/cjs/lib/tee.cjs +2 -3
- package/dist/cjs/lib/tee.cjs.map +1 -1
- package/dist/cjs/lib/toArray.cjs +1 -1
- package/dist/cjs/lib/toArray.cjs.map +1 -1
- package/dist/cjs/lib/toIterableIterator.cjs +1 -1
- package/dist/cjs/lib/toIterableIterator.cjs.map +1 -1
- package/dist/cjs/lib/union.cjs +1 -1
- package/dist/cjs/lib/union.cjs.map +1 -1
- package/dist/cjs/lib/unique.cjs +1 -1
- package/dist/cjs/lib/unique.cjs.map +1 -1
- package/dist/cjs/lib/unzip.cjs +2 -3
- package/dist/cjs/lib/unzip.cjs.map +1 -1
- package/dist/cjs/lib/zip.cjs +2 -3
- package/dist/cjs/lib/zip.cjs.map +1 -1
- package/dist/esm/{chunk-G5GHKT7C.mjs → chunk-PAWJFY3S.mjs} +2 -2
- package/dist/esm/chunk-PAWJFY3S.mjs.map +1 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/append.mjs +2 -2
- package/dist/esm/lib/append.mjs.map +1 -1
- package/dist/esm/lib/at.mjs +2 -2
- package/dist/esm/lib/at.mjs.map +1 -1
- package/dist/esm/lib/average.mjs +2 -2
- package/dist/esm/lib/average.mjs.map +1 -1
- package/dist/esm/lib/chain.mjs +2 -2
- package/dist/esm/lib/chain.mjs.map +1 -1
- package/dist/esm/lib/chunk.mjs +2 -2
- package/dist/esm/lib/chunk.mjs.map +1 -1
- package/dist/esm/lib/compact.mjs +2 -2
- package/dist/esm/lib/compact.mjs.map +1 -1
- package/dist/esm/lib/compress.mjs +2 -2
- package/dist/esm/lib/compress.mjs.map +1 -1
- package/dist/esm/lib/contains.mjs +3 -4
- package/dist/esm/lib/contains.mjs.map +1 -1
- package/dist/esm/lib/count.mjs +2 -2
- package/dist/esm/lib/count.mjs.map +1 -1
- package/dist/esm/lib/cycle.mjs +2 -2
- package/dist/esm/lib/cycle.mjs.map +1 -1
- package/dist/esm/lib/difference.mjs +2 -2
- package/dist/esm/lib/difference.mjs.map +1 -1
- package/dist/esm/lib/drop.mjs +5 -8
- package/dist/esm/lib/drop.mjs.map +1 -1
- package/dist/esm/lib/dropLast.mjs +3 -4
- package/dist/esm/lib/dropLast.mjs.map +1 -1
- package/dist/esm/lib/dropWhile.mjs +2 -2
- package/dist/esm/lib/dropWhile.mjs.map +1 -1
- package/dist/esm/lib/empty.mjs +2 -2
- package/dist/esm/lib/empty.mjs.map +1 -1
- package/dist/esm/lib/enumerate.mjs +2 -2
- package/dist/esm/lib/enumerate.mjs.map +1 -1
- package/dist/esm/lib/every.mjs +3 -4
- package/dist/esm/lib/every.mjs.map +1 -1
- package/dist/esm/lib/filter.mjs +3 -4
- package/dist/esm/lib/filter.mjs.map +1 -1
- package/dist/esm/lib/find.mjs +2 -2
- package/dist/esm/lib/find.mjs.map +1 -1
- package/dist/esm/lib/findIndex.mjs +2 -2
- package/dist/esm/lib/findIndex.mjs.map +1 -1
- package/dist/esm/lib/first.mjs +2 -2
- package/dist/esm/lib/first.mjs.map +1 -1
- package/dist/esm/lib/flat.mjs +2 -2
- package/dist/esm/lib/flat.mjs.map +1 -1
- package/dist/esm/lib/flatMap.mjs +2 -2
- package/dist/esm/lib/flatMap.mjs.map +1 -1
- package/dist/esm/lib/forEach.mjs +2 -2
- package/dist/esm/lib/forEach.mjs.map +1 -1
- package/dist/esm/lib/from.mjs +2 -2
- package/dist/esm/lib/from.mjs.map +1 -1
- package/dist/esm/lib/indexOf.mjs +2 -2
- package/dist/esm/lib/indexOf.mjs.map +1 -1
- package/dist/esm/lib/intersect.mjs +2 -2
- package/dist/esm/lib/intersect.mjs.map +1 -1
- package/dist/esm/lib/isEmpty.mjs +2 -2
- package/dist/esm/lib/isEmpty.mjs.map +1 -1
- package/dist/esm/lib/last.mjs +2 -2
- package/dist/esm/lib/last.mjs.map +1 -1
- package/dist/esm/lib/map.mjs +2 -2
- package/dist/esm/lib/map.mjs.map +1 -1
- package/dist/esm/lib/max.mjs +3 -4
- package/dist/esm/lib/max.mjs.map +1 -1
- package/dist/esm/lib/min.mjs +3 -4
- package/dist/esm/lib/min.mjs.map +1 -1
- package/dist/esm/lib/partition.mjs +2 -2
- package/dist/esm/lib/partition.mjs.map +1 -1
- package/dist/esm/lib/peekable.mjs +2 -2
- package/dist/esm/lib/peekable.mjs.map +1 -1
- package/dist/esm/lib/prepend.mjs +2 -2
- package/dist/esm/lib/prepend.mjs.map +1 -1
- package/dist/esm/lib/product.mjs +2 -2
- package/dist/esm/lib/product.mjs.map +1 -1
- package/dist/esm/lib/range.mjs +2 -2
- package/dist/esm/lib/range.mjs.map +1 -1
- package/dist/esm/lib/reduce.mjs +3 -4
- package/dist/esm/lib/reduce.mjs.map +1 -1
- package/dist/esm/lib/repeat.mjs +2 -2
- package/dist/esm/lib/repeat.mjs.map +1 -1
- package/dist/esm/lib/reverse.mjs +2 -2
- package/dist/esm/lib/reverse.mjs.map +1 -1
- package/dist/esm/lib/shared/_assertFunction.mjs +2 -2
- package/dist/esm/lib/shared/_assertFunction.mjs.map +1 -1
- package/dist/esm/lib/shared/_assertNotNegative.mjs +2 -2
- package/dist/esm/lib/shared/_assertNotNegative.mjs.map +1 -1
- package/dist/esm/lib/shared/_assertPositive.mjs +2 -2
- package/dist/esm/lib/shared/_assertPositive.mjs.map +1 -1
- package/dist/esm/lib/shared/_makeIterableIterator.mjs +2 -2
- package/dist/esm/lib/shared/_makeIterableIterator.mjs.map +1 -1
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs +5 -8
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs.map +1 -1
- package/dist/esm/lib/shared/_toIntegerOrThrow.mjs +5 -8
- package/dist/esm/lib/shared/_toIntegerOrThrow.mjs.map +1 -1
- package/dist/esm/lib/shared/_toNumberOrThrow.mjs +2 -2
- package/dist/esm/lib/shared/_toNumberOrThrow.mjs.map +1 -1
- package/dist/esm/lib/slice.mjs +3 -4
- package/dist/esm/lib/slice.mjs.map +1 -1
- package/dist/esm/lib/some.mjs +2 -2
- package/dist/esm/lib/some.mjs.map +1 -1
- package/dist/esm/lib/sorted.mjs +2 -2
- package/dist/esm/lib/sorted.mjs.map +1 -1
- package/dist/esm/lib/starMap.mjs +2 -2
- package/dist/esm/lib/starMap.mjs.map +1 -1
- package/dist/esm/lib/sum.mjs +2 -2
- package/dist/esm/lib/sum.mjs.map +1 -1
- package/dist/esm/lib/take.mjs +3 -4
- package/dist/esm/lib/take.mjs.map +1 -1
- package/dist/esm/lib/takeLast.mjs +4 -6
- package/dist/esm/lib/takeLast.mjs.map +1 -1
- package/dist/esm/lib/tee.mjs +3 -4
- package/dist/esm/lib/tee.mjs.map +1 -1
- package/dist/esm/lib/toArray.mjs +2 -2
- package/dist/esm/lib/toArray.mjs.map +1 -1
- package/dist/esm/lib/toIterableIterator.mjs +2 -2
- package/dist/esm/lib/toIterableIterator.mjs.map +1 -1
- package/dist/esm/lib/union.mjs +2 -2
- package/dist/esm/lib/union.mjs.map +1 -1
- package/dist/esm/lib/unique.mjs +2 -2
- package/dist/esm/lib/unique.mjs.map +1 -1
- package/dist/esm/lib/unzip.mjs +3 -4
- package/dist/esm/lib/unzip.mjs.map +1 -1
- package/dist/esm/lib/zip.mjs +3 -4
- package/dist/esm/lib/zip.mjs.map +1 -1
- package/dist/iife/index.global.js +24 -47
- package/dist/iife/index.global.js.map +1 -1
- package/package.json +9 -9
- package/dist/esm/chunk-G5GHKT7C.mjs.map +0 -1
package/dist/esm/lib/starMap.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import './from.mjs';
|
|
3
3
|
import { assertFunction } from './shared/_assertFunction.mjs';
|
|
4
4
|
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
@@ -12,5 +12,5 @@ function* starMap(iterable, callbackFn) {
|
|
|
12
12
|
__name(starMap, "starMap");
|
|
13
13
|
|
|
14
14
|
export { starMap };
|
|
15
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=starMap.mjs.map
|
|
16
16
|
//# sourceMappingURL=starMap.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/starMap.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/starMap.ts"],"names":[],"mappings":";;;;;AA0BO,UAAU,OAAA,CAChB,UACA,UAC+B,EAAA;AAC/B,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,IAAA,MAAM,UAAW,CAAA,GAAI,kBAAmB,CAAA,KAAK,CAAS,CAAA,CAAA;AAAA,GACvD;AACD,CAAA;AATiB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA","file":"starMap.mjs","sourcesContent":["import { type IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterable with the results of calling a provided function on each element of the input iterables as the function's parameters.\n *\n * @param iterable The iterable to map over.\n * @param callbackFn The callback function to apply to each element.\n * @returns An iterable iterator that yields the mapped elements.\n *\n * @example\n * ```typescript\n * import { starMap } from '@sapphire/iterator-utilities';\n *\n * const iterable = [[1, 2], [3, 4], [5, 6]];\n * console.log([...starMap(iterable, (a, b) => a + b)]);\n * // Output: [3, 7, 11]\n * ```\n *\n * @remarks\n *\n * While very similar to {@link map}, `starMap` takes an iterable of iterables (which can be an array of tuples) and\n * calls the function with each inner iterable's values as the function's parameters. {@link map} calls the function\n * with the value and the index by comparison.\n */\nexport function* starMap<const ElementType extends IterableResolvable<any>, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (...args: StarMapParameters<ElementType>) => MappedType\n): IterableIterator<MappedType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tyield callbackFn(...(toIterableIterator(value) as any));\n\t}\n}\n\nexport type StarMapParameters<ElementType> = ElementType extends readonly [...infer ElementTypeEntry]\n\t? ElementTypeEntry\n\t: ElementType extends IterableResolvable<infer ElementType>\n\t\t? ElementType[]\n\t\t: never;\n"]}
|
package/dist/esm/lib/sum.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { map } from './map.mjs';
|
|
3
3
|
import { toNumberOrThrow } from './shared/_toNumberOrThrow.mjs';
|
|
4
4
|
|
|
@@ -12,5 +12,5 @@ function sum(iterable) {
|
|
|
12
12
|
__name(sum, "sum");
|
|
13
13
|
|
|
14
14
|
export { sum };
|
|
15
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=sum.mjs.map
|
|
16
16
|
//# sourceMappingURL=sum.mjs.map
|
package/dist/esm/lib/sum.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/sum.ts"],"names":["sum"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/sum.ts"],"names":["sum"],"mappings":";;;;AAuBO,SAAS,IAAI,QAAgD,EAAA;AACnE,EAAA,IAAIA,IAAM,GAAA,CAAA,CAAA;AACV,EAAA,KAAA,MAAW,KAAS,IAAA,GAAA,CAAI,QAAU,EAAA,eAAe,CAAG,EAAA;AACnD,IAAAA,IAAO,IAAA,KAAA,CAAA;AAAA,GACR;AAEA,EAAOA,OAAAA,IAAAA,CAAAA;AACR,CAAA;AAPgB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"sum.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { map } from './map';\nimport { toNumberOrThrow, type NumberResolvable } from './shared/_toNumberOrThrow';\n\n/**\n * Consumes the iterable and returns the sum of all the elements.\n *\n * @param iterable An iterator of numbers to calculate the sum of.\n * @returns The sum of the numbers in the input iterator.\n *\n * @example\n * ```typescript\n * import { sum } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(sum(iterable));\n * // Output: 15\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function sum(iterable: IterableResolvable<NumberResolvable>) {\n\tlet sum = 0;\n\tfor (const value of map(iterable, toNumberOrThrow)) {\n\t\tsum += value;\n\t}\n\n\treturn sum;\n}\n"]}
|
package/dist/esm/lib/take.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { empty } from './empty.mjs';
|
|
3
3
|
import { from } from './from.mjs';
|
|
4
4
|
import { assertNotNegative } from './shared/_assertNotNegative.mjs';
|
|
@@ -7,8 +7,7 @@ import { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow
|
|
|
7
7
|
|
|
8
8
|
function take(iterable, count) {
|
|
9
9
|
count = assertNotNegative(toIntegerOrInfinityOrThrow(count), count);
|
|
10
|
-
if (count === 0)
|
|
11
|
-
return empty();
|
|
10
|
+
if (count === 0) return empty();
|
|
12
11
|
let i = 0;
|
|
13
12
|
const resolvedIterable = from(iterable);
|
|
14
13
|
return makeIterableIterator(
|
|
@@ -18,5 +17,5 @@ function take(iterable, count) {
|
|
|
18
17
|
__name(take, "take");
|
|
19
18
|
|
|
20
19
|
export { take };
|
|
21
|
-
//# sourceMappingURL=
|
|
20
|
+
//# sourceMappingURL=take.mjs.map
|
|
22
21
|
//# sourceMappingURL=take.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/take.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/take.ts"],"names":[],"mappings":";;;;;;;AAsBO,SAAS,IAAA,CAAwB,UAA2C,KAA8C,EAAA;AAChI,EAAA,KAAA,GAAQ,iBAAkB,CAAA,0BAAA,CAA2B,KAAK,CAAA,EAAG,KAAK,CAAA,CAAA;AAClE,EAAI,IAAA,KAAA,KAAU,CAAG,EAAA,OAAO,KAAM,EAAA,CAAA;AAE9B,EAAA,IAAI,CAAI,GAAA,CAAA,CAAA;AACR,EAAM,MAAA,gBAAA,GAAmB,KAAK,QAAQ,CAAA,CAAA;AACtC,EAAO,OAAA,oBAAA;AAAA,IAAkC,MACxC,CAAK,IAAA,KAAA,GACF,EAAE,IAAA,EAAM,IAAM,EAAA,KAAA,EAAO,KAAU,CAAA,EAAA,IAC9B,CAAK,EAAA,EAAA,gBAAA,CAAiB,IAAK,EAAA,CAAA;AAAA,GAChC,CAAA;AACD,CAAA;AAXgB,MAAA,CAAA,IAAA,EAAA,MAAA,CAAA","file":"take.mjs","sourcesContent":["import { empty } from './empty';\nimport { from, type IterableResolvable } from './from';\nimport { assertNotNegative } from './shared/_assertNotNegative';\nimport { makeIterableIterator } from './shared/_makeIterableIterator';\nimport { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow';\n\n/**\n * Creates an iterable with the first `count` elements.\n *\n * @param iterable The iterator to take values from.\n * @param count The maximum number of values to take from the iterator.\n * @returns An iterator that yields at most `count` values from the provided iterator.\n *\n * @example\n * ```typescript\n * import { take } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...take(iterable, 2)]);\n * // Output: [1, 2]\n * ```\n */\nexport function take<const ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType> {\n\tcount = assertNotNegative(toIntegerOrInfinityOrThrow(count), count);\n\tif (count === 0) return empty();\n\n\tlet i = 0;\n\tconst resolvedIterable = from(iterable);\n\treturn makeIterableIterator<ElementType>(() =>\n\t\ti >= count //\n\t\t\t? { done: true, value: undefined }\n\t\t\t: (i++, resolvedIterable.next())\n\t);\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { empty } from './empty.mjs';
|
|
3
3
|
import { assertNotNegative } from './shared/_assertNotNegative.mjs';
|
|
4
4
|
import { makeIterableIterator } from './shared/_makeIterableIterator.mjs';
|
|
@@ -8,10 +8,8 @@ import { toIterableIterator } from './toIterableIterator.mjs';
|
|
|
8
8
|
|
|
9
9
|
function takeLast(iterable, count) {
|
|
10
10
|
count = assertNotNegative(toIntegerOrInfinityOrThrow(count), count);
|
|
11
|
-
if (count === 0)
|
|
12
|
-
|
|
13
|
-
if (count === Number.POSITIVE_INFINITY)
|
|
14
|
-
return toIterableIterator(iterable);
|
|
11
|
+
if (count === 0) return empty();
|
|
12
|
+
if (count === Number.POSITIVE_INFINITY) return toIterableIterator(iterable);
|
|
15
13
|
const array = toArray(iterable);
|
|
16
14
|
let i = Math.max(0, array.length - count);
|
|
17
15
|
return makeIterableIterator(() => {
|
|
@@ -24,5 +22,5 @@ function takeLast(iterable, count) {
|
|
|
24
22
|
__name(takeLast, "takeLast");
|
|
25
23
|
|
|
26
24
|
export { takeLast };
|
|
27
|
-
//# sourceMappingURL=
|
|
25
|
+
//# sourceMappingURL=takeLast.mjs.map
|
|
28
26
|
//# sourceMappingURL=takeLast.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/takeLast.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/takeLast.ts"],"names":[],"mappings":";;;;;;;;AA4BO,SAAS,QAAA,CAA4B,UAA2C,KAA8C,EAAA;AACpI,EAAA,KAAA,GAAQ,iBAAkB,CAAA,0BAAA,CAA2B,KAAK,CAAA,EAAG,KAAK,CAAA,CAAA;AAClE,EAAI,IAAA,KAAA,KAAU,CAAG,EAAA,OAAO,KAAM,EAAA,CAAA;AAC9B,EAAA,IAAI,KAAU,KAAA,MAAA,CAAO,iBAAmB,EAAA,OAAO,mBAAmB,QAAQ,CAAA,CAAA;AAE1E,EAAM,MAAA,KAAA,GAAQ,QAAQ,QAAQ,CAAA,CAAA;AAC9B,EAAA,IAAI,IAAI,IAAK,CAAA,GAAA,CAAI,CAAG,EAAA,KAAA,CAAM,SAAS,KAAK,CAAA,CAAA;AACxC,EAAA,OAAO,qBAAkC,MAAM;AAC9C,IAAI,IAAA,CAAA,IAAK,MAAM,MAAQ,EAAA;AACtB,MAAA,OAAO,EAAE,IAAA,EAAM,IAAM,EAAA,KAAA,EAAO,KAAU,CAAA,EAAA,CAAA;AAAA,KACvC;AAEA,IAAA,OAAO,EAAE,IAAM,EAAA,KAAA,EAAO,KAAO,EAAA,KAAA,CAAM,GAAG,CAAE,EAAA,CAAA;AAAA,GACxC,CAAA,CAAA;AACF,CAAA;AAdgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"takeLast.mjs","sourcesContent":["import { empty } from './empty';\nimport type { IterableResolvable } from './from';\nimport { assertNotNegative } from './shared/_assertNotNegative';\nimport { makeIterableIterator } from './shared/_makeIterableIterator';\nimport { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow';\nimport { toArray } from './toArray';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable and returns a new iterable with the last `count` elements.\n *\n * @param iterable An iterator to take values from.\n * @param count The number of values to take from the end of the iterator.\n * @returns An iterator that contains the last `count` elements of the provided iterator.\n *\n * @example\n * ```typescript\n * import { takeLast } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...takeLast(iterable, 2)]);\n * // Output: [4, 5]\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function takeLast<const ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType> {\n\tcount = assertNotNegative(toIntegerOrInfinityOrThrow(count), count);\n\tif (count === 0) return empty();\n\tif (count === Number.POSITIVE_INFINITY) return toIterableIterator(iterable);\n\n\tconst array = toArray(iterable);\n\tlet i = Math.max(0, array.length - count);\n\treturn makeIterableIterator<ElementType>(() => {\n\t\tif (i >= array.length) {\n\t\t\treturn { done: true, value: undefined };\n\t\t}\n\n\t\treturn { done: false, value: array[i++] };\n\t});\n}\n"]}
|
package/dist/esm/lib/tee.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { from } from './from.mjs';
|
|
3
3
|
import { repeat } from './repeat.mjs';
|
|
4
4
|
import { assertNotNegative } from './shared/_assertNotNegative.mjs';
|
|
@@ -8,8 +8,7 @@ import { toArray } from './toArray.mjs';
|
|
|
8
8
|
|
|
9
9
|
function tee(iterable, count) {
|
|
10
10
|
count = assertNotNegative(toIntegerOrThrow(count), count);
|
|
11
|
-
if (count === 0)
|
|
12
|
-
return [];
|
|
11
|
+
if (count === 0) return [];
|
|
13
12
|
const entries = [];
|
|
14
13
|
const indexes = toArray(repeat(0, count));
|
|
15
14
|
const resolvedIterable = from(iterable);
|
|
@@ -32,5 +31,5 @@ function tee(iterable, count) {
|
|
|
32
31
|
__name(tee, "tee");
|
|
33
32
|
|
|
34
33
|
export { tee };
|
|
35
|
-
//# sourceMappingURL=
|
|
34
|
+
//# sourceMappingURL=tee.mjs.map
|
|
36
35
|
//# sourceMappingURL=tee.mjs.map
|
package/dist/esm/lib/tee.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/tee.ts"],"names":["iterable"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/tee.ts"],"names":["iterable"],"mappings":";;;;;;;;AA2BO,SAAS,GAAA,CAAuB,UAA2C,KAAgD,EAAA;AACjI,EAAA,KAAA,GAAQ,iBAAkB,CAAA,gBAAA,CAAiB,KAAK,CAAA,EAAG,KAAK,CAAA,CAAA;AACxD,EAAI,IAAA,KAAA,KAAU,CAAG,EAAA,OAAO,EAAC,CAAA;AAEzB,EAAA,MAAM,UAAU,EAAC,CAAA;AACjB,EAAA,MAAM,OAAU,GAAA,OAAA,CAAQ,MAAO,CAAA,CAAA,EAAG,KAAK,CAAC,CAAA,CAAA;AACxC,EAAM,MAAA,gBAAA,GAAmB,KAAK,QAAQ,CAAA,CAAA;AAEtC,EAAA,MAAM,YAAY,EAAC,CAAA;AACnB,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,EAAO,CAAK,EAAA,EAAA;AAC/B,IAAMA,MAAAA,SAAAA,GAAW,qBAAkC,MAAM;AACxD,MAAA,IAAI,OAAQ,CAAA,CAAC,CAAK,IAAA,OAAA,CAAQ,MAAQ,EAAA;AACjC,QAAM,MAAA,MAAA,GAAS,iBAAiB,IAAK,EAAA,CAAA;AACrC,QAAA,IAAI,OAAO,IAAM,EAAA;AAChB,UAAA,OAAO,EAAE,IAAA,EAAM,IAAM,EAAA,KAAA,EAAO,KAAU,CAAA,EAAA,CAAA;AAAA,SACvC;AAEA,QAAQ,OAAA,CAAA,IAAA,CAAK,OAAO,KAAK,CAAA,CAAA;AAAA,OAC1B;AAEA,MAAO,OAAA,EAAE,MAAM,KAAO,EAAA,KAAA,EAAO,QAAQ,OAAQ,CAAA,CAAC,GAAG,CAAE,EAAA,CAAA;AAAA,KACnD,CAAA,CAAA;AAED,IAAA,SAAA,CAAU,KAAKA,SAAQ,CAAA,CAAA;AAAA,GACxB;AAEA,EAAO,OAAA,SAAA,CAAA;AACR,CAAA;AA3BgB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"tee.mjs","sourcesContent":["import { from, type IterableResolvable } from './from';\nimport { repeat } from './repeat';\nimport { assertNotNegative } from './shared/_assertNotNegative';\nimport { makeIterableIterator } from './shared/_makeIterableIterator';\nimport { toIntegerOrThrow } from './shared/_toIntegerOrThrow';\nimport { toArray } from './toArray';\n\n/**\n * Creates `count` independent iterators from the input iterable.\n *\n * @param iterable An iterator to tee.\n * @param count The number of iterators to create.\n * @returns An array of `count` iterators that each yield the same values as the input iterator.\n *\n * @example\n * ```typescript\n * import { tee } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * const [iter1, iter2] = tee(iterable, 2);\n * console.log([...iter1]);\n * // Output: [1, 2, 3, 4, 5]\n *\n * console.log([...iter2]);\n * // Output: [1, 2, 3, 4, 5]\n * ```\n */\nexport function tee<const ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType>[] {\n\tcount = assertNotNegative(toIntegerOrThrow(count), count);\n\tif (count === 0) return [];\n\n\tconst entries = [] as ElementType[];\n\tconst indexes = toArray(repeat(0, count));\n\tconst resolvedIterable = from(iterable);\n\n\tconst iterables = [] as IterableIterator<ElementType>[];\n\tfor (let i = 0; i < count; i++) {\n\t\tconst iterable = makeIterableIterator<ElementType>(() => {\n\t\t\tif (indexes[i] >= entries.length) {\n\t\t\t\tconst result = resolvedIterable.next();\n\t\t\t\tif (result.done) {\n\t\t\t\t\treturn { done: true, value: undefined };\n\t\t\t\t}\n\n\t\t\t\tentries.push(result.value);\n\t\t\t}\n\n\t\t\treturn { done: false, value: entries[indexes[i]++] };\n\t\t});\n\n\t\titerables.push(iterable);\n\t}\n\n\treturn iterables;\n}\n"]}
|
package/dist/esm/lib/toArray.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
3
3
|
|
|
4
4
|
function toArray(iterable) {
|
|
@@ -7,5 +7,5 @@ function toArray(iterable) {
|
|
|
7
7
|
__name(toArray, "toArray");
|
|
8
8
|
|
|
9
9
|
export { toArray };
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=toArray.mjs.map
|
|
11
11
|
//# sourceMappingURL=toArray.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/toArray.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/toArray.ts"],"names":[],"mappings":";;;AAkCO,SAAS,QAA2B,QAA0D,EAAA;AACpG,EAAA,OAAO,CAAC,GAAG,kBAAmB,CAAA,QAAQ,CAAC,CAAA,CAAA;AACxC,CAAA;AAFgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA","file":"toArray.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable and returns an array with all the elements.\n *\n * @param iterable The iterator to convert to an array.\n * @returns An array containing the values of the provided iterator.\n *\n * @example\n * ```typescript\n * import { toArray } from '@sapphire/iterator-utilities';\n *\n * const array = [1, 2, 3, 4, 5];\n * console.log(toArray(array));\n * // Output: [1, 2, 3, 4, 5]\n *\n * const set = new Set([1, 2, 3, 4, 5]);\n * console.log(toArray(set));\n * // Output: [1, 2, 3, 4, 5]\n *\n * const map = new Map([['a', 1], ['b', 2], ['c', 3]]);\n * console.log(toArray(map));\n * // Output: [['a', 1], ['b', 2], ['c', 3]]\n *\n * const string = 'hello';\n * console.log(toArray(string));\n * // Output: ['h', 'e', 'l', 'l', 'o']\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function toArray<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType[] {\n\treturn [...toIterableIterator(iterable)];\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { from } from './from.mjs';
|
|
3
3
|
import { makeIterableIterator } from './shared/_makeIterableIterator.mjs';
|
|
4
4
|
|
|
@@ -12,5 +12,5 @@ function toIterableIterator(iterable) {
|
|
|
12
12
|
__name(toIterableIterator, "toIterableIterator");
|
|
13
13
|
|
|
14
14
|
export { toIterableIterator };
|
|
15
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=toIterableIterator.mjs.map
|
|
16
16
|
//# sourceMappingURL=toIterableIterator.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/toIterableIterator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/toIterableIterator.ts"],"names":[],"mappings":";;;;AA8BO,SAAS,mBAAsC,QAA0E,EAAA;AAC/H,EAAM,MAAA,gBAAA,GAAmB,KAAK,QAAQ,CAAA,CAAA;AACtC,EAAI,IAAA,MAAA,CAAO,YAAY,gBAAkB,EAAA;AACxC,IAAO,OAAA,gBAAA,CAAA;AAAA,GACR;AAEA,EAAA,OAAO,oBAAqB,CAAA,MAAM,gBAAiB,CAAA,IAAA,EAAM,CAAA,CAAA;AAC1D,CAAA;AAPgB,MAAA,CAAA,kBAAA,EAAA,oBAAA,CAAA","file":"toIterableIterator.mjs","sourcesContent":["import { from, type IterableResolvable } from './from';\nimport { makeIterableIterator } from './shared/_makeIterableIterator';\n\n/**\n * Creates an iterable iterator from an iterable or iterator-like object.\n *\n * @param iterable The iterable or iterable-like object to convert.\n * @returns An iterable iterator.\n *\n * @example\n * ```typescript\n * import { toIterableIterator } from '@sapphire/iterator-utilities';\n *\n * const array = [1, 2, 3, 4, 5];\n * console.log([...toIterableIterator(array)]);\n * // Output: [1, 2, 3, 4, 5]\n *\n * const set = new Set([1, 2, 3, 4, 5]);\n * console.log([...toIterableIterator(set)]);\n * // Output: [1, 2, 3, 4, 5]\n *\n * const map = new Map([['a', 1], ['b', 2], ['c', 3]]);\n * console.log([...toIterableIterator(map)]);\n * // Output: [['a', 1], ['b', 2], ['c', 3]]\n *\n * const string = 'hello';\n * console.log([...toIterableIterator(string)]);\n * // Output: ['h', 'e', 'l', 'l', 'o']\n * ```\n */\nexport function toIterableIterator<const ElementType>(iterable: IterableResolvable<ElementType>): IterableIterator<ElementType> {\n\tconst resolvedIterable = from(iterable);\n\tif (Symbol.iterator in resolvedIterable) {\n\t\treturn resolvedIterable;\n\t}\n\n\treturn makeIterableIterator(() => resolvedIterable.next());\n}\n"]}
|
package/dist/esm/lib/union.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
3
3
|
|
|
4
4
|
function* union(...iterables) {
|
|
@@ -15,5 +15,5 @@ function* union(...iterables) {
|
|
|
15
15
|
__name(union, "union");
|
|
16
16
|
|
|
17
17
|
export { union };
|
|
18
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=union.mjs.map
|
|
19
19
|
//# sourceMappingURL=union.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/union.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/union.ts"],"names":[],"mappings":";;;AAmBO,UAAU,SAA4B,SAA6E,EAAA;AACzH,EAAM,MAAA,IAAA,uBAAW,GAAiB,EAAA,CAAA;AAClC,EAAA,KAAA,MAAW,YAAY,SAAW,EAAA;AACjC,IAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,MAAA,IAAI,CAAC,IAAA,CAAK,GAAI,CAAA,KAAK,CAAG,EAAA;AACrB,QAAA,IAAA,CAAK,IAAI,KAAK,CAAA,CAAA;AACd,QAAM,MAAA,KAAA,CAAA;AAAA,OACP;AAAA,KACD;AAAA,GACD;AACD,CAAA;AAViB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA","file":"union.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterable with the elements that are in either input iterable.\n *\n * @param iterables The iterators to combine.\n * @returns An iterator that yields the union of the provided iterators.\n *\n * @example\n * ```typescript\n * import { union } from '@sapphire/iterator-utilities';\n *\n * const iterable1 = [1, 2, 3];\n * const iterable2 = [3, 4, 5];\n * console.log([...union(iterable1, iterable2)]);\n * // Output: [1, 2, 3, 4, 5]\n * ```\n */\nexport function* union<const ElementType>(...iterables: IterableResolvable<ElementType>[]): IterableIterator<ElementType> {\n\tconst seen = new Set<ElementType>();\n\tfor (const iterator of iterables) {\n\t\tfor (const value of toIterableIterator(iterator)) {\n\t\t\tif (!seen.has(value)) {\n\t\t\t\tseen.add(value);\n\t\t\t\tyield value;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/dist/esm/lib/unique.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { union } from './union.mjs';
|
|
3
3
|
|
|
4
4
|
function unique(iterable) {
|
|
@@ -7,5 +7,5 @@ function unique(iterable) {
|
|
|
7
7
|
__name(unique, "unique");
|
|
8
8
|
|
|
9
9
|
export { unique };
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=unique.mjs.map
|
|
11
11
|
//# sourceMappingURL=unique.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/unique.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/unique.ts"],"names":[],"mappings":";;;AAkBO,SAAS,OAA0B,QAA0E,EAAA;AAEnH,EAAA,OAAO,MAAM,QAAQ,CAAA,CAAA;AACtB,CAAA;AAHgB,MAAA,CAAA,MAAA,EAAA,QAAA,CAAA","file":"unique.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { union } from './union';\n\n/**\n * Creates an iterable with the unique elements of the input iterable. Under the hood, it calls {@linkcode union} with the iterable itself.\n *\n * @param iterable An iterator to remove duplicates from.\n * @returns An iterator that yields the values of the provided iterator with duplicates removed.\n *\n * @example\n * ```typescript\n * import { unique } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5];\n * console.log([...unique(iterable)]);\n * // Output: [1, 2, 3, 4, 5]\n * ```\n */\nexport function unique<const ElementType>(iterable: IterableResolvable<ElementType>): IterableIterator<ElementType> {\n\t// The union of a single iterator is the iterator itself, with duplicates removed.\n\treturn union(iterable);\n}\n"]}
|
package/dist/esm/lib/unzip.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
2
|
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
3
3
|
|
|
4
4
|
function unzip(iterable) {
|
|
@@ -12,8 +12,7 @@ function unzip(iterable) {
|
|
|
12
12
|
}
|
|
13
13
|
const size = firstResult.value.length;
|
|
14
14
|
const results = [];
|
|
15
|
-
for (let i = 0; i < size; i++)
|
|
16
|
-
results.push([firstResult.value[i]]);
|
|
15
|
+
for (let i = 0; i < size; i++) results.push([firstResult.value[i]]);
|
|
17
16
|
for (const entries of resolvedIterable) {
|
|
18
17
|
if (!Array.isArray(entries)) {
|
|
19
18
|
throw new Error("Cannot unzip an iterable that does not yield an array");
|
|
@@ -30,5 +29,5 @@ function unzip(iterable) {
|
|
|
30
29
|
__name(unzip, "unzip");
|
|
31
30
|
|
|
32
31
|
export { unzip };
|
|
33
|
-
//# sourceMappingURL=
|
|
32
|
+
//# sourceMappingURL=unzip.mjs.map
|
|
34
33
|
//# sourceMappingURL=unzip.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/unzip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/unzip.ts"],"names":[],"mappings":";;;AA2BO,SAAS,MAAgD,QAAuE,EAAA;AACtI,EAAM,MAAA,gBAAA,GAAmB,mBAAmB,QAAQ,CAAA,CAAA;AACpD,EAAM,MAAA,WAAA,GAAc,iBAAiB,IAAK,EAAA,CAAA;AAC1C,EAAA,IAAI,YAAY,IAAM,EAAA;AACrB,IAAM,MAAA,IAAI,MAAM,gCAAgC,CAAA,CAAA;AAAA,GACjD;AAEA,EAAA,IAAI,CAAC,KAAA,CAAM,OAAQ,CAAA,WAAA,CAAY,KAAK,CAAG,EAAA;AACtC,IAAM,MAAA,IAAI,MAAM,uDAAuD,CAAA,CAAA;AAAA,GACxE;AAEA,EAAM,MAAA,IAAA,GAAO,YAAY,KAAM,CAAA,MAAA,CAAA;AAC/B,EAAA,MAAM,UAAU,EAAC,CAAA;AACjB,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,EAAM,CAAK,EAAA,EAAA,OAAA,CAAQ,IAAK,CAAA,CAAC,WAAY,CAAA,KAAA,CAAM,CAAC,CAAC,CAAC,CAAA,CAAA;AAClE,EAAA,KAAA,MAAW,WAAW,gBAAkB,EAAA;AACvC,IAAA,IAAI,CAAC,KAAA,CAAM,OAAQ,CAAA,OAAO,CAAG,EAAA;AAC5B,MAAM,MAAA,IAAI,MAAM,uDAAuD,CAAA,CAAA;AAAA,KACxE;AAEA,IAAI,IAAA,OAAA,CAAQ,WAAW,IAAM,EAAA;AAC5B,MAAM,MAAA,IAAI,MAAM,gEAAgE,CAAA,CAAA;AAAA,KACjF;AAEA,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,EAAM,CAAK,EAAA,EAAA;AAC9B,MAAA,OAAA,CAAQ,CAAC,CAAA,CAAE,IAAK,CAAA,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA;AAAA,KAC3B;AAAA,GACD;AAEA,EAAO,OAAA,OAAA,CAAA;AACR,CAAA;AA7BgB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA","file":"unzip.mjs","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-PAWJFY3S.mjs';
|
|
2
2
|
import { from } from './from.mjs';
|
|
3
3
|
|
|
4
4
|
function* zip(...iterables) {
|
|
@@ -7,8 +7,7 @@ function* zip(...iterables) {
|
|
|
7
7
|
const results = [];
|
|
8
8
|
for (const resolvedIterable of resolvedIterables) {
|
|
9
9
|
const result = resolvedIterable.next();
|
|
10
|
-
if (result.done)
|
|
11
|
-
return;
|
|
10
|
+
if (result.done) return;
|
|
12
11
|
results.push(result.value);
|
|
13
12
|
}
|
|
14
13
|
yield results;
|
|
@@ -17,5 +16,5 @@ function* zip(...iterables) {
|
|
|
17
16
|
__name(zip, "zip");
|
|
18
17
|
|
|
19
18
|
export { zip };
|
|
20
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=zip.mjs.map
|
|
21
20
|
//# sourceMappingURL=zip.mjs.map
|
package/dist/esm/lib/zip.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/zip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/zip.ts"],"names":[],"mappings":";;;AAwBO,UAAU,OAAmE,SAA+C,EAAA;AAClI,EAAA,MAAM,oBAAoB,SAAU,CAAA,GAAA,CAAI,CAAC,QAAa,KAAA,IAAA,CAAK,QAAQ,CAAC,CAAA,CAAA;AACpE,EAAA,OAAO,IAAM,EAAA;AACZ,IAAA,MAAM,UAAU,EAAC,CAAA;AACjB,IAAA,KAAA,MAAW,oBAAoB,iBAAmB,EAAA;AACjD,MAAM,MAAA,MAAA,GAAS,iBAAiB,IAAK,EAAA,CAAA;AACrC,MAAA,IAAI,OAAO,IAAM,EAAA,OAAA;AAEjB,MAAQ,OAAA,CAAA,IAAA,CAAK,OAAO,KAAK,CAAA,CAAA;AAAA,KAC1B;AAEA,IAAM,MAAA,OAAA,CAAA;AAAA,GACP;AACD,CAAA;AAbiB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"zip.mjs","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,12 +100,9 @@ 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.
|
|
106
|
-
return Number.POSITIVE_INFINITY;
|
|
107
|
-
if (number === Number.NEGATIVE_INFINITY)
|
|
108
|
-
return Number.NEGATIVE_INFINITY;
|
|
103
|
+
if (Number.isNaN(number) || number === 0) return 0;
|
|
104
|
+
if (number === Number.POSITIVE_INFINITY) return Number.POSITIVE_INFINITY;
|
|
105
|
+
if (number === Number.NEGATIVE_INFINITY) return Number.NEGATIVE_INFINITY;
|
|
109
106
|
return Math.trunc(number);
|
|
110
107
|
}
|
|
111
108
|
__name(toIntegerOrInfinityOrThrow, "toIntegerOrInfinityOrThrow");
|
|
@@ -114,13 +111,10 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
114
111
|
function drop(iterable, count2) {
|
|
115
112
|
count2 = assertNotNegative(toIntegerOrInfinityOrThrow(count2), count2);
|
|
116
113
|
const resolvedIterable = toIterableIterator(iterable);
|
|
117
|
-
if (count2 === 0)
|
|
118
|
-
|
|
119
|
-
if (count2 === Number.POSITIVE_INFINITY)
|
|
120
|
-
return empty();
|
|
114
|
+
if (count2 === 0) return resolvedIterable;
|
|
115
|
+
if (count2 === Number.POSITIVE_INFINITY) return empty();
|
|
121
116
|
for (let i = 0; i < count2; i++) {
|
|
122
|
-
if (resolvedIterable.next().done)
|
|
123
|
-
break;
|
|
117
|
+
if (resolvedIterable.next().done) break;
|
|
124
118
|
}
|
|
125
119
|
return resolvedIterable;
|
|
126
120
|
}
|
|
@@ -182,12 +176,9 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
182
176
|
// src/lib/shared/_toIntegerOrThrow.ts
|
|
183
177
|
function toIntegerOrThrow(value) {
|
|
184
178
|
const number = toNumberOrThrow(value);
|
|
185
|
-
if (Number.isNaN(number) || number === 0)
|
|
186
|
-
|
|
187
|
-
if (number === Number.
|
|
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");
|
|
179
|
+
if (Number.isNaN(number) || number === 0) return 0;
|
|
180
|
+
if (number === Number.POSITIVE_INFINITY) throw new RangeError("+Infinity cannot be represented as an integer");
|
|
181
|
+
if (number === Number.NEGATIVE_INFINITY) throw new RangeError("-Infinity cannot be represented as an integer");
|
|
191
182
|
return Math.trunc(number);
|
|
192
183
|
}
|
|
193
184
|
__name(toIntegerOrThrow, "toIntegerOrThrow");
|
|
@@ -214,8 +205,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
214
205
|
callbackFn = assertFunction(callbackFn);
|
|
215
206
|
let index = 0;
|
|
216
207
|
for (const value of toIterableIterator(iterable)) {
|
|
217
|
-
if (callbackFn(value, index++))
|
|
218
|
-
yield value;
|
|
208
|
+
if (callbackFn(value, index++)) yield value;
|
|
219
209
|
}
|
|
220
210
|
}
|
|
221
211
|
__name(filter, "filter");
|
|
@@ -244,8 +234,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
244
234
|
// src/lib/contains.ts
|
|
245
235
|
function contains(iterable, value) {
|
|
246
236
|
for (const element of toIterableIterator(iterable)) {
|
|
247
|
-
if (element === value)
|
|
248
|
-
return true;
|
|
237
|
+
if (element === value) return true;
|
|
249
238
|
}
|
|
250
239
|
return false;
|
|
251
240
|
}
|
|
@@ -287,8 +276,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
287
276
|
// src/lib/take.ts
|
|
288
277
|
function take(iterable, count2) {
|
|
289
278
|
count2 = assertNotNegative(toIntegerOrInfinityOrThrow(count2), count2);
|
|
290
|
-
if (count2 === 0)
|
|
291
|
-
return empty();
|
|
279
|
+
if (count2 === 0) return empty();
|
|
292
280
|
let i = 0;
|
|
293
281
|
const resolvedIterable = from(iterable);
|
|
294
282
|
return makeIterableIterator(
|
|
@@ -307,8 +295,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
307
295
|
function dropLast(iterable, count2) {
|
|
308
296
|
count2 = assertNotNegative(toIntegerOrInfinityOrThrow(count2), count2);
|
|
309
297
|
const array = toArray(iterable);
|
|
310
|
-
if (array.length <= count2)
|
|
311
|
-
return empty();
|
|
298
|
+
if (array.length <= count2) return empty();
|
|
312
299
|
return take(array.values(), array.length - count2);
|
|
313
300
|
}
|
|
314
301
|
__name(dropLast, "dropLast");
|
|
@@ -339,8 +326,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
339
326
|
callbackFn = assertFunction(callbackFn);
|
|
340
327
|
let index = 0;
|
|
341
328
|
for (const value of toIterableIterator(iterable)) {
|
|
342
|
-
if (!callbackFn(value, index++))
|
|
343
|
-
return false;
|
|
329
|
+
if (!callbackFn(value, index++)) return false;
|
|
344
330
|
}
|
|
345
331
|
return true;
|
|
346
332
|
}
|
|
@@ -434,8 +420,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
434
420
|
function max(iterable) {
|
|
435
421
|
let max2 = null;
|
|
436
422
|
for (const value of map(iterable, toNumberOrThrow)) {
|
|
437
|
-
if (max2 === null || value > max2)
|
|
438
|
-
max2 = value;
|
|
423
|
+
if (max2 === null || value > max2) max2 = value;
|
|
439
424
|
}
|
|
440
425
|
return max2;
|
|
441
426
|
}
|
|
@@ -445,8 +430,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
445
430
|
function min(iterable) {
|
|
446
431
|
let min2 = null;
|
|
447
432
|
for (const value of map(iterable, toNumberOrThrow)) {
|
|
448
|
-
if (min2 === null || value < min2)
|
|
449
|
-
min2 = value;
|
|
433
|
+
if (min2 === null || value < min2) min2 = value;
|
|
450
434
|
}
|
|
451
435
|
return min2;
|
|
452
436
|
}
|
|
@@ -548,8 +532,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
548
532
|
const resolvedIterable = toIterableIterator(iterable);
|
|
549
533
|
if (arguments.length < 3) {
|
|
550
534
|
const firstValue = resolvedIterable.next();
|
|
551
|
-
if (firstValue.done)
|
|
552
|
-
throw new TypeError("Reduce of empty iterator with no initial value");
|
|
535
|
+
if (firstValue.done) throw new TypeError("Reduce of empty iterator with no initial value");
|
|
553
536
|
index = 1;
|
|
554
537
|
accumulator = firstValue.value;
|
|
555
538
|
} else {
|
|
@@ -588,10 +571,8 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
588
571
|
// src/lib/takeLast.ts
|
|
589
572
|
function takeLast(iterable, count2) {
|
|
590
573
|
count2 = assertNotNegative(toIntegerOrInfinityOrThrow(count2), count2);
|
|
591
|
-
if (count2 === 0)
|
|
592
|
-
|
|
593
|
-
if (count2 === Number.POSITIVE_INFINITY)
|
|
594
|
-
return toIterableIterator(iterable);
|
|
574
|
+
if (count2 === 0) return empty();
|
|
575
|
+
if (count2 === Number.POSITIVE_INFINITY) return toIterableIterator(iterable);
|
|
595
576
|
const array = toArray(iterable);
|
|
596
577
|
let i = Math.max(0, array.length - count2);
|
|
597
578
|
return makeIterableIterator(() => {
|
|
@@ -628,8 +609,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
628
609
|
}
|
|
629
610
|
return take(takeLast(iterable, -start), end - start);
|
|
630
611
|
}
|
|
631
|
-
if (start >= end)
|
|
632
|
-
return empty();
|
|
612
|
+
if (start >= end) return empty();
|
|
633
613
|
return end === Number.POSITIVE_INFINITY ? drop(iterable, start) : take(drop(iterable, start), end - start);
|
|
634
614
|
}
|
|
635
615
|
__name(slice, "slice");
|
|
@@ -675,8 +655,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
675
655
|
// src/lib/tee.ts
|
|
676
656
|
function tee(iterable, count2) {
|
|
677
657
|
count2 = assertNotNegative(toIntegerOrThrow(count2), count2);
|
|
678
|
-
if (count2 === 0)
|
|
679
|
-
return [];
|
|
658
|
+
if (count2 === 0) return [];
|
|
680
659
|
const entries = [];
|
|
681
660
|
const indexes = toArray(repeat(0, count2));
|
|
682
661
|
const resolvedIterable = from(iterable);
|
|
@@ -730,8 +709,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
730
709
|
}
|
|
731
710
|
const size = firstResult.value.length;
|
|
732
711
|
const results = [];
|
|
733
|
-
for (let i = 0; i < size; i++)
|
|
734
|
-
results.push([firstResult.value[i]]);
|
|
712
|
+
for (let i = 0; i < size; i++) results.push([firstResult.value[i]]);
|
|
735
713
|
for (const entries of resolvedIterable) {
|
|
736
714
|
if (!Array.isArray(entries)) {
|
|
737
715
|
throw new Error("Cannot unzip an iterable that does not yield an array");
|
|
@@ -754,8 +732,7 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
754
732
|
const results = [];
|
|
755
733
|
for (const resolvedIterable of resolvedIterables) {
|
|
756
734
|
const result = resolvedIterable.next();
|
|
757
|
-
if (result.done)
|
|
758
|
-
return;
|
|
735
|
+
if (result.done) return;
|
|
759
736
|
results.push(result.value);
|
|
760
737
|
}
|
|
761
738
|
yield results;
|
|
@@ -829,5 +806,5 @@ var SapphireIteratorUtilities = (function (exports) {
|
|
|
829
806
|
return exports;
|
|
830
807
|
|
|
831
808
|
})({});
|
|
832
|
-
//# sourceMappingURL=
|
|
809
|
+
//# sourceMappingURL=index.global.js.map
|
|
833
810
|
//# sourceMappingURL=index.global.js.map
|