@sapphire/iterator-utilities 1.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/CHANGELOG.md +10 -0
- package/README.md +765 -0
- package/dist/cjs/index.cjs +385 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +55 -0
- package/dist/cjs/lib/append.cjs +15 -0
- package/dist/cjs/lib/append.cjs.map +1 -0
- package/dist/cjs/lib/append.d.cts +21 -0
- package/dist/cjs/lib/at.cjs +18 -0
- package/dist/cjs/lib/at.cjs.map +1 -0
- package/dist/cjs/lib/at.d.cts +25 -0
- package/dist/cjs/lib/average.cjs +21 -0
- package/dist/cjs/lib/average.cjs.map +1 -0
- package/dist/cjs/lib/average.d.cts +25 -0
- package/dist/cjs/lib/chain.cjs +16 -0
- package/dist/cjs/lib/chain.cjs.map +1 -0
- package/dist/cjs/lib/chain.d.cts +20 -0
- package/dist/cjs/lib/chunk.cjs +27 -0
- package/dist/cjs/lib/chunk.cjs.map +1 -0
- package/dist/cjs/lib/chunk.d.cts +20 -0
- package/dist/cjs/lib/compact.cjs +14 -0
- package/dist/cjs/lib/compact.cjs.map +1 -0
- package/dist/cjs/lib/compact.d.cts +19 -0
- package/dist/cjs/lib/compress.cjs +24 -0
- package/dist/cjs/lib/compress.cjs.map +1 -0
- package/dist/cjs/lib/compress.d.cts +26 -0
- package/dist/cjs/lib/contains.cjs +18 -0
- package/dist/cjs/lib/contains.cjs.map +1 -0
- package/dist/cjs/lib/contains.d.cts +25 -0
- package/dist/cjs/lib/count.cjs +19 -0
- package/dist/cjs/lib/count.cjs.map +1 -0
- package/dist/cjs/lib/count.d.cts +24 -0
- package/dist/cjs/lib/cycle.cjs +23 -0
- package/dist/cjs/lib/cycle.cjs.map +1 -0
- package/dist/cjs/lib/cycle.d.cts +21 -0
- package/dist/cjs/lib/difference.cjs +18 -0
- package/dist/cjs/lib/difference.cjs.map +1 -0
- package/dist/cjs/lib/difference.d.cts +25 -0
- package/dist/cjs/lib/drop.cjs +28 -0
- package/dist/cjs/lib/drop.cjs.map +1 -0
- package/dist/cjs/lib/drop.d.cts +21 -0
- package/dist/cjs/lib/dropLast.cjs +23 -0
- package/dist/cjs/lib/dropLast.cjs.map +1 -0
- package/dist/cjs/lib/dropLast.d.cts +25 -0
- package/dist/cjs/lib/dropWhile.cjs +22 -0
- package/dist/cjs/lib/dropWhile.cjs.map +1 -0
- package/dist/cjs/lib/dropWhile.d.cts +24 -0
- package/dist/cjs/lib/empty.cjs +14 -0
- package/dist/cjs/lib/empty.cjs.map +1 -0
- package/dist/cjs/lib/empty.d.cts +17 -0
- package/dist/cjs/lib/enumerate.cjs +17 -0
- package/dist/cjs/lib/enumerate.cjs.map +1 -0
- package/dist/cjs/lib/enumerate.d.cts +24 -0
- package/dist/cjs/lib/every.cjs +21 -0
- package/dist/cjs/lib/every.cjs.map +1 -0
- package/dist/cjs/lib/every.d.cts +29 -0
- package/dist/cjs/lib/filter.cjs +21 -0
- package/dist/cjs/lib/filter.cjs.map +1 -0
- package/dist/cjs/lib/filter.d.cts +22 -0
- package/dist/cjs/lib/find.cjs +15 -0
- package/dist/cjs/lib/find.cjs.map +1 -0
- package/dist/cjs/lib/find.d.cts +26 -0
- package/dist/cjs/lib/findIndex.cjs +23 -0
- package/dist/cjs/lib/findIndex.cjs.map +1 -0
- package/dist/cjs/lib/findIndex.d.cts +25 -0
- package/dist/cjs/lib/first.cjs +14 -0
- package/dist/cjs/lib/first.cjs.map +1 -0
- package/dist/cjs/lib/first.d.cts +24 -0
- package/dist/cjs/lib/flat.cjs +16 -0
- package/dist/cjs/lib/flat.cjs.map +1 -0
- package/dist/cjs/lib/flat.d.cts +20 -0
- package/dist/cjs/lib/flatMap.cjs +19 -0
- package/dist/cjs/lib/flatMap.cjs.map +1 -0
- package/dist/cjs/lib/flatMap.d.cts +21 -0
- package/dist/cjs/lib/forEach.cjs +19 -0
- package/dist/cjs/lib/forEach.cjs.map +1 -0
- package/dist/cjs/lib/forEach.d.cts +24 -0
- package/dist/cjs/lib/from.cjs +25 -0
- package/dist/cjs/lib/from.cjs.map +1 -0
- package/dist/cjs/lib/from.d.cts +21 -0
- package/dist/cjs/lib/indexOf.cjs +22 -0
- package/dist/cjs/lib/indexOf.cjs.map +1 -0
- package/dist/cjs/lib/indexOf.d.cts +25 -0
- package/dist/cjs/lib/intersect.cjs +16 -0
- package/dist/cjs/lib/intersect.cjs.map +1 -0
- package/dist/cjs/lib/intersect.d.cts +26 -0
- package/dist/cjs/lib/isEmpty.cjs +14 -0
- package/dist/cjs/lib/isEmpty.cjs.map +1 -0
- package/dist/cjs/lib/isEmpty.d.cts +26 -0
- package/dist/cjs/lib/last.cjs +18 -0
- package/dist/cjs/lib/last.cjs.map +1 -0
- package/dist/cjs/lib/last.d.cts +24 -0
- package/dist/cjs/lib/map.cjs +19 -0
- package/dist/cjs/lib/map.cjs.map +1 -0
- package/dist/cjs/lib/map.d.cts +20 -0
- package/dist/cjs/lib/max.cjs +20 -0
- package/dist/cjs/lib/max.cjs.map +1 -0
- package/dist/cjs/lib/max.d.cts +25 -0
- package/dist/cjs/lib/min.cjs +20 -0
- package/dist/cjs/lib/min.cjs.map +1 -0
- package/dist/cjs/lib/min.d.cts +25 -0
- package/dist/cjs/lib/partition.cjs +26 -0
- package/dist/cjs/lib/partition.cjs.map +1 -0
- package/dist/cjs/lib/partition.d.cts +33 -0
- package/dist/cjs/lib/peekable.cjs +32 -0
- package/dist/cjs/lib/peekable.cjs.map +1 -0
- package/dist/cjs/lib/peekable.d.cts +35 -0
- package/dist/cjs/lib/prepend.cjs +17 -0
- package/dist/cjs/lib/prepend.cjs.map +1 -0
- package/dist/cjs/lib/prepend.d.cts +22 -0
- package/dist/cjs/lib/product.cjs +19 -0
- package/dist/cjs/lib/product.cjs.map +1 -0
- package/dist/cjs/lib/product.d.cts +24 -0
- package/dist/cjs/lib/range.cjs +37 -0
- package/dist/cjs/lib/range.cjs.map +1 -0
- package/dist/cjs/lib/range.d.cts +33 -0
- package/dist/cjs/lib/reduce.cjs +32 -0
- package/dist/cjs/lib/reduce.cjs.map +1 -0
- package/dist/cjs/lib/reduce.d.cts +33 -0
- package/dist/cjs/lib/repeat.cjs +20 -0
- package/dist/cjs/lib/repeat.cjs.map +1 -0
- package/dist/cjs/lib/repeat.d.cts +20 -0
- package/dist/cjs/lib/reverse.cjs +20 -0
- package/dist/cjs/lib/reverse.cjs.map +1 -0
- package/dist/cjs/lib/reverse.d.cts +26 -0
- package/dist/cjs/lib/shared/_assertFunction.cjs +17 -0
- package/dist/cjs/lib/shared/_assertFunction.cjs.map +1 -0
- package/dist/cjs/lib/shared/_assertFunction.d.cts +3 -0
- package/dist/cjs/lib/shared/_assertNotNegative.cjs +17 -0
- package/dist/cjs/lib/shared/_assertNotNegative.cjs.map +1 -0
- package/dist/cjs/lib/shared/_assertNotNegative.d.cts +3 -0
- package/dist/cjs/lib/shared/_assertPositive.cjs +17 -0
- package/dist/cjs/lib/shared/_assertPositive.cjs.map +1 -0
- package/dist/cjs/lib/shared/_assertPositive.d.cts +3 -0
- package/dist/cjs/lib/shared/_makeIterableIterator.cjs +19 -0
- package/dist/cjs/lib/shared/_makeIterableIterator.cjs.map +1 -0
- package/dist/cjs/lib/shared/_makeIterableIterator.d.cts +3 -0
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs +21 -0
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs.map +1 -0
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.d.cts +3 -0
- package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs +21 -0
- package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs.map +1 -0
- package/dist/cjs/lib/shared/_toIntegerOrThrow.d.cts +3 -0
- package/dist/cjs/lib/shared/_toNumberOrThrow.cjs +34 -0
- package/dist/cjs/lib/shared/_toNumberOrThrow.cjs.map +1 -0
- package/dist/cjs/lib/shared/_toNumberOrThrow.d.cts +8 -0
- package/dist/cjs/lib/slice.cjs +44 -0
- package/dist/cjs/lib/slice.cjs.map +1 -0
- package/dist/cjs/lib/slice.d.cts +62 -0
- package/dist/cjs/lib/some.cjs +22 -0
- package/dist/cjs/lib/some.cjs.map +1 -0
- package/dist/cjs/lib/some.d.cts +33 -0
- package/dist/cjs/lib/sorted.cjs +14 -0
- package/dist/cjs/lib/sorted.cjs.map +1 -0
- package/dist/cjs/lib/sorted.d.cts +25 -0
- package/dist/cjs/lib/starMap.cjs +19 -0
- package/dist/cjs/lib/starMap.cjs.map +1 -0
- package/dist/cjs/lib/starMap.d.cts +28 -0
- package/dist/cjs/lib/sum.cjs +19 -0
- package/dist/cjs/lib/sum.cjs.map +1 -0
- package/dist/cjs/lib/sum.d.cts +25 -0
- package/dist/cjs/lib/take.cjs +25 -0
- package/dist/cjs/lib/take.cjs.map +1 -0
- package/dist/cjs/lib/take.d.cts +21 -0
- package/dist/cjs/lib/takeLast.cjs +31 -0
- package/dist/cjs/lib/takeLast.cjs.map +1 -0
- package/dist/cjs/lib/takeLast.d.cts +25 -0
- package/dist/cjs/lib/tee.cjs +39 -0
- package/dist/cjs/lib/tee.cjs.map +1 -0
- package/dist/cjs/lib/tee.d.cts +25 -0
- package/dist/cjs/lib/toArray.cjs +14 -0
- package/dist/cjs/lib/toArray.cjs.map +1 -0
- package/dist/cjs/lib/toArray.d.cts +36 -0
- package/dist/cjs/lib/toIterableIterator.cjs +19 -0
- package/dist/cjs/lib/toIterableIterator.cjs.map +1 -0
- package/dist/cjs/lib/toIterableIterator.d.cts +32 -0
- package/dist/cjs/lib/union.cjs +22 -0
- package/dist/cjs/lib/union.cjs.map +1 -0
- package/dist/cjs/lib/union.d.cts +20 -0
- package/dist/cjs/lib/unique.cjs +14 -0
- package/dist/cjs/lib/unique.cjs.map +1 -0
- package/dist/cjs/lib/unique.d.cts +20 -0
- package/dist/cjs/lib/unzip.cjs +37 -0
- package/dist/cjs/lib/unzip.cjs.map +1 -0
- package/dist/cjs/lib/unzip.d.cts +32 -0
- package/dist/cjs/lib/zip.cjs +24 -0
- package/dist/cjs/lib/zip.cjs.map +1 -0
- package/dist/cjs/lib/zip.d.cts +30 -0
- package/dist/esm/chunk-G5GHKT7C.mjs +6 -0
- package/dist/esm/chunk-G5GHKT7C.mjs.map +1 -0
- package/dist/esm/index.d.mts +55 -0
- package/dist/esm/index.mjs +56 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/lib/append.d.mts +21 -0
- package/dist/esm/lib/append.mjs +11 -0
- package/dist/esm/lib/append.mjs.map +1 -0
- package/dist/esm/lib/at.d.mts +25 -0
- package/dist/esm/lib/at.mjs +15 -0
- package/dist/esm/lib/at.mjs.map +1 -0
- package/dist/esm/lib/average.d.mts +25 -0
- package/dist/esm/lib/average.mjs +18 -0
- package/dist/esm/lib/average.mjs.map +1 -0
- package/dist/esm/lib/chain.d.mts +20 -0
- package/dist/esm/lib/chain.mjs +13 -0
- package/dist/esm/lib/chain.mjs.map +1 -0
- package/dist/esm/lib/chunk.d.mts +20 -0
- package/dist/esm/lib/chunk.mjs +24 -0
- package/dist/esm/lib/chunk.mjs.map +1 -0
- package/dist/esm/lib/compact.d.mts +19 -0
- package/dist/esm/lib/compact.mjs +11 -0
- package/dist/esm/lib/compact.mjs.map +1 -0
- package/dist/esm/lib/compress.d.mts +26 -0
- package/dist/esm/lib/compress.mjs +21 -0
- package/dist/esm/lib/compress.mjs.map +1 -0
- package/dist/esm/lib/contains.d.mts +25 -0
- package/dist/esm/lib/contains.mjs +15 -0
- package/dist/esm/lib/contains.mjs.map +1 -0
- package/dist/esm/lib/count.d.mts +24 -0
- package/dist/esm/lib/count.mjs +16 -0
- package/dist/esm/lib/count.mjs.map +1 -0
- package/dist/esm/lib/cycle.d.mts +21 -0
- package/dist/esm/lib/cycle.mjs +20 -0
- package/dist/esm/lib/cycle.mjs.map +1 -0
- package/dist/esm/lib/difference.d.mts +25 -0
- package/dist/esm/lib/difference.mjs +13 -0
- package/dist/esm/lib/difference.mjs.map +1 -0
- package/dist/esm/lib/drop.d.mts +21 -0
- package/dist/esm/lib/drop.mjs +24 -0
- package/dist/esm/lib/drop.mjs.map +1 -0
- package/dist/esm/lib/dropLast.d.mts +25 -0
- package/dist/esm/lib/dropLast.mjs +19 -0
- package/dist/esm/lib/dropLast.mjs.map +1 -0
- package/dist/esm/lib/dropWhile.d.mts +24 -0
- package/dist/esm/lib/dropWhile.mjs +18 -0
- package/dist/esm/lib/dropWhile.mjs.map +1 -0
- package/dist/esm/lib/empty.d.mts +17 -0
- package/dist/esm/lib/empty.mjs +11 -0
- package/dist/esm/lib/empty.mjs.map +1 -0
- package/dist/esm/lib/enumerate.d.mts +24 -0
- package/dist/esm/lib/enumerate.mjs +14 -0
- package/dist/esm/lib/enumerate.mjs.map +1 -0
- package/dist/esm/lib/every.d.mts +29 -0
- package/dist/esm/lib/every.mjs +18 -0
- package/dist/esm/lib/every.mjs.map +1 -0
- package/dist/esm/lib/filter.d.mts +22 -0
- package/dist/esm/lib/filter.mjs +17 -0
- package/dist/esm/lib/filter.mjs.map +1 -0
- package/dist/esm/lib/find.d.mts +26 -0
- package/dist/esm/lib/find.mjs +12 -0
- package/dist/esm/lib/find.mjs.map +1 -0
- package/dist/esm/lib/findIndex.d.mts +25 -0
- package/dist/esm/lib/findIndex.mjs +20 -0
- package/dist/esm/lib/findIndex.mjs.map +1 -0
- package/dist/esm/lib/first.d.mts +24 -0
- package/dist/esm/lib/first.mjs +11 -0
- package/dist/esm/lib/first.mjs.map +1 -0
- package/dist/esm/lib/flat.d.mts +20 -0
- package/dist/esm/lib/flat.mjs +13 -0
- package/dist/esm/lib/flat.mjs.map +1 -0
- package/dist/esm/lib/flatMap.d.mts +21 -0
- package/dist/esm/lib/flatMap.mjs +16 -0
- package/dist/esm/lib/flatMap.mjs.map +1 -0
- package/dist/esm/lib/forEach.d.mts +24 -0
- package/dist/esm/lib/forEach.mjs +16 -0
- package/dist/esm/lib/forEach.mjs.map +1 -0
- package/dist/esm/lib/from.d.mts +21 -0
- package/dist/esm/lib/from.mjs +22 -0
- package/dist/esm/lib/from.mjs.map +1 -0
- package/dist/esm/lib/indexOf.d.mts +25 -0
- package/dist/esm/lib/indexOf.mjs +18 -0
- package/dist/esm/lib/indexOf.mjs.map +1 -0
- package/dist/esm/lib/intersect.d.mts +26 -0
- package/dist/esm/lib/intersect.mjs +13 -0
- package/dist/esm/lib/intersect.mjs.map +1 -0
- package/dist/esm/lib/isEmpty.d.mts +26 -0
- package/dist/esm/lib/isEmpty.mjs +11 -0
- package/dist/esm/lib/isEmpty.mjs.map +1 -0
- package/dist/esm/lib/last.d.mts +24 -0
- package/dist/esm/lib/last.mjs +15 -0
- package/dist/esm/lib/last.mjs.map +1 -0
- package/dist/esm/lib/map.d.mts +20 -0
- package/dist/esm/lib/map.mjs +16 -0
- package/dist/esm/lib/map.mjs.map +1 -0
- package/dist/esm/lib/max.d.mts +25 -0
- package/dist/esm/lib/max.mjs +17 -0
- package/dist/esm/lib/max.mjs.map +1 -0
- package/dist/esm/lib/min.d.mts +25 -0
- package/dist/esm/lib/min.mjs +17 -0
- package/dist/esm/lib/min.mjs.map +1 -0
- package/dist/esm/lib/partition.d.mts +33 -0
- package/dist/esm/lib/partition.mjs +23 -0
- package/dist/esm/lib/partition.mjs.map +1 -0
- package/dist/esm/lib/peekable.d.mts +35 -0
- package/dist/esm/lib/peekable.mjs +29 -0
- package/dist/esm/lib/peekable.mjs.map +1 -0
- package/dist/esm/lib/prepend.d.mts +22 -0
- package/dist/esm/lib/prepend.mjs +14 -0
- package/dist/esm/lib/prepend.mjs.map +1 -0
- package/dist/esm/lib/product.d.mts +24 -0
- package/dist/esm/lib/product.mjs +16 -0
- package/dist/esm/lib/product.mjs.map +1 -0
- package/dist/esm/lib/range.d.mts +33 -0
- package/dist/esm/lib/range.mjs +34 -0
- package/dist/esm/lib/range.mjs.map +1 -0
- package/dist/esm/lib/reduce.d.mts +33 -0
- package/dist/esm/lib/reduce.mjs +29 -0
- package/dist/esm/lib/reduce.mjs.map +1 -0
- package/dist/esm/lib/repeat.d.mts +20 -0
- package/dist/esm/lib/repeat.mjs +17 -0
- package/dist/esm/lib/repeat.mjs.map +1 -0
- package/dist/esm/lib/reverse.d.mts +26 -0
- package/dist/esm/lib/reverse.mjs +17 -0
- package/dist/esm/lib/reverse.mjs.map +1 -0
- package/dist/esm/lib/shared/_assertFunction.d.mts +3 -0
- package/dist/esm/lib/shared/_assertFunction.mjs +14 -0
- package/dist/esm/lib/shared/_assertFunction.mjs.map +1 -0
- package/dist/esm/lib/shared/_assertNotNegative.d.mts +3 -0
- package/dist/esm/lib/shared/_assertNotNegative.mjs +14 -0
- package/dist/esm/lib/shared/_assertNotNegative.mjs.map +1 -0
- package/dist/esm/lib/shared/_assertPositive.d.mts +3 -0
- package/dist/esm/lib/shared/_assertPositive.mjs +14 -0
- package/dist/esm/lib/shared/_assertPositive.mjs.map +1 -0
- package/dist/esm/lib/shared/_makeIterableIterator.d.mts +3 -0
- package/dist/esm/lib/shared/_makeIterableIterator.mjs +16 -0
- package/dist/esm/lib/shared/_makeIterableIterator.mjs.map +1 -0
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.d.mts +3 -0
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs +18 -0
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs.map +1 -0
- package/dist/esm/lib/shared/_toIntegerOrThrow.d.mts +3 -0
- package/dist/esm/lib/shared/_toIntegerOrThrow.mjs +18 -0
- package/dist/esm/lib/shared/_toIntegerOrThrow.mjs.map +1 -0
- package/dist/esm/lib/shared/_toNumberOrThrow.d.mts +8 -0
- package/dist/esm/lib/shared/_toNumberOrThrow.mjs +31 -0
- package/dist/esm/lib/shared/_toNumberOrThrow.mjs.map +1 -0
- package/dist/esm/lib/slice.d.mts +62 -0
- package/dist/esm/lib/slice.mjs +41 -0
- package/dist/esm/lib/slice.mjs.map +1 -0
- package/dist/esm/lib/some.d.mts +33 -0
- package/dist/esm/lib/some.mjs +19 -0
- package/dist/esm/lib/some.mjs.map +1 -0
- package/dist/esm/lib/sorted.d.mts +25 -0
- package/dist/esm/lib/sorted.mjs +11 -0
- package/dist/esm/lib/sorted.mjs.map +1 -0
- package/dist/esm/lib/starMap.d.mts +28 -0
- package/dist/esm/lib/starMap.mjs +16 -0
- package/dist/esm/lib/starMap.mjs.map +1 -0
- package/dist/esm/lib/sum.d.mts +25 -0
- package/dist/esm/lib/sum.mjs +16 -0
- package/dist/esm/lib/sum.mjs.map +1 -0
- package/dist/esm/lib/take.d.mts +21 -0
- package/dist/esm/lib/take.mjs +22 -0
- package/dist/esm/lib/take.mjs.map +1 -0
- package/dist/esm/lib/takeLast.d.mts +25 -0
- package/dist/esm/lib/takeLast.mjs +28 -0
- package/dist/esm/lib/takeLast.mjs.map +1 -0
- package/dist/esm/lib/tee.d.mts +25 -0
- package/dist/esm/lib/tee.mjs +36 -0
- package/dist/esm/lib/tee.mjs.map +1 -0
- package/dist/esm/lib/toArray.d.mts +36 -0
- package/dist/esm/lib/toArray.mjs +11 -0
- package/dist/esm/lib/toArray.mjs.map +1 -0
- package/dist/esm/lib/toIterableIterator.d.mts +32 -0
- package/dist/esm/lib/toIterableIterator.mjs +16 -0
- package/dist/esm/lib/toIterableIterator.mjs.map +1 -0
- package/dist/esm/lib/union.d.mts +20 -0
- package/dist/esm/lib/union.mjs +19 -0
- package/dist/esm/lib/union.mjs.map +1 -0
- package/dist/esm/lib/unique.d.mts +20 -0
- package/dist/esm/lib/unique.mjs +11 -0
- package/dist/esm/lib/unique.mjs.map +1 -0
- package/dist/esm/lib/unzip.d.mts +32 -0
- package/dist/esm/lib/unzip.mjs +34 -0
- package/dist/esm/lib/unzip.mjs.map +1 -0
- package/dist/esm/lib/zip.d.mts +30 -0
- package/dist/esm/lib/zip.mjs +21 -0
- package/dist/esm/lib/zip.mjs.map +1 -0
- package/dist/iife/index.global.js +834 -0
- package/dist/iife/index.global.js.map +1 -0
- package/package.json +692 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterable with the elements that are in both input iterables.
|
|
5
|
+
*
|
|
6
|
+
* @param first An iterator to return elements from.
|
|
7
|
+
* @param second An iterator that contains elements to include in the result.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { intersect } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* const iterable = intersect([1, 2, 3, 4, 5], [3, 4, 5, 6, 7]);
|
|
14
|
+
* console.log([...iterable]);
|
|
15
|
+
* // Output: [3, 4, 5]
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
*
|
|
20
|
+
* This function consumes the entire `second` iterator to build the set of elements to intersect with `first`.
|
|
21
|
+
*
|
|
22
|
+
* @seealso {@link difference} for the opposite behavior.
|
|
23
|
+
*/
|
|
24
|
+
declare function intersect<const ElementType>(first: IterableResolvable<ElementType>, second: IterableResolvable<ElementType>): IterableIterator<ElementType>;
|
|
25
|
+
|
|
26
|
+
export { intersect };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { filter } from './filter.mjs';
|
|
3
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
4
|
+
|
|
5
|
+
function intersect(first, second) {
|
|
6
|
+
const set = new Set(toIterableIterator(second));
|
|
7
|
+
return filter(first, (value) => set.has(value));
|
|
8
|
+
}
|
|
9
|
+
__name(intersect, "intersect");
|
|
10
|
+
|
|
11
|
+
export { intersect };
|
|
12
|
+
//# sourceMappingURL=out.js.map
|
|
13
|
+
//# sourceMappingURL=intersect.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/intersect.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,cAAc;AAEvB,SAAS,0BAA0B;AAuB5B,SAAS,UACf,OACA,QACgC;AAChC,QAAM,MAAM,IAAI,IAAI,mBAAmB,MAAM,CAAC;AAC9C,SAAO,OAAO,OAAO,CAAC,UAAU,IAAI,IAAI,KAAK,CAAC;AAC/C;AANgB","sourcesContent":["import { filter } from './filter';\nimport type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterable with the elements that are in both input iterables.\n *\n * @param first An iterator to return elements from.\n * @param second An iterator that contains elements to include in the result.\n *\n * @example\n * ```typescript\n * import { intersect } from '@sapphire/iterator-utilities';\n *\n * const iterable = intersect([1, 2, 3, 4, 5], [3, 4, 5, 6, 7]);\n * console.log([...iterable]);\n * // Output: [3, 4, 5]\n * ```\n *\n * @remarks\n *\n * This function consumes the entire `second` iterator to build the set of elements to intersect with `first`.\n *\n * @seealso {@link difference} for the opposite behavior.\n */\nexport function intersect<const ElementType>(\n\tfirst: IterableResolvable<ElementType>,\n\tsecond: IterableResolvable<ElementType>\n): IterableIterator<ElementType> {\n\tconst set = new Set(toIterableIterator(second));\n\treturn filter(first, (value) => set.has(value));\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Advances the iterable once, returning `true` if it's exhausted and `false` otherwise.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable The iterator to check for emptiness.
|
|
7
|
+
* @returns `true` if the iterator is empty; otherwise, `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { isEmpty } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* console.log(isEmpty([]));
|
|
14
|
+
* // Output: true
|
|
15
|
+
*
|
|
16
|
+
* console.log(isEmpty([1, 2, 3, 4, 5]));
|
|
17
|
+
* // Output: false
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
*
|
|
22
|
+
* This function consumes the first value of the iterator.
|
|
23
|
+
*/
|
|
24
|
+
declare function isEmpty<const ElementType>(iterable: IterableResolvable<ElementType>): boolean;
|
|
25
|
+
|
|
26
|
+
export { isEmpty };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { from } from './from.mjs';
|
|
3
|
+
|
|
4
|
+
function isEmpty(iterable) {
|
|
5
|
+
return from(iterable).next().done ?? false;
|
|
6
|
+
}
|
|
7
|
+
__name(isEmpty, "isEmpty");
|
|
8
|
+
|
|
9
|
+
export { isEmpty };
|
|
10
|
+
//# sourceMappingURL=out.js.map
|
|
11
|
+
//# sourceMappingURL=isEmpty.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/isEmpty.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAAqC;AAuBvC,SAAS,QAA2B,UAAoD;AAC9F,SAAO,KAAK,QAAQ,EAAE,KAAK,EAAE,QAAQ;AACtC;AAFgB","sourcesContent":["import { from, type IterableResolvable } from './from';\n\n/**\n * Advances the iterable once, returning `true` if it's exhausted and `false` otherwise.\n *\n * @param iterable The iterator to check for emptiness.\n * @returns `true` if the iterator is empty; otherwise, `false`.\n *\n * @example\n * ```typescript\n * import { isEmpty } from '@sapphire/iterator-utilities';\n *\n * console.log(isEmpty([]));\n * // Output: true\n *\n * console.log(isEmpty([1, 2, 3, 4, 5]));\n * // Output: false\n * ```\n *\n * @remarks\n *\n * This function consumes the first value of the iterator.\n */\nexport function isEmpty<const ElementType>(iterable: IterableResolvable<ElementType>): boolean {\n\treturn from(iterable).next().done ?? false;\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable until it's exhausted, returning the last element.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to return the last value of.
|
|
7
|
+
* @returns The value at the last position in the source iterator, or `undefined` if the iterator is empty.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { last } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
14
|
+
* console.log(last(iterable));
|
|
15
|
+
* // Output: 5
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
*
|
|
20
|
+
* This function consumes the entire iterator to find the last value.
|
|
21
|
+
*/
|
|
22
|
+
declare function last<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | undefined;
|
|
23
|
+
|
|
24
|
+
export { last };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
3
|
+
|
|
4
|
+
function last(iterable) {
|
|
5
|
+
let last2;
|
|
6
|
+
for (const value of toIterableIterator(iterable)) {
|
|
7
|
+
last2 = value;
|
|
8
|
+
}
|
|
9
|
+
return last2;
|
|
10
|
+
}
|
|
11
|
+
__name(last, "last");
|
|
12
|
+
|
|
13
|
+
export { last };
|
|
14
|
+
//# sourceMappingURL=out.js.map
|
|
15
|
+
//# sourceMappingURL=last.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/last.ts"],"names":["last"],"mappings":";;;;;AACA,SAAS,0BAA0B;AAqB5B,SAAS,KAAwB,UAAoE;AAC3G,MAAIA;AACJ,aAAW,SAAS,mBAAmB,QAAQ,GAAG;AACjD,IAAAA,QAAO;AAAA,EACR;AAEA,SAAOA;AACR;AAPgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable until it's exhausted, returning the last element.\n *\n * @param iterable An iterator to return the last value of.\n * @returns The value at the last position in the source iterator, or `undefined` if the iterator is empty.\n *\n * @example\n * ```typescript\n * import { last } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(last(iterable));\n * // Output: 5\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator to find the last value.\n */\nexport function last<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | undefined {\n\tlet last: ElementType | undefined;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tlast = value;\n\t}\n\n\treturn last;\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterable with the results of calling a provided function on each element.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to map over.
|
|
7
|
+
* @param callbackFn A function to execute for each element produced by the iterator. Its return value is yielded by the iterator helper.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { map } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
14
|
+
* console.log([...map(iterable, (value) => value * 2)]);
|
|
15
|
+
* // Output: [2, 4, 6, 8, 10]
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function map<const ElementType, const MappedType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => MappedType): IterableIterator<MappedType>;
|
|
19
|
+
|
|
20
|
+
export { map };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { assertFunction } from './shared/_assertFunction.mjs';
|
|
3
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
4
|
+
|
|
5
|
+
function* map(iterable, callbackFn) {
|
|
6
|
+
callbackFn = assertFunction(callbackFn);
|
|
7
|
+
let index = 0;
|
|
8
|
+
for (const element of toIterableIterator(iterable)) {
|
|
9
|
+
yield callbackFn(element, index++);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
__name(map, "map");
|
|
13
|
+
|
|
14
|
+
export { map };
|
|
15
|
+
//# sourceMappingURL=out.js.map
|
|
16
|
+
//# sourceMappingURL=map.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/map.ts"],"names":[],"mappings":";;;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AAiB5B,UAAU,IAChB,UACA,YAC+B;AAC/B,eAAa,eAAe,UAAU;AAEtC,MAAI,QAAQ;AACZ,aAAW,WAAW,mBAAmB,QAAQ,GAAG;AACnD,UAAM,WAAW,SAAS,OAAO;AAAA,EAClC;AACD;AAViB","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.\n *\n * @param iterable An iterator to map over.\n * @param callbackFn A function to execute for each element produced by the iterator. Its return value is yielded by the iterator helper.\n *\n * @example\n * ```typescript\n * import { map } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...map(iterable, (value) => value * 2)]);\n * // Output: [2, 4, 6, 8, 10]\n * ```\n */\nexport function* map<const ElementType, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => MappedType\n): IterableIterator<MappedType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const element of toIterableIterator(iterable)) {\n\t\tyield callbackFn(element, index++);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
import { NumberResolvable } from './shared/_toNumberOrThrow.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Consumes the iterable and returns the highest number element. If the iterable is empty, or contains only non-number values, it returns `null`.
|
|
6
|
+
*
|
|
7
|
+
* @param iterable An iterator of number values to determine the maximum value of.
|
|
8
|
+
* @returns The maximum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { max } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
15
|
+
* console.log(max(iterable));
|
|
16
|
+
* // Output: 5
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
*
|
|
21
|
+
* This function consumes the entire iterator.
|
|
22
|
+
*/
|
|
23
|
+
declare function max(iterable: IterableResolvable<NumberResolvable>): number | null;
|
|
24
|
+
|
|
25
|
+
export { max };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { map } from './map.mjs';
|
|
3
|
+
import { toNumberOrThrow } from './shared/_toNumberOrThrow.mjs';
|
|
4
|
+
|
|
5
|
+
function max(iterable) {
|
|
6
|
+
let max2 = null;
|
|
7
|
+
for (const value of map(iterable, toNumberOrThrow)) {
|
|
8
|
+
if (max2 === null || value > max2)
|
|
9
|
+
max2 = value;
|
|
10
|
+
}
|
|
11
|
+
return max2;
|
|
12
|
+
}
|
|
13
|
+
__name(max, "max");
|
|
14
|
+
|
|
15
|
+
export { max };
|
|
16
|
+
//# sourceMappingURL=out.js.map
|
|
17
|
+
//# sourceMappingURL=max.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/max.ts"],"names":["max"],"mappings":";;;;;AACA,SAAS,WAAW;AACpB,SAAS,uBAA8C;AAqBhD,SAAS,IAAI,UAA+D;AAClF,MAAIA,OAAqB;AACzB,aAAW,SAAS,IAAI,UAAU,eAAe,GAAG;AACnD,QAAIA,SAAQ,QAAQ,QAAQA;AAAK,MAAAA,OAAM;AAAA,EACxC;AAEA,SAAOA;AACR;AAPgB","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 highest number element. If the iterable is empty, or contains only non-number values, it returns `null`.\n *\n * @param iterable An iterator of number values to determine the maximum value of.\n * @returns The maximum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.\n *\n * @example\n * ```typescript\n * import { max } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(max(iterable));\n * // Output: 5\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function max(iterable: IterableResolvable<NumberResolvable>): number | null {\n\tlet max: number | null = null;\n\tfor (const value of map(iterable, toNumberOrThrow)) {\n\t\tif (max === null || value > max) max = value;\n\t}\n\n\treturn max;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
import { NumberResolvable } from './shared/_toNumberOrThrow.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Consumes the iterable and returns the lowest number element. If the iterable is empty, or contains only non-number values, it returns `null`.
|
|
6
|
+
*
|
|
7
|
+
* @param iterable An iterator of number values to determine the minimum value of.
|
|
8
|
+
* @returns The minimum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { min } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
15
|
+
* console.log(min(iterable));
|
|
16
|
+
* // Output: 1
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
*
|
|
21
|
+
* This function consumes the entire iterator.
|
|
22
|
+
*/
|
|
23
|
+
declare function min(iterable: IterableResolvable<NumberResolvable>): number | null;
|
|
24
|
+
|
|
25
|
+
export { min };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { map } from './map.mjs';
|
|
3
|
+
import { toNumberOrThrow } from './shared/_toNumberOrThrow.mjs';
|
|
4
|
+
|
|
5
|
+
function min(iterable) {
|
|
6
|
+
let min2 = null;
|
|
7
|
+
for (const value of map(iterable, toNumberOrThrow)) {
|
|
8
|
+
if (min2 === null || value < min2)
|
|
9
|
+
min2 = value;
|
|
10
|
+
}
|
|
11
|
+
return min2;
|
|
12
|
+
}
|
|
13
|
+
__name(min, "min");
|
|
14
|
+
|
|
15
|
+
export { min };
|
|
16
|
+
//# sourceMappingURL=out.js.map
|
|
17
|
+
//# sourceMappingURL=min.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/min.ts"],"names":["min"],"mappings":";;;;;AACA,SAAS,WAAW;AACpB,SAAS,uBAA8C;AAqBhD,SAAS,IAAI,UAA+D;AAClF,MAAIA,OAAqB;AACzB,aAAW,SAAS,IAAI,UAAU,eAAe,GAAG;AACnD,QAAIA,SAAQ,QAAQ,QAAQA;AAAK,MAAAA,OAAM;AAAA,EACxC;AAEA,SAAOA;AACR;AAPgB","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 lowest number element. If the iterable is empty, or contains only non-number values, it returns `null`.\n *\n * @param iterable An iterator of number values to determine the minimum value of.\n * @returns The minimum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.\n *\n * @example\n * ```typescript\n * import { min } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(min(iterable));\n * // Output: 1\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function min(iterable: IterableResolvable<NumberResolvable>): number | null {\n\tlet min: number | null = null;\n\tfor (const value of map(iterable, toNumberOrThrow)) {\n\t\tif (min === null || value < min) min = value;\n\t}\n\n\treturn min;\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable and creates two arrays, one with the elements that pass the test and another with the elements that don't.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to partition.
|
|
7
|
+
* @param predicate A function that determines which partition an element belongs to.
|
|
8
|
+
* @returns An array containing two iterators. The first iterator contains elements that satisfy the predicate, and the
|
|
9
|
+
* second iterator contains elements that do not.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { partition } from '@sapphire/iterator-utilities';
|
|
14
|
+
*
|
|
15
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
16
|
+
* const [even, odd] = partition(iterable, (value) => value % 2 === 0);
|
|
17
|
+
*
|
|
18
|
+
* console.log(even);
|
|
19
|
+
* // Output: [2, 4]
|
|
20
|
+
*
|
|
21
|
+
* console.log(odd);
|
|
22
|
+
* // Output: [1, 3, 5]
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
*
|
|
27
|
+
* This function collects all elements of the provided iterator into two arrays based on the predicate before returning
|
|
28
|
+
* them, which may not be desirable for large iterators.
|
|
29
|
+
*/
|
|
30
|
+
declare function partition<const ElementType, const FilteredType extends ElementType>(iterable: IterableResolvable<ElementType>, predicate: (value: ElementType, index: number) => value is FilteredType): [FilteredType[], Exclude<ElementType, FilteredType>[]];
|
|
31
|
+
declare function partition<const ElementType>(iterable: IterableResolvable<ElementType>, predicate: (value: ElementType, index: number) => boolean): [ElementType[], ElementType[]];
|
|
32
|
+
|
|
33
|
+
export { partition };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { assertFunction } from './shared/_assertFunction.mjs';
|
|
3
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
4
|
+
|
|
5
|
+
function partition(iterable, predicate) {
|
|
6
|
+
predicate = assertFunction(predicate);
|
|
7
|
+
const bufferLeft = [];
|
|
8
|
+
const bufferRight = [];
|
|
9
|
+
let index = 0;
|
|
10
|
+
for (const value of toIterableIterator(iterable)) {
|
|
11
|
+
if (predicate(value, index++)) {
|
|
12
|
+
bufferLeft.push(value);
|
|
13
|
+
} else {
|
|
14
|
+
bufferRight.push(value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return [bufferLeft, bufferRight];
|
|
18
|
+
}
|
|
19
|
+
__name(partition, "partition");
|
|
20
|
+
|
|
21
|
+
export { partition };
|
|
22
|
+
//# sourceMappingURL=out.js.map
|
|
23
|
+
//# sourceMappingURL=partition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/partition.ts"],"names":[],"mappings":";;;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AAsC5B,SAAS,UACf,UACA,WACiC;AACjC,cAAY,eAAe,SAAS;AAEpC,QAAM,aAA4B,CAAC;AACnC,QAAM,cAA6B,CAAC;AAEpC,MAAI,QAAQ;AACZ,aAAW,SAAS,mBAAmB,QAAQ,GAAG;AACjD,QAAI,UAAU,OAAO,OAAO,GAAG;AAC9B,iBAAW,KAAK,KAAK;AAAA,IACtB,OAAO;AACN,kBAAY,KAAK,KAAK;AAAA,IACvB;AAAA,EACD;AAEA,SAAO,CAAC,YAAY,WAAW;AAChC;AAnBgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable and creates two arrays, one with the elements that pass the test and another with the elements that don't.\n *\n * @param iterable An iterator to partition.\n * @param predicate A function that determines which partition an element belongs to.\n * @returns An array containing two iterators. The first iterator contains elements that satisfy the predicate, and the\n * second iterator contains elements that do not.\n *\n * @example\n * ```typescript\n * import { partition } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * const [even, odd] = partition(iterable, (value) => value % 2 === 0);\n *\n * console.log(even);\n * // Output: [2, 4]\n *\n * console.log(odd);\n * // Output: [1, 3, 5]\n * ```\n *\n * @remarks\n *\n * This function collects all elements of the provided iterator into two arrays based on the predicate before returning\n * them, which may not be desirable for large iterators.\n */\nexport function partition<const ElementType, const FilteredType extends ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tpredicate: (value: ElementType, index: number) => value is FilteredType\n): [FilteredType[], Exclude<ElementType, FilteredType>[]];\nexport function partition<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tpredicate: (value: ElementType, index: number) => boolean\n): [ElementType[], ElementType[]];\n\nexport function partition<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tpredicate: (value: ElementType, index: number) => boolean\n): [ElementType[], ElementType[]] {\n\tpredicate = assertFunction(predicate);\n\n\tconst bufferLeft: ElementType[] = [];\n\tconst bufferRight: ElementType[] = [];\n\n\tlet index = 0;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tif (predicate(value, index++)) {\n\t\t\tbufferLeft.push(value);\n\t\t} else {\n\t\t\tbufferRight.push(value);\n\t\t}\n\t}\n\n\treturn [bufferLeft, bufferRight];\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterator that allows you to peek at the next element without advancing the iterator.
|
|
5
|
+
*
|
|
6
|
+
* @template ElementType The type of elements in the iterable.
|
|
7
|
+
* @param iterable The iterable to create a peekable iterator from.
|
|
8
|
+
* @returns A new peekable iterator.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { peekable } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
15
|
+
* const peekableIterator = peekable(iterable);
|
|
16
|
+
*
|
|
17
|
+
* console.log(peekableIterator.next());
|
|
18
|
+
* // Output: { value: 1, done: false }
|
|
19
|
+
*
|
|
20
|
+
* console.log(peekableIterator.peek());
|
|
21
|
+
* // Output: { value: 2, done: false }
|
|
22
|
+
*
|
|
23
|
+
* console.log(peekableIterator.next());
|
|
24
|
+
* // Output: { value: 2, done: false }
|
|
25
|
+
*
|
|
26
|
+
* console.log(peekableIterator.next());
|
|
27
|
+
* // Output: { value: 3, done: false }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function peekable<const ElementType>(iterable: IterableResolvable<ElementType>): Peekable<ElementType>;
|
|
31
|
+
interface Peekable<T> extends IterableIterator<T> {
|
|
32
|
+
peek(): IteratorResult<T> | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { type Peekable, peekable };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { from } from './from.mjs';
|
|
3
|
+
|
|
4
|
+
function peekable(iterable) {
|
|
5
|
+
const resolvedIterable = from(iterable);
|
|
6
|
+
let peeked;
|
|
7
|
+
return {
|
|
8
|
+
next() {
|
|
9
|
+
if (peeked) {
|
|
10
|
+
const value = peeked;
|
|
11
|
+
peeked = void 0;
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
return resolvedIterable.next();
|
|
15
|
+
},
|
|
16
|
+
peek() {
|
|
17
|
+
peeked = peeked ?? resolvedIterable.next();
|
|
18
|
+
return peeked;
|
|
19
|
+
},
|
|
20
|
+
[Symbol.iterator]() {
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
__name(peekable, "peekable");
|
|
26
|
+
|
|
27
|
+
export { peekable };
|
|
28
|
+
//# sourceMappingURL=out.js.map
|
|
29
|
+
//# sourceMappingURL=peekable.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/peekable.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAAqC;AA6BvC,SAAS,SAA4B,UAAkE;AAC7G,QAAM,mBAAmB,KAAK,QAAQ;AACtC,MAAI;AACJ,SAAO;AAAA,IACN,OAAO;AACN,UAAI,QAAQ;AACX,cAAM,QAAQ;AACd,iBAAS;AACT,eAAO;AAAA,MACR;AAEA,aAAO,iBAAiB,KAAK;AAAA,IAC9B;AAAA,IACA,OAAO;AACN,eAAS,UAAU,iBAAiB,KAAK;AACzC,aAAO;AAAA,IACR;AAAA,IACA,CAAC,OAAO,QAAQ,IAAI;AACnB,aAAO;AAAA,IACR;AAAA,EACD;AACD;AArBgB","sourcesContent":["import { from, type IterableResolvable } from './from';\n\n/**\n * Creates an iterator that allows you to peek at the next element without advancing the iterator.\n *\n * @template ElementType The type of elements in the iterable.\n * @param iterable The iterable to create a peekable iterator from.\n * @returns A new peekable iterator.\n *\n * @example\n * ```typescript\n * import { peekable } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * const peekableIterator = peekable(iterable);\n *\n * console.log(peekableIterator.next());\n * // Output: { value: 1, done: false }\n *\n * console.log(peekableIterator.peek());\n * // Output: { value: 2, done: false }\n *\n * console.log(peekableIterator.next());\n * // Output: { value: 2, done: false }\n *\n * console.log(peekableIterator.next());\n * // Output: { value: 3, done: false }\n * ```\n */\nexport function peekable<const ElementType>(iterable: IterableResolvable<ElementType>): Peekable<ElementType> {\n\tconst resolvedIterable = from(iterable);\n\tlet peeked: IteratorResult<ElementType> | undefined;\n\treturn {\n\t\tnext() {\n\t\t\tif (peeked) {\n\t\t\t\tconst value = peeked;\n\t\t\t\tpeeked = undefined;\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\treturn resolvedIterable.next();\n\t\t},\n\t\tpeek() {\n\t\t\tpeeked = peeked ?? resolvedIterable.next();\n\t\t\treturn peeked;\n\t\t},\n\t\t[Symbol.iterator]() {\n\t\t\treturn this as IterableIterator<ElementType>;\n\t\t}\n\t};\n}\n\nexport interface Peekable<T> extends IterableIterator<T> {\n\tpeek(): IteratorResult<T> | undefined;\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterator with the provided iterables prepended to the first iterable.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable The iterator to prepend values to.
|
|
7
|
+
* @param iterables The iterables to prepend to the iterator.
|
|
8
|
+
* @returns An iterator that yields the values of the provided iterator followed by the values of the provided iterables.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { prepend } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* console.log([...prepend([3, 4, 5], [1, 2])]);
|
|
15
|
+
* // Output: [1, 2, 3, 4, 5]
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @seealso {@link append} to append values to the end of an iterator.
|
|
19
|
+
*/
|
|
20
|
+
declare function prepend<const ElementType>(iterable: IterableResolvable<ElementType>, ...iterables: IterableResolvable<ElementType>[]): IterableIterator<ElementType>;
|
|
21
|
+
|
|
22
|
+
export { prepend };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
3
|
+
|
|
4
|
+
function* prepend(iterable, ...iterables) {
|
|
5
|
+
for (const iterable2 of iterables) {
|
|
6
|
+
yield* toIterableIterator(iterable2);
|
|
7
|
+
}
|
|
8
|
+
yield* toIterableIterator(iterable);
|
|
9
|
+
}
|
|
10
|
+
__name(prepend, "prepend");
|
|
11
|
+
|
|
12
|
+
export { prepend };
|
|
13
|
+
//# sourceMappingURL=out.js.map
|
|
14
|
+
//# sourceMappingURL=prepend.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/prepend.ts"],"names":["iterable"],"mappings":";;;;;AACA,SAAS,0BAA0B;AAmB5B,UAAU,QAChB,aACG,WAC6B;AAChC,aAAWA,aAAY,WAAW;AACjC,WAAO,mBAAmBA,SAAQ;AAAA,EACnC;AAEA,SAAO,mBAAmB,QAAQ;AACnC;AATiB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterator with the provided iterables prepended to the first iterable.\n *\n * @param iterable The iterator to prepend values to.\n * @param iterables The iterables to prepend to the iterator.\n * @returns An iterator that yields the values of the provided iterator followed by the values of the provided iterables.\n *\n * @example\n * ```typescript\n * import { prepend } from '@sapphire/iterator-utilities';\n *\n * console.log([...prepend([3, 4, 5], [1, 2])]);\n * // Output: [1, 2, 3, 4, 5]\n * ```\n *\n * @seealso {@link append} to append values to the end of an iterator.\n */\nexport function* prepend<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\t...iterables: IterableResolvable<ElementType>[]\n): IterableIterator<ElementType> {\n\tfor (const iterable of iterables) {\n\t\tyield* toIterableIterator(iterable);\n\t}\n\n\tyield* toIterableIterator(iterable);\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable and returns the product of all the elements. If the iterable is empty, it returns `1`.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to calculate the product of.
|
|
7
|
+
* @returns The product of the elements in the input iterator.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { product } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
14
|
+
* console.log(product(iterable));
|
|
15
|
+
* // Output: 120
|
|
16
|
+
*
|
|
17
|
+
* const iterable = [1, 2, 3, 4, 5, 0];
|
|
18
|
+
* console.log(product(iterable));
|
|
19
|
+
* // Output: 0
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare function product(iterable: IterableResolvable<number>): number;
|
|
23
|
+
|
|
24
|
+
export { product };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { map } from './map.mjs';
|
|
3
|
+
import { toNumberOrThrow } from './shared/_toNumberOrThrow.mjs';
|
|
4
|
+
|
|
5
|
+
function product(iterable) {
|
|
6
|
+
let result = 1;
|
|
7
|
+
for (const value of map(iterable, toNumberOrThrow)) {
|
|
8
|
+
result *= value;
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
__name(product, "product");
|
|
13
|
+
|
|
14
|
+
export { product };
|
|
15
|
+
//# sourceMappingURL=out.js.map
|
|
16
|
+
//# sourceMappingURL=product.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/product.ts"],"names":[],"mappings":";;;;;AACA,SAAS,WAAW;AACpB,SAAS,uBAAuB;AAqBzB,SAAS,QAAQ,UAA8C;AACrE,MAAI,SAAS;AACb,aAAW,SAAS,IAAI,UAAU,eAAe,GAAG;AACnD,cAAU;AAAA,EACX;AAEA,SAAO;AACR;AAPgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { map } from './map';\nimport { toNumberOrThrow } from './shared/_toNumberOrThrow';\n\n/**\n * Consumes the iterable and returns the product of all the elements. If the iterable is empty, it returns `1`.\n *\n * @param iterable An iterator to calculate the product of.\n * @returns The product of the elements in the input iterator.\n *\n * @example\n * ```typescript\n * import { product } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(product(iterable));\n * // Output: 120\n *\n * const iterable = [1, 2, 3, 4, 5, 0];\n * console.log(product(iterable));\n * // Output: 0\n * ```\n */\nexport function product(iterable: IterableResolvable<number>): number {\n\tlet result = 1;\n\tfor (const value of map(iterable, toNumberOrThrow)) {\n\t\tresult *= value;\n\t}\n\n\treturn result;\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an iterable with the numbers from `start` to `stop` (exclusive) with an optional step.
|
|
3
|
+
*
|
|
4
|
+
* @param start The value of the first number in the range.
|
|
5
|
+
* @param end The end value of the range.
|
|
6
|
+
* @param step The amount to increment the range by.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { range } from '@sapphire/iterator-utilities';
|
|
11
|
+
*
|
|
12
|
+
* const iterable = range(0, 5);
|
|
13
|
+
* console.log([...iterable]);
|
|
14
|
+
* // Output: [0, 1, 2, 3, 4]
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const iterable = range(5, 0);
|
|
20
|
+
* console.log([...iterable]);
|
|
21
|
+
* // Output: [5, 4, 3, 2, 1]
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const iterable = range(0, 5, 2);
|
|
27
|
+
* console.log([...iterable]);
|
|
28
|
+
* // Output: [0, 2, 4]
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function range(start: number, end: number, step?: number | undefined): IterableIterator<number>;
|
|
32
|
+
|
|
33
|
+
export { range };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { toNumberOrThrow } from './shared/_toNumberOrThrow.mjs';
|
|
3
|
+
|
|
4
|
+
function* range(start, end, step) {
|
|
5
|
+
start = toNumberOrThrow(start);
|
|
6
|
+
end = toNumberOrThrow(end);
|
|
7
|
+
if (step === void 0) {
|
|
8
|
+
step = start < end ? 1 : -1;
|
|
9
|
+
} else {
|
|
10
|
+
step = toNumberOrThrow(step);
|
|
11
|
+
if (step === 0) {
|
|
12
|
+
throw new RangeError("Step cannot be zero");
|
|
13
|
+
}
|
|
14
|
+
if (step > 0 && start > end) {
|
|
15
|
+
throw new RangeError("Start must be less than end when step is positive");
|
|
16
|
+
} else if (step < 0 && start < end) {
|
|
17
|
+
throw new RangeError("Start must be greater than end when step is negative");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (start < end) {
|
|
21
|
+
for (let i = start; i < end; i += step) {
|
|
22
|
+
yield i;
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
for (let i = start; i > end; i += step) {
|
|
26
|
+
yield i;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
__name(range, "range");
|
|
31
|
+
|
|
32
|
+
export { range };
|
|
33
|
+
//# sourceMappingURL=out.js.map
|
|
34
|
+
//# sourceMappingURL=range.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/range.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAgCzB,UAAU,MAAM,OAAe,KAAa,MAAqD;AACvG,UAAQ,gBAAgB,KAAK;AAC7B,QAAM,gBAAgB,GAAG;AAEzB,MAAI,SAAS,QAAW;AACvB,WAAO,QAAQ,MAAM,IAAI;AAAA,EAC1B,OAAO;AACN,WAAO,gBAAgB,IAAI;AAG3B,QAAI,SAAS,GAAG;AACf,YAAM,IAAI,WAAW,qBAAqB;AAAA,IAC3C;AAGA,QAAI,OAAO,KAAK,QAAQ,KAAK;AAC5B,YAAM,IAAI,WAAW,mDAAmD;AAAA,IACzE,WAAW,OAAO,KAAK,QAAQ,KAAK;AACnC,YAAM,IAAI,WAAW,sDAAsD;AAAA,IAC5E;AAAA,EACD;AAEA,MAAI,QAAQ,KAAK;AAChB,aAAS,IAAI,OAAO,IAAI,KAAK,KAAK,MAAM;AACvC,YAAM;AAAA,IACP;AAAA,EACD,OAAO;AACN,aAAS,IAAI,OAAO,IAAI,KAAK,KAAK,MAAM;AACvC,YAAM;AAAA,IACP;AAAA,EACD;AACD;AA/BiB","sourcesContent":["import { toNumberOrThrow } from './shared/_toNumberOrThrow';\n\n/**\n * Creates an iterable with the numbers from `start` to `stop` (exclusive) with an optional step.\n *\n * @param start The value of the first number in the range.\n * @param end The end value of the range.\n * @param step The amount to increment the range by.\n *\n * @example\n * ```typescript\n * import { range } from '@sapphire/iterator-utilities';\n *\n * const iterable = range(0, 5);\n * console.log([...iterable]);\n * // Output: [0, 1, 2, 3, 4]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = range(5, 0);\n * console.log([...iterable]);\n * // Output: [5, 4, 3, 2, 1]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = range(0, 5, 2);\n * console.log([...iterable]);\n * // Output: [0, 2, 4]\n * ```\n */\nexport function* range(start: number, end: number, step?: number | undefined): IterableIterator<number> {\n\tstart = toNumberOrThrow(start);\n\tend = toNumberOrThrow(end);\n\n\tif (step === undefined) {\n\t\tstep = start < end ? 1 : -1;\n\t} else {\n\t\tstep = toNumberOrThrow(step);\n\n\t\t// Prevent infinite loops.\n\t\tif (step === 0) {\n\t\t\tthrow new RangeError('Step cannot be zero');\n\t\t}\n\n\t\t// If the step is positive, the start must be less than the end.\n\t\tif (step > 0 && start > end) {\n\t\t\tthrow new RangeError('Start must be less than end when step is positive');\n\t\t} else if (step < 0 && start < end) {\n\t\t\tthrow new RangeError('Start must be greater than end when step is negative');\n\t\t}\n\t}\n\n\tif (start < end) {\n\t\tfor (let i = start; i < end; i += step) {\n\t\t\tyield i;\n\t\t}\n\t} else {\n\t\tfor (let i = start; i > end; i += step) {\n\t\t\tyield i;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable and reduces it to the reducer function's result.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to reduce.
|
|
7
|
+
* @param callbackFn A function to execute for each element produced by the iterator. Its return value becomes the value
|
|
8
|
+
* of the `accumulator` parameter on the next invocation of `callbackFn`. For the last invocation, the return value
|
|
9
|
+
* becomes the return value of `reduce()`.
|
|
10
|
+
* @param initialValue A value to which `accumulator` is initialized the first time the callback is called. If
|
|
11
|
+
* `initialValue` is specified, `callbackFn` starts executing with the first element as `currentValue`. If
|
|
12
|
+
* `initialValue` is not specified, `accumulator` is initialized to the first element, and `callbackFn` starts executing
|
|
13
|
+
* with the second element as `currentValue`. In this case, if the iterator is empty (so that there's no first value to
|
|
14
|
+
* return as `accumulator`), an error is thrown.
|
|
15
|
+
* @returns
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { reduce } from '@sapphire/iterator-utilities';
|
|
20
|
+
*
|
|
21
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
22
|
+
* console.log(reduce(iterable, (accumulator, currentValue) => accumulator + currentValue));
|
|
23
|
+
* // Output: 15
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
*
|
|
28
|
+
* If `initialValue` is not provided, the first element of the iterator is used as the initial value of `accumulator`,
|
|
29
|
+
* consuming the first element.
|
|
30
|
+
*/
|
|
31
|
+
declare function reduce<const ElementType, const MappedType>(iterable: IterableResolvable<ElementType>, callbackFn: (accumulator: MappedType, currentValue: ElementType, currentIndex: number) => MappedType, initialValue?: MappedType): MappedType;
|
|
32
|
+
|
|
33
|
+
export { reduce };
|