@sapphire/iterator-utilities 1.0.3-next.fc35dd86 → 2.0.0-next.1e7d2dec
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 +217 -0
- package/dist/cjs/index.d.cts +32 -9
- package/dist/cjs/lib/all.cjs +12 -0
- package/dist/cjs/lib/all.cjs.map +1 -0
- package/dist/cjs/lib/all.d.cts +2 -0
- package/dist/cjs/lib/any.cjs +12 -0
- package/dist/cjs/lib/any.cjs.map +1 -0
- package/dist/cjs/lib/any.d.cts +2 -0
- package/dist/cjs/lib/collect.cjs +12 -0
- package/dist/cjs/lib/collect.cjs.map +1 -0
- package/dist/cjs/lib/collect.d.cts +2 -0
- package/dist/cjs/lib/collectInto.cjs +17 -0
- package/dist/cjs/lib/collectInto.cjs.map +1 -0
- package/dist/cjs/lib/collectInto.d.cts +29 -0
- package/dist/cjs/lib/compare.cjs +15 -0
- package/dist/cjs/lib/compare.cjs.map +1 -0
- package/dist/cjs/lib/compare.d.cts +32 -0
- package/dist/cjs/lib/compareBy.cjs +26 -0
- package/dist/cjs/lib/compareBy.cjs.map +1 -0
- package/dist/cjs/lib/compareBy.d.cts +31 -0
- package/dist/cjs/lib/drop.cjs +0 -1
- package/dist/cjs/lib/drop.cjs.map +1 -1
- package/dist/cjs/lib/drop.d.cts +1 -1
- package/dist/cjs/lib/dropLast.cjs +0 -1
- package/dist/cjs/lib/dropLast.cjs.map +1 -1
- package/dist/cjs/lib/dropLast.d.cts +1 -1
- package/dist/cjs/lib/dropWhile.cjs +0 -1
- package/dist/cjs/lib/dropWhile.cjs.map +1 -1
- package/dist/cjs/lib/dropWhile.d.cts +1 -1
- package/dist/cjs/lib/equal.cjs +15 -0
- package/dist/cjs/lib/equal.cjs.map +1 -0
- package/dist/cjs/lib/equal.d.cts +26 -0
- package/dist/cjs/lib/equalBy.cjs +23 -0
- package/dist/cjs/lib/equalBy.cjs.map +1 -0
- package/dist/cjs/lib/equalBy.d.cts +27 -0
- package/dist/cjs/lib/filter.cjs +0 -1
- package/dist/cjs/lib/filter.cjs.map +1 -1
- package/dist/cjs/lib/filter.d.cts +1 -1
- package/dist/cjs/lib/fuse.cjs +26 -0
- package/dist/cjs/lib/fuse.cjs.map +1 -0
- package/dist/cjs/lib/fuse.d.cts +47 -0
- package/dist/cjs/lib/greaterOrEqualThan.cjs +17 -0
- package/dist/cjs/lib/greaterOrEqualThan.cjs.map +1 -0
- package/dist/cjs/lib/greaterOrEqualThan.d.cts +32 -0
- package/dist/cjs/lib/greaterThan.cjs +17 -0
- package/dist/cjs/lib/greaterThan.cjs.map +1 -0
- package/dist/cjs/lib/greaterThan.d.cts +32 -0
- package/dist/cjs/lib/indexOf.cjs +0 -1
- package/dist/cjs/lib/indexOf.cjs.map +1 -1
- package/dist/cjs/lib/indexOf.d.cts +1 -1
- package/dist/cjs/lib/inspect.cjs +25 -0
- package/dist/cjs/lib/inspect.cjs.map +1 -0
- package/dist/cjs/lib/inspect.d.cts +39 -0
- package/dist/cjs/lib/intersperse.cjs +35 -0
- package/dist/cjs/lib/intersperse.cjs.map +1 -0
- package/dist/cjs/lib/intersperse.d.cts +30 -0
- package/dist/cjs/lib/isSorted.cjs +15 -0
- package/dist/cjs/lib/isSorted.cjs.map +1 -0
- package/dist/cjs/lib/isSorted.d.cts +35 -0
- package/dist/cjs/lib/isSortedBy.cjs +26 -0
- package/dist/cjs/lib/isSortedBy.cjs.map +1 -0
- package/dist/cjs/lib/isSortedBy.d.cts +32 -0
- package/dist/cjs/lib/isSortedByKey.cjs +29 -0
- package/dist/cjs/lib/isSortedByKey.cjs.map +1 -0
- package/dist/cjs/lib/isSortedByKey.d.cts +30 -0
- package/dist/cjs/lib/lessOrEqualThan.cjs +17 -0
- package/dist/cjs/lib/lessOrEqualThan.cjs.map +1 -0
- package/dist/cjs/lib/lessOrEqualThan.d.cts +32 -0
- package/dist/cjs/lib/lessThan.cjs +17 -0
- package/dist/cjs/lib/lessThan.cjs.map +1 -0
- package/dist/cjs/lib/lessThan.d.cts +32 -0
- package/dist/cjs/lib/max.cjs +3 -7
- package/dist/cjs/lib/max.cjs.map +1 -1
- package/dist/cjs/lib/max.d.cts +8 -3
- package/dist/cjs/lib/maxBy.cjs +27 -0
- package/dist/cjs/lib/maxBy.cjs.map +1 -0
- package/dist/cjs/lib/maxBy.d.cts +31 -0
- package/dist/cjs/lib/maxByKey.cjs +32 -0
- package/dist/cjs/lib/maxByKey.cjs.map +1 -0
- package/dist/cjs/lib/maxByKey.d.cts +32 -0
- package/dist/cjs/lib/min.cjs +3 -7
- package/dist/cjs/lib/min.cjs.map +1 -1
- package/dist/cjs/lib/min.d.cts +8 -3
- package/dist/cjs/lib/minBy.cjs +27 -0
- package/dist/cjs/lib/minBy.cjs.map +1 -0
- package/dist/cjs/lib/minBy.d.cts +31 -0
- package/dist/cjs/lib/minByKey.cjs +32 -0
- package/dist/cjs/lib/minByKey.cjs.map +1 -0
- package/dist/cjs/lib/minByKey.d.cts +31 -0
- package/dist/cjs/lib/notEqual.cjs +15 -0
- package/dist/cjs/lib/notEqual.cjs.map +1 -0
- package/dist/cjs/lib/notEqual.d.cts +26 -0
- package/dist/cjs/lib/nth.cjs +12 -0
- package/dist/cjs/lib/nth.cjs.map +1 -0
- package/dist/cjs/lib/nth.d.cts +2 -0
- package/dist/cjs/lib/position.cjs +12 -0
- package/dist/cjs/lib/position.cjs.map +1 -0
- package/dist/cjs/lib/position.d.cts +2 -0
- package/dist/cjs/lib/reverse.cjs +2 -5
- package/dist/cjs/lib/reverse.cjs.map +1 -1
- package/dist/cjs/lib/shared/_compare.cjs +36 -0
- package/dist/cjs/lib/shared/_compare.cjs.map +1 -0
- package/dist/cjs/lib/shared/_compare.d.cts +20 -0
- package/dist/cjs/lib/shared/comparators.cjs +28 -0
- package/dist/cjs/lib/shared/comparators.cjs.map +1 -0
- package/dist/cjs/lib/shared/comparators.d.cts +34 -0
- package/dist/cjs/lib/skip.cjs +12 -0
- package/dist/cjs/lib/skip.cjs.map +1 -0
- package/dist/cjs/lib/skip.d.cts +2 -0
- package/dist/cjs/lib/skipLast.cjs +12 -0
- package/dist/cjs/lib/skipLast.cjs.map +1 -0
- package/dist/cjs/lib/skipLast.d.cts +2 -0
- package/dist/cjs/lib/skipWhile.cjs +12 -0
- package/dist/cjs/lib/skipWhile.cjs.map +1 -0
- package/dist/cjs/lib/skipWhile.d.cts +2 -0
- package/dist/cjs/lib/stepBy.cjs +29 -0
- package/dist/cjs/lib/stepBy.cjs.map +1 -0
- package/dist/cjs/lib/stepBy.d.cts +24 -0
- package/dist/cjs/lib/takeWhile.cjs +12 -0
- package/dist/cjs/lib/takeWhile.cjs.map +1 -0
- package/dist/cjs/lib/takeWhile.d.cts +2 -0
- package/dist/esm/index.d.mts +32 -9
- package/dist/esm/index.mjs +31 -0
- package/dist/esm/lib/all.d.mts +2 -0
- package/dist/esm/lib/all.mjs +4 -0
- package/dist/esm/lib/all.mjs.map +1 -0
- package/dist/esm/lib/any.d.mts +2 -0
- package/dist/esm/lib/any.mjs +4 -0
- package/dist/esm/lib/any.mjs.map +1 -0
- package/dist/esm/lib/collect.d.mts +2 -0
- package/dist/esm/lib/collect.mjs +4 -0
- package/dist/esm/lib/collect.mjs.map +1 -0
- package/dist/esm/lib/collectInto.d.mts +29 -0
- package/dist/esm/lib/collectInto.mjs +14 -0
- package/dist/esm/lib/collectInto.mjs.map +1 -0
- package/dist/esm/lib/compare.d.mts +32 -0
- package/dist/esm/lib/compare.mjs +12 -0
- package/dist/esm/lib/compare.mjs.map +1 -0
- package/dist/esm/lib/compareBy.d.mts +31 -0
- package/dist/esm/lib/compareBy.mjs +23 -0
- package/dist/esm/lib/compareBy.mjs.map +1 -0
- package/dist/esm/lib/drop.d.mts +1 -1
- package/dist/esm/lib/drop.mjs +1 -1
- package/dist/esm/lib/drop.mjs.map +1 -1
- package/dist/esm/lib/dropLast.d.mts +1 -1
- package/dist/esm/lib/dropLast.mjs +1 -1
- package/dist/esm/lib/dropLast.mjs.map +1 -1
- package/dist/esm/lib/dropWhile.d.mts +1 -1
- package/dist/esm/lib/dropWhile.mjs +1 -1
- package/dist/esm/lib/dropWhile.mjs.map +1 -1
- package/dist/esm/lib/equal.d.mts +26 -0
- package/dist/esm/lib/equal.mjs +11 -0
- package/dist/esm/lib/equal.mjs.map +1 -0
- package/dist/esm/lib/equalBy.d.mts +27 -0
- package/dist/esm/lib/equalBy.mjs +19 -0
- package/dist/esm/lib/equalBy.mjs.map +1 -0
- package/dist/esm/lib/filter.d.mts +1 -1
- package/dist/esm/lib/filter.mjs +1 -1
- package/dist/esm/lib/filter.mjs.map +1 -1
- package/dist/esm/lib/fuse.d.mts +47 -0
- package/dist/esm/lib/fuse.mjs +23 -0
- package/dist/esm/lib/fuse.mjs.map +1 -0
- package/dist/esm/lib/greaterOrEqualThan.d.mts +32 -0
- package/dist/esm/lib/greaterOrEqualThan.mjs +13 -0
- package/dist/esm/lib/greaterOrEqualThan.mjs.map +1 -0
- package/dist/esm/lib/greaterThan.d.mts +32 -0
- package/dist/esm/lib/greaterThan.mjs +13 -0
- package/dist/esm/lib/greaterThan.mjs.map +1 -0
- package/dist/esm/lib/indexOf.d.mts +1 -1
- package/dist/esm/lib/indexOf.mjs +1 -1
- package/dist/esm/lib/indexOf.mjs.map +1 -1
- package/dist/esm/lib/inspect.d.mts +39 -0
- package/dist/esm/lib/inspect.mjs +22 -0
- package/dist/esm/lib/inspect.mjs.map +1 -0
- package/dist/esm/lib/intersperse.d.mts +30 -0
- package/dist/esm/lib/intersperse.mjs +32 -0
- package/dist/esm/lib/intersperse.mjs.map +1 -0
- package/dist/esm/lib/isSorted.d.mts +35 -0
- package/dist/esm/lib/isSorted.mjs +12 -0
- package/dist/esm/lib/isSorted.mjs.map +1 -0
- package/dist/esm/lib/isSortedBy.d.mts +32 -0
- package/dist/esm/lib/isSortedBy.mjs +23 -0
- package/dist/esm/lib/isSortedBy.mjs.map +1 -0
- package/dist/esm/lib/isSortedByKey.d.mts +30 -0
- package/dist/esm/lib/isSortedByKey.mjs +26 -0
- package/dist/esm/lib/isSortedByKey.mjs.map +1 -0
- package/dist/esm/lib/lessOrEqualThan.d.mts +32 -0
- package/dist/esm/lib/lessOrEqualThan.mjs +13 -0
- package/dist/esm/lib/lessOrEqualThan.mjs.map +1 -0
- package/dist/esm/lib/lessThan.d.mts +32 -0
- package/dist/esm/lib/lessThan.mjs +13 -0
- package/dist/esm/lib/lessThan.mjs.map +1 -0
- package/dist/esm/lib/max.d.mts +8 -3
- package/dist/esm/lib/max.mjs +3 -7
- package/dist/esm/lib/max.mjs.map +1 -1
- package/dist/esm/lib/maxBy.d.mts +31 -0
- package/dist/esm/lib/maxBy.mjs +24 -0
- package/dist/esm/lib/maxBy.mjs.map +1 -0
- package/dist/esm/lib/maxByKey.d.mts +32 -0
- package/dist/esm/lib/maxByKey.mjs +29 -0
- package/dist/esm/lib/maxByKey.mjs.map +1 -0
- package/dist/esm/lib/min.d.mts +8 -3
- package/dist/esm/lib/min.mjs +3 -7
- package/dist/esm/lib/min.mjs.map +1 -1
- package/dist/esm/lib/minBy.d.mts +31 -0
- package/dist/esm/lib/minBy.mjs +24 -0
- package/dist/esm/lib/minBy.mjs.map +1 -0
- package/dist/esm/lib/minByKey.d.mts +31 -0
- package/dist/esm/lib/minByKey.mjs +29 -0
- package/dist/esm/lib/minByKey.mjs.map +1 -0
- package/dist/esm/lib/notEqual.d.mts +26 -0
- package/dist/esm/lib/notEqual.mjs +11 -0
- package/dist/esm/lib/notEqual.mjs.map +1 -0
- package/dist/esm/lib/nth.d.mts +2 -0
- package/dist/esm/lib/nth.mjs +4 -0
- package/dist/esm/lib/nth.mjs.map +1 -0
- package/dist/esm/lib/position.d.mts +2 -0
- package/dist/esm/lib/position.mjs +4 -0
- package/dist/esm/lib/position.mjs.map +1 -0
- package/dist/esm/lib/reverse.mjs +2 -5
- package/dist/esm/lib/reverse.mjs.map +1 -1
- package/dist/esm/lib/shared/_compare.d.mts +20 -0
- package/dist/esm/lib/shared/_compare.mjs +30 -0
- package/dist/esm/lib/shared/_compare.mjs.map +1 -0
- package/dist/esm/lib/shared/comparators.d.mts +34 -0
- package/dist/esm/lib/shared/comparators.mjs +21 -0
- package/dist/esm/lib/shared/comparators.mjs.map +1 -0
- package/dist/esm/lib/skip.d.mts +2 -0
- package/dist/esm/lib/skip.mjs +4 -0
- package/dist/esm/lib/skip.mjs.map +1 -0
- package/dist/esm/lib/skipLast.d.mts +2 -0
- package/dist/esm/lib/skipLast.mjs +4 -0
- package/dist/esm/lib/skipLast.mjs.map +1 -0
- package/dist/esm/lib/skipWhile.d.mts +2 -0
- package/dist/esm/lib/skipWhile.mjs +4 -0
- package/dist/esm/lib/skipWhile.mjs.map +1 -0
- package/dist/esm/lib/stepBy.d.mts +24 -0
- package/dist/esm/lib/stepBy.mjs +26 -0
- package/dist/esm/lib/stepBy.mjs.map +1 -0
- package/dist/esm/lib/takeWhile.d.mts +2 -0
- package/dist/esm/lib/takeWhile.mjs +4 -0
- package/dist/esm/lib/takeWhile.mjs.map +1 -0
- package/dist/iife/index.global.js +391 -49
- package/dist/iife/index.global.js.map +1 -1
- package/package.json +292 -22
package/dist/esm/index.mjs
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
export * from './lib/all.mjs';
|
|
2
|
+
export * from './lib/any.mjs';
|
|
1
3
|
export * from './lib/append.mjs';
|
|
2
4
|
export * from './lib/at.mjs';
|
|
3
5
|
export * from './lib/average.mjs';
|
|
4
6
|
export * from './lib/chain.mjs';
|
|
5
7
|
export * from './lib/chunk.mjs';
|
|
8
|
+
export * from './lib/collect.mjs';
|
|
9
|
+
export * from './lib/collectInto.mjs';
|
|
6
10
|
export * from './lib/compact.mjs';
|
|
11
|
+
export * from './lib/compare.mjs';
|
|
12
|
+
export * from './lib/compareBy.mjs';
|
|
7
13
|
export * from './lib/compress.mjs';
|
|
8
14
|
export * from './lib/contains.mjs';
|
|
9
15
|
export * from './lib/count.mjs';
|
|
@@ -14,6 +20,8 @@ export * from './lib/dropLast.mjs';
|
|
|
14
20
|
export * from './lib/dropWhile.mjs';
|
|
15
21
|
export * from './lib/empty.mjs';
|
|
16
22
|
export * from './lib/enumerate.mjs';
|
|
23
|
+
export * from './lib/equal.mjs';
|
|
24
|
+
export * from './lib/equalBy.mjs';
|
|
17
25
|
export * from './lib/every.mjs';
|
|
18
26
|
export * from './lib/filter.mjs';
|
|
19
27
|
export * from './lib/find.mjs';
|
|
@@ -23,28 +31,51 @@ export * from './lib/flat.mjs';
|
|
|
23
31
|
export * from './lib/flatMap.mjs';
|
|
24
32
|
export * from './lib/forEach.mjs';
|
|
25
33
|
export * from './lib/from.mjs';
|
|
34
|
+
export * from './lib/fuse.mjs';
|
|
35
|
+
export * from './lib/greaterOrEqualThan.mjs';
|
|
36
|
+
export * from './lib/greaterThan.mjs';
|
|
26
37
|
export * from './lib/indexOf.mjs';
|
|
38
|
+
export * from './lib/inspect.mjs';
|
|
27
39
|
export * from './lib/intersect.mjs';
|
|
40
|
+
export * from './lib/intersperse.mjs';
|
|
28
41
|
export * from './lib/isEmpty.mjs';
|
|
42
|
+
export * from './lib/isSorted.mjs';
|
|
43
|
+
export * from './lib/isSortedBy.mjs';
|
|
44
|
+
export * from './lib/isSortedByKey.mjs';
|
|
29
45
|
export * from './lib/last.mjs';
|
|
46
|
+
export * from './lib/lessOrEqualThan.mjs';
|
|
47
|
+
export * from './lib/lessThan.mjs';
|
|
30
48
|
export * from './lib/map.mjs';
|
|
31
49
|
export * from './lib/max.mjs';
|
|
50
|
+
export * from './lib/maxBy.mjs';
|
|
51
|
+
export * from './lib/maxByKey.mjs';
|
|
32
52
|
export * from './lib/min.mjs';
|
|
53
|
+
export * from './lib/minBy.mjs';
|
|
54
|
+
export * from './lib/minByKey.mjs';
|
|
55
|
+
export * from './lib/notEqual.mjs';
|
|
56
|
+
export * from './lib/nth.mjs';
|
|
33
57
|
export * from './lib/partition.mjs';
|
|
34
58
|
export * from './lib/peekable.mjs';
|
|
59
|
+
export * from './lib/position.mjs';
|
|
35
60
|
export * from './lib/prepend.mjs';
|
|
36
61
|
export * from './lib/product.mjs';
|
|
37
62
|
export * from './lib/range.mjs';
|
|
38
63
|
export * from './lib/reduce.mjs';
|
|
39
64
|
export * from './lib/repeat.mjs';
|
|
40
65
|
export * from './lib/reverse.mjs';
|
|
66
|
+
export * from './lib/shared/comparators.mjs';
|
|
67
|
+
export * from './lib/skip.mjs';
|
|
68
|
+
export * from './lib/skipLast.mjs';
|
|
69
|
+
export * from './lib/skipWhile.mjs';
|
|
41
70
|
export * from './lib/slice.mjs';
|
|
42
71
|
export * from './lib/some.mjs';
|
|
43
72
|
export * from './lib/sorted.mjs';
|
|
44
73
|
export * from './lib/starMap.mjs';
|
|
74
|
+
export * from './lib/stepBy.mjs';
|
|
45
75
|
export * from './lib/sum.mjs';
|
|
46
76
|
export * from './lib/take.mjs';
|
|
47
77
|
export * from './lib/takeLast.mjs';
|
|
78
|
+
export * from './lib/takeWhile.mjs';
|
|
48
79
|
export * from './lib/tee.mjs';
|
|
49
80
|
export * from './lib/toArray.mjs';
|
|
50
81
|
export * from './lib/toIterableIterator.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"all.mjs","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"any.mjs","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"collect.mjs","sourcesContent":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Collects all the items from an iterator into an array.
|
|
5
|
+
*
|
|
6
|
+
* This method consumes the iterator and adds all its items to the passed array. The array is then returned, so the call
|
|
7
|
+
* chain can be continued.
|
|
8
|
+
*
|
|
9
|
+
* This is useful when you already have a collection and want to add the iterator items to it.
|
|
10
|
+
*
|
|
11
|
+
* @param iterable An iterator to fuse.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { collectInto, map } from '@sapphire/iterator-utilities';
|
|
16
|
+
*
|
|
17
|
+
* const iterable = [1, 2, 3];
|
|
18
|
+
* const output = [0, 1];
|
|
19
|
+
*
|
|
20
|
+
* collectInto(map(iterable, (value) => value * 2), output);
|
|
21
|
+
* collectInto(map(iterable, (value) => value * 10), output);
|
|
22
|
+
*
|
|
23
|
+
* console.log(output);
|
|
24
|
+
* // Output: [0, 1, 2, 4, 6, 10, 20, 30]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function collectInto<const ElementType>(iterable: IterableResolvable<ElementType>, output: ElementType[]): ElementType[];
|
|
28
|
+
|
|
29
|
+
export { collectInto };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
3
|
+
|
|
4
|
+
function collectInto(iterable, output) {
|
|
5
|
+
for (const value of toIterableIterator(iterable)) {
|
|
6
|
+
output.push(value);
|
|
7
|
+
}
|
|
8
|
+
return output;
|
|
9
|
+
}
|
|
10
|
+
__name(collectInto, "collectInto");
|
|
11
|
+
|
|
12
|
+
export { collectInto };
|
|
13
|
+
//# sourceMappingURL=collectInto.mjs.map
|
|
14
|
+
//# sourceMappingURL=collectInto.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/collectInto.ts"],"names":[],"mappings":";;;AA2BO,SAAS,WAAA,CAA+B,UAA2C,MAAsC,EAAA;AAC/H,EAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,IAAA,MAAA,CAAO,KAAK,KAAK,CAAA,CAAA;AAAA,GAClB;AAEA,EAAO,OAAA,MAAA,CAAA;AACR,CAAA;AANgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"collectInto.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Collects all the items from an iterator into an array.\n *\n * This method consumes the iterator and adds all its items to the passed array. The array is then returned, so the call\n * chain can be continued.\n *\n * This is useful when you already have a collection and want to add the iterator items to it.\n *\n * @param iterable An iterator to fuse.\n *\n * @example\n * ```typescript\n * import { collectInto, map } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3];\n * const output = [0, 1];\n *\n * collectInto(map(iterable, (value) => value * 2), output);\n * collectInto(map(iterable, (value) => value * 10), output);\n *\n * console.log(output);\n * // Output: [0, 1, 2, 4, 6, 10, 20, 30]\n * ```\n */\nexport function collectInto<const ElementType>(iterable: IterableResolvable<ElementType>, output: ElementType[]): ElementType[] {\n\tfor (const value of toIterableIterator(iterable)) {\n\t\toutput.push(value);\n\t}\n\n\treturn output;\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
import { LexicographicComparison } from './shared/_compare.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* {@link LexicographicComparison Lexicographically} compares the elements of both iterators are equal.
|
|
6
|
+
*
|
|
7
|
+
* This function uses the default comparator (lexicographically), which means it will compare the elements as strings.
|
|
8
|
+
* If this is undesirable, use {@link compareBy} instead.
|
|
9
|
+
*
|
|
10
|
+
* @param iterable The iterator to compare.
|
|
11
|
+
* @param other The iterator to compare against.
|
|
12
|
+
* @returns Whether the two iterators are equal.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { compare } from '@sapphire/iterator-utilities';
|
|
17
|
+
*
|
|
18
|
+
* console.log(compare([1], [1]));
|
|
19
|
+
* // Output: 0
|
|
20
|
+
* console.log(compare([1], [1, 2]));
|
|
21
|
+
* // Output: -1
|
|
22
|
+
* console.log(compare([1, 2], [1]));
|
|
23
|
+
* // Output: 1
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
*
|
|
28
|
+
* This function consumes the entire iterator.
|
|
29
|
+
*/
|
|
30
|
+
declare function compare<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): LexicographicComparison;
|
|
31
|
+
|
|
32
|
+
export { compare };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
|
+
import { compareBy } from './compareBy.mjs';
|
|
3
|
+
import { defaultCompare } from './shared/comparators.mjs';
|
|
4
|
+
|
|
5
|
+
function compare(iterable, other) {
|
|
6
|
+
return compareBy(iterable, other, defaultCompare);
|
|
7
|
+
}
|
|
8
|
+
__name(compare, "compare");
|
|
9
|
+
|
|
10
|
+
export { compare };
|
|
11
|
+
//# sourceMappingURL=compare.mjs.map
|
|
12
|
+
//# sourceMappingURL=compare.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/compare.ts"],"names":[],"mappings":";;;;AA+BO,SAAS,OAAA,CACf,UACA,KAC0B,EAAA;AAC1B,EAAO,OAAA,SAAA,CAAU,QAAU,EAAA,KAAA,EAAO,cAAc,CAAA,CAAA;AACjD,CAAA;AALgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA","file":"compare.mjs","sourcesContent":["import { compareBy } from './compareBy';\nimport type { IterableResolvable } from './from';\nimport type { LexicographicComparison } from './shared/_compare';\nimport { defaultCompare } from './shared/comparators';\n\n/**\n * {@link LexicographicComparison Lexicographically} compares the elements of both iterators are equal.\n *\n * This function uses the default comparator (lexicographically), which means it will compare the elements as strings.\n * If this is undesirable, use {@link compareBy} instead.\n *\n * @param iterable The iterator to compare.\n * @param other The iterator to compare against.\n * @returns Whether the two iterators are equal.\n *\n * @example\n * ```typescript\n * import { compare } from '@sapphire/iterator-utilities';\n *\n * console.log(compare([1], [1]));\n * // Output: 0\n * console.log(compare([1], [1, 2]));\n * // Output: -1\n * console.log(compare([1, 2], [1]));\n * // Output: 1\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function compare<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tother: IterableResolvable<ElementType>\n): LexicographicComparison {\n\treturn compareBy(iterable, other, defaultCompare);\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
import { CompareByComparator, LexicographicComparison } from './shared/_compare.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* {@link LexicographicComparison Lexicographically} compares the elements of both iterators are equal. That is:
|
|
6
|
+
*
|
|
7
|
+
* @param iterable The iterator to compare.
|
|
8
|
+
* @param other The iterator to compare against.
|
|
9
|
+
* @returns Whether the two iterators are equal.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { ascNumber, compareBy } from '@sapphire/iterator-utilities';
|
|
14
|
+
*
|
|
15
|
+
* const x = [1, 2, 3, 4];
|
|
16
|
+
* const y = [1, 4, 9, 16];
|
|
17
|
+
* console.log(compareBy(x, y, (x, y) => ascNumber(x, y)));
|
|
18
|
+
* // Output: -1
|
|
19
|
+
* console.log(compareBy(x, y, (x, y) => ascNumber(x * x, y)));
|
|
20
|
+
* // Output: 0
|
|
21
|
+
* console.log(compareBy(x, y, (x, y) => ascNumber(x * 2, y)));
|
|
22
|
+
* // Output: 1
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
*
|
|
27
|
+
* This function consumes the entire iterator.
|
|
28
|
+
*/
|
|
29
|
+
declare function compareBy<const ElementType>(iterable: IterableResolvable<ElementType | undefined>, other: IterableResolvable<ElementType | undefined>, comparator: CompareByComparator<ElementType>): LexicographicComparison;
|
|
30
|
+
|
|
31
|
+
export { compareBy };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
|
+
import { from } from './from.mjs';
|
|
3
|
+
import { compareIteratorElements, orderingIsEqual, orderingIsLess } from './shared/_compare.mjs';
|
|
4
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
5
|
+
|
|
6
|
+
function compareBy(iterable, other, comparator) {
|
|
7
|
+
const iterator1 = from(other);
|
|
8
|
+
for (const x of toIterableIterator(iterable)) {
|
|
9
|
+
const result1 = iterator1.next();
|
|
10
|
+
if (result1.done) return 1;
|
|
11
|
+
const y = result1.value;
|
|
12
|
+
const comparison = compareIteratorElements(x, y, comparator);
|
|
13
|
+
if (!orderingIsEqual(comparison)) {
|
|
14
|
+
return orderingIsLess(comparison) ? -1 : 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return iterator1.next().done ? 0 : -1;
|
|
18
|
+
}
|
|
19
|
+
__name(compareBy, "compareBy");
|
|
20
|
+
|
|
21
|
+
export { compareBy };
|
|
22
|
+
//# sourceMappingURL=compareBy.mjs.map
|
|
23
|
+
//# sourceMappingURL=compareBy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/compareBy.ts"],"names":[],"mappings":";;;;;AA6BO,SAAS,SAAA,CACf,QACA,EAAA,KAAA,EACA,UAC0B,EAAA;AAC1B,EAAM,MAAA,SAAA,GAAY,KAAK,KAAK,CAAA,CAAA;AAE5B,EAAW,KAAA,MAAA,CAAA,IAAK,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AAC7C,IAAM,MAAA,OAAA,GAAU,UAAU,IAAK,EAAA,CAAA;AAC/B,IAAI,IAAA,OAAA,CAAQ,MAAa,OAAA,CAAA,CAAA;AAEzB,IAAA,MAAM,IAAI,OAAQ,CAAA,KAAA,CAAA;AAClB,IAAA,MAAM,UAAa,GAAA,uBAAA,CAAqC,CAAG,EAAA,CAAA,EAAG,UAAU,CAAA,CAAA;AACxE,IAAI,IAAA,CAAC,eAAgB,CAAA,UAAU,CAAG,EAAA;AACjC,MAAO,OAAA,cAAA,CAAe,UAAU,CAAA,GAAI,CAAK,CAAA,GAAA,CAAA,CAAA;AAAA,KAC1C;AAAA,GACD;AAEA,EAAA,OAAO,SAAU,CAAA,IAAA,EAAO,CAAA,IAAA,GAAO,CAAI,GAAA,CAAA,CAAA,CAAA;AACpC,CAAA;AAnBgB,MAAA,CAAA,SAAA,EAAA,WAAA,CAAA","file":"compareBy.mjs","sourcesContent":["import { from, type IterableResolvable } from './from';\nimport { compareIteratorElements, orderingIsEqual, orderingIsLess, type CompareByComparator, type LexicographicComparison } from './shared/_compare';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * {@link LexicographicComparison Lexicographically} compares the elements of both iterators are equal. That is:\n *\n * @param iterable The iterator to compare.\n * @param other The iterator to compare against.\n * @returns Whether the two iterators are equal.\n *\n * @example\n * ```typescript\n * import { ascNumber, compareBy } from '@sapphire/iterator-utilities';\n *\n * const x = [1, 2, 3, 4];\n * const y = [1, 4, 9, 16];\n * console.log(compareBy(x, y, (x, y) => ascNumber(x, y)));\n * // Output: -1\n * console.log(compareBy(x, y, (x, y) => ascNumber(x * x, y)));\n * // Output: 0\n * console.log(compareBy(x, y, (x, y) => ascNumber(x * 2, y)));\n * // Output: 1\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function compareBy<const ElementType>(\n\titerable: IterableResolvable<ElementType | undefined>,\n\tother: IterableResolvable<ElementType | undefined>,\n\tcomparator: CompareByComparator<ElementType>\n): LexicographicComparison {\n\tconst iterator1 = from(other);\n\n\tfor (const x of toIterableIterator(iterable)) {\n\t\tconst result1 = iterator1.next();\n\t\tif (result1.done) return 1;\n\n\t\tconst y = result1.value;\n\t\tconst comparison = compareIteratorElements<ElementType>(x, y, comparator);\n\t\tif (!orderingIsEqual(comparison)) {\n\t\t\treturn orderingIsLess(comparison) ? -1 : 1;\n\t\t}\n\t}\n\n\treturn iterator1.next().done ? 0 : -1;\n}\n"]}
|
package/dist/esm/lib/drop.d.mts
CHANGED
package/dist/esm/lib/drop.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/drop.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,EAAM,MAAA,gBAAA,GAAmB,mBAAmB,QAAQ,CAAA,CAAA;AAGpD,EAAI,IAAA,KAAA,KAAU,GAAU,OAAA,gBAAA,CAAA;AAExB,EAAA,IAAI,KAAU,KAAA,MAAA,CAAO,iBAAmB,EAAA,OAAO,KAAM,EAAA,CAAA;AAErD,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,EAAO,CAAK,EAAA,EAAA;AAC/B,IAAI,IAAA,gBAAA,CAAiB,IAAK,EAAA,CAAE,IAAM,EAAA,MAAA;AAAA,GACnC;AAEA,EAAO,OAAA,gBAAA,CAAA;AACR,CAAA;AAdgB,MAAA,CAAA,IAAA,EAAA,MAAA,CAAA","file":"drop.mjs","sourcesContent":["import { empty } from './empty';\nimport type { IterableResolvable } from './from';\nimport { assertNotNegative } from './shared/_assertNotNegative';\nimport { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Advances the iterable by `count` elements from the iterable.\n *\n * @param iterable An iterator to drop values from.\n * @param count The number of elements to drop from the start of the iteration.\n * @returns An iterator that contains the elements of the provided iterator, except for the first `count` elements.\n *\n * @example\n * ```typescript\n * import { drop } from '@sapphire/iterator-utilities';\n *\n * const iterable = drop(iterator, 2);\n * console.log([...iterable]);\n * // Output: [3, 4, 5]\n * ```\n */\nexport function drop<const ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType> {\n\tcount = assertNotNegative(toIntegerOrInfinityOrThrow(count), count);\n\tconst resolvedIterable = toIterableIterator(iterable);\n\n\t// If the count is 0, return the original iterable:\n\tif (count === 0) return resolvedIterable;\n\t// If the count is infinite, return an empty iterable:\n\tif (count === Number.POSITIVE_INFINITY) return empty();\n\n\tfor (let i = 0; i < count; i++) {\n\t\tif (resolvedIterable.next().done) break;\n\t}\n\n\treturn resolvedIterable;\n}\n
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/drop.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,EAAM,MAAA,gBAAA,GAAmB,mBAAmB,QAAQ,CAAA,CAAA;AAGpD,EAAI,IAAA,KAAA,KAAU,GAAU,OAAA,gBAAA,CAAA;AAExB,EAAA,IAAI,KAAU,KAAA,MAAA,CAAO,iBAAmB,EAAA,OAAO,KAAM,EAAA,CAAA;AAErD,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,EAAO,CAAK,EAAA,EAAA;AAC/B,IAAI,IAAA,gBAAA,CAAiB,IAAK,EAAA,CAAE,IAAM,EAAA,MAAA;AAAA,GACnC;AAEA,EAAO,OAAA,gBAAA,CAAA;AACR,CAAA;AAdgB,MAAA,CAAA,IAAA,EAAA,MAAA,CAAA","file":"drop.mjs","sourcesContent":["import { empty } from './empty';\nimport type { IterableResolvable } from './from';\nimport { assertNotNegative } from './shared/_assertNotNegative';\nimport { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Advances the iterable by `count` elements from the iterable.\n *\n * @param iterable An iterator to drop values from.\n * @param count The number of elements to drop from the start of the iteration.\n * @returns An iterator that contains the elements of the provided iterator, except for the first `count` elements.\n *\n * @example\n * ```typescript\n * import { drop } from '@sapphire/iterator-utilities';\n *\n * const iterable = drop(iterator, 2);\n * console.log([...iterable]);\n * // Output: [3, 4, 5]\n * ```\n */\nexport function drop<const ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType> {\n\tcount = assertNotNegative(toIntegerOrInfinityOrThrow(count), count);\n\tconst resolvedIterable = toIterableIterator(iterable);\n\n\t// If the count is 0, return the original iterable:\n\tif (count === 0) return resolvedIterable;\n\t// If the count is infinite, return an empty iterable:\n\tif (count === Number.POSITIVE_INFINITY) return empty();\n\n\tfor (let i = 0; i < count; i++) {\n\t\tif (resolvedIterable.next().done) break;\n\t}\n\n\treturn resolvedIterable;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/dropLast.ts"],"names":[],"mappings":";;;;;;;AA2BO,SAAS,QAAA,CAA4B,UAA2C,KAA8C,EAAA;AACpI,EAAA,KAAA,GAAQ,iBAAkB,CAAA,0BAAA,CAA2B,KAAK,CAAA,EAAG,KAAK,CAAA,CAAA;AAClE,EAAM,MAAA,KAAA,GAAQ,QAAQ,QAAQ,CAAA,CAAA;AAC9B,EAAA,IAAI,KAAM,CAAA,MAAA,IAAU,KAAO,EAAA,OAAO,KAAM,EAAA,CAAA;AACxC,EAAA,OAAO,KAAK,KAAM,CAAA,MAAA,EAAU,EAAA,KAAA,CAAM,SAAS,KAAK,CAAA,CAAA;AACjD,CAAA;AALgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"dropLast.mjs","sourcesContent":["import { empty } from './empty';\nimport type { IterableResolvable } from './from';\nimport { assertNotNegative } from './shared/_assertNotNegative';\nimport { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow';\nimport { take } from './take';\nimport { toArray } from './toArray';\n\n/**\n * Consumes the iterable, creating a new iterator without the last `count` elements from the iterable.\n *\n * @param iterable An iterator to drop values from.\n * @param count The number of values to drop from the end of the iterator.\n * @returns An iterator that contains the elements of the provided iterator, except for the last `count` elements.\n *\n * @example\n * ```typescript\n * import { dropLast } from '@sapphire/iterator-utilities';\n *\n * const iterable = dropLast([1, 2, 3, 4, 5], 2);\n * console.log([...iterable]);\n * // Output: [1, 2, 3]\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function dropLast<const ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType> {\n\tcount = assertNotNegative(toIntegerOrInfinityOrThrow(count), count);\n\tconst array = toArray(iterable);\n\tif (array.length <= count) return empty();\n\treturn take(array.values(), array.length - count);\n}\n
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/dropLast.ts"],"names":[],"mappings":";;;;;;;AA2BO,SAAS,QAAA,CAA4B,UAA2C,KAA8C,EAAA;AACpI,EAAA,KAAA,GAAQ,iBAAkB,CAAA,0BAAA,CAA2B,KAAK,CAAA,EAAG,KAAK,CAAA,CAAA;AAClE,EAAM,MAAA,KAAA,GAAQ,QAAQ,QAAQ,CAAA,CAAA;AAC9B,EAAA,IAAI,KAAM,CAAA,MAAA,IAAU,KAAO,EAAA,OAAO,KAAM,EAAA,CAAA;AACxC,EAAA,OAAO,KAAK,KAAM,CAAA,MAAA,EAAU,EAAA,KAAA,CAAM,SAAS,KAAK,CAAA,CAAA;AACjD,CAAA;AALgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"dropLast.mjs","sourcesContent":["import { empty } from './empty';\nimport type { IterableResolvable } from './from';\nimport { assertNotNegative } from './shared/_assertNotNegative';\nimport { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow';\nimport { take } from './take';\nimport { toArray } from './toArray';\n\n/**\n * Consumes the iterable, creating a new iterator without the last `count` elements from the iterable.\n *\n * @param iterable An iterator to drop values from.\n * @param count The number of values to drop from the end of the iterator.\n * @returns An iterator that contains the elements of the provided iterator, except for the last `count` elements.\n *\n * @example\n * ```typescript\n * import { dropLast } from '@sapphire/iterator-utilities';\n *\n * const iterable = dropLast([1, 2, 3, 4, 5], 2);\n * console.log([...iterable]);\n * // Output: [1, 2, 3]\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function dropLast<const ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType> {\n\tcount = assertNotNegative(toIntegerOrInfinityOrThrow(count), count);\n\tconst array = toArray(iterable);\n\tif (array.length <= count) return empty();\n\treturn take(array.values(), array.length - count);\n}\n"]}
|
|
@@ -21,4 +21,4 @@ import { IterableResolvable } from './from.mjs';
|
|
|
21
21
|
declare function dropWhile<const ElementType, const FilteredType extends ElementType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => element is FilteredType): IterableIterator<Exclude<ElementType, FilteredType>>;
|
|
22
22
|
declare function dropWhile<const ElementType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => boolean): IterableIterator<ElementType>;
|
|
23
23
|
|
|
24
|
-
export { dropWhile
|
|
24
|
+
export { dropWhile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/dropWhile.ts"],"names":[],"mappings":";;;;AA8BO,UAAU,SAAA,CAChB,UACA,UACgC,EAAA;AAChC,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,IAAA,IAAI,CAAC,UAAA,CAAW,KAAO,EAAA,KAAA,EAAO,CAAG,EAAA;AAChC,MAAM,MAAA,KAAA,CAAA;AAAA,KACP;AAAA,GACD;AACD,CAAA;AAZiB,MAAA,CAAA,SAAA,EAAA,WAAA,CAAA","file":"dropWhile.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates a new iterator without the elements that satisfy the specified test.\n *\n * @param iterable An iterator to drop values from.\n * @param callbackFn A function to execute for each element produced by the iterator. It should return a falsy value to make the element yielded by the iterator helper, and a truthy value otherwise.\n * @returns An iterator that produces elements from the given iterator that don't satisfy the specified test.\n *\n * @example\n * ```typescript\n * import { dropWhile } from '@sapphire/iterator-utilities';\n *\n * const iterable = dropWhile([1, 2, 3, 4, 5], (value) => value < 3);\n * console.log([...iterable]);\n * // Output: [3, 4, 5]\n * ```\n *\n * @seealso {@link filter} or {@link takeWhile} for the opposite behavior.\n */\nexport function dropWhile<const ElementType, const FilteredType extends ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => element is FilteredType\n): IterableIterator<Exclude<ElementType, FilteredType>>;\nexport function dropWhile<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): IterableIterator<ElementType>;\nexport function* dropWhile<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): IterableIterator<ElementType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tif (!callbackFn(value, index++)) {\n\t\t\tyield value;\n\t\t}\n\t}\n}\n
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/dropWhile.ts"],"names":[],"mappings":";;;;AA8BO,UAAU,SAAA,CAChB,UACA,UACgC,EAAA;AAChC,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,IAAA,IAAI,CAAC,UAAA,CAAW,KAAO,EAAA,KAAA,EAAO,CAAG,EAAA;AAChC,MAAM,MAAA,KAAA,CAAA;AAAA,KACP;AAAA,GACD;AACD,CAAA;AAZiB,MAAA,CAAA,SAAA,EAAA,WAAA,CAAA","file":"dropWhile.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates a new iterator without the elements that satisfy the specified test.\n *\n * @param iterable An iterator to drop values from.\n * @param callbackFn A function to execute for each element produced by the iterator. It should return a falsy value to make the element yielded by the iterator helper, and a truthy value otherwise.\n * @returns An iterator that produces elements from the given iterator that don't satisfy the specified test.\n *\n * @example\n * ```typescript\n * import { dropWhile } from '@sapphire/iterator-utilities';\n *\n * const iterable = dropWhile([1, 2, 3, 4, 5], (value) => value < 3);\n * console.log([...iterable]);\n * // Output: [3, 4, 5]\n * ```\n *\n * @seealso {@link filter} or {@link takeWhile} for the opposite behavior.\n */\nexport function dropWhile<const ElementType, const FilteredType extends ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => element is FilteredType\n): IterableIterator<Exclude<ElementType, FilteredType>>;\nexport function dropWhile<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): IterableIterator<ElementType>;\nexport function* dropWhile<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): IterableIterator<ElementType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tif (!callbackFn(value, index++)) {\n\t\t\tyield value;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Determines if the elements of both iterators are equal.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable The iterator to compare.
|
|
7
|
+
* @param other The iterator to compare against.
|
|
8
|
+
* @returns Whether the two iterators are equal.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { equal } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* console.log(equal([1], [1]));
|
|
15
|
+
* // Output: true
|
|
16
|
+
* console.log(equal([1], [1, 2]));
|
|
17
|
+
* // Output: false
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
*
|
|
22
|
+
* This function consumes the entire iterator.
|
|
23
|
+
*/
|
|
24
|
+
declare function equal<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean;
|
|
25
|
+
|
|
26
|
+
export { equal as eq, equal };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
|
+
import { equalBy } from './equalBy.mjs';
|
|
3
|
+
|
|
4
|
+
function equal(iterable, other) {
|
|
5
|
+
return equalBy(iterable, other, (a, b) => a === b);
|
|
6
|
+
}
|
|
7
|
+
__name(equal, "equal");
|
|
8
|
+
|
|
9
|
+
export { equal as eq, equal };
|
|
10
|
+
//# sourceMappingURL=equal.mjs.map
|
|
11
|
+
//# sourceMappingURL=equal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/equal.ts"],"names":[],"mappings":";;;AAwBO,SAAS,KAAA,CAAyB,UAA2C,KAAiD,EAAA;AACpI,EAAA,OAAO,QAAQ,QAAU,EAAA,KAAA,EAAO,CAAC,CAAG,EAAA,CAAA,KAAM,MAAM,CAAC,CAAA,CAAA;AAClD,CAAA;AAFgB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA","file":"equal.mjs","sourcesContent":["import { equalBy } from './equalBy';\nimport type { IterableResolvable } from './from';\n\n/**\n * Determines if the elements of both iterators are equal.\n *\n * @param iterable The iterator to compare.\n * @param other The iterator to compare against.\n * @returns Whether the two iterators are equal.\n *\n * @example\n * ```typescript\n * import { equal } from '@sapphire/iterator-utilities';\n *\n * console.log(equal([1], [1]));\n * // Output: true\n * console.log(equal([1], [1, 2]));\n * // Output: false\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function equal<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean {\n\treturn equalBy(iterable, other, (a, b) => a === b);\n}\n\nexport { equal as eq };\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Determines if the elements of both iterators are equal with respect to the specified equality function.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable The iterator to compare.
|
|
7
|
+
* @param other The iterator to compare against.
|
|
8
|
+
* @returns Whether the two iterators are equal with respect to the specified equality function.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { equalBy } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const x = [1, 2, 3, 4];
|
|
15
|
+
* const y = [1, 4, 9, 16];
|
|
16
|
+
*
|
|
17
|
+
* console.log(equalBy(x, y, (a, b) => a * a === b));
|
|
18
|
+
* // Output: true
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
*
|
|
23
|
+
* This function consumes the entire iterator.
|
|
24
|
+
*/
|
|
25
|
+
declare function equalBy<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>, callbackFn: (x: ElementType, y: ElementType) => boolean): boolean;
|
|
26
|
+
|
|
27
|
+
export { equalBy as eqBy, equalBy };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
|
+
import { from } from './from.mjs';
|
|
3
|
+
import { assertFunction } from './shared/_assertFunction.mjs';
|
|
4
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
5
|
+
|
|
6
|
+
function equalBy(iterable, other, callbackFn) {
|
|
7
|
+
callbackFn = assertFunction(callbackFn);
|
|
8
|
+
const iterator1 = from(other);
|
|
9
|
+
for (const value0 of toIterableIterator(iterable)) {
|
|
10
|
+
const result1 = iterator1.next();
|
|
11
|
+
if (result1.done || !callbackFn(value0, result1.value)) return false;
|
|
12
|
+
}
|
|
13
|
+
return iterator1.next().done === true;
|
|
14
|
+
}
|
|
15
|
+
__name(equalBy, "equalBy");
|
|
16
|
+
|
|
17
|
+
export { equalBy as eqBy, equalBy };
|
|
18
|
+
//# sourceMappingURL=equalBy.mjs.map
|
|
19
|
+
//# sourceMappingURL=equalBy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/equalBy.ts"],"names":[],"mappings":";;;;;AA0BO,SAAS,OAAA,CACf,QACA,EAAA,KAAA,EACA,UACU,EAAA;AACV,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAM,MAAA,SAAA,GAAY,KAAK,KAAK,CAAA,CAAA;AAE5B,EAAW,KAAA,MAAA,MAAA,IAAU,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AAClD,IAAM,MAAA,OAAA,GAAU,UAAU,IAAK,EAAA,CAAA;AAC/B,IAAI,IAAA,OAAA,CAAQ,QAAQ,CAAC,UAAA,CAAW,QAAQ,OAAQ,CAAA,KAAK,GAAU,OAAA,KAAA,CAAA;AAAA,GAChE;AAEA,EAAO,OAAA,SAAA,CAAU,IAAK,EAAA,CAAE,IAAS,KAAA,IAAA,CAAA;AAClC,CAAA;AAfgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA","file":"equalBy.mjs","sourcesContent":["import { from, type IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Determines if the elements of both iterators are equal with respect to the specified equality function.\n *\n * @param iterable The iterator to compare.\n * @param other The iterator to compare against.\n * @returns Whether the two iterators are equal with respect to the specified equality function.\n *\n * @example\n * ```typescript\n * import { equalBy } from '@sapphire/iterator-utilities';\n *\n * const x = [1, 2, 3, 4];\n * const y = [1, 4, 9, 16];\n *\n * console.log(equalBy(x, y, (a, b) => a * a === b));\n * // Output: true\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function equalBy<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tother: IterableResolvable<ElementType>,\n\tcallbackFn: (x: ElementType, y: ElementType) => boolean\n): boolean {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tconst iterator1 = from(other);\n\n\tfor (const value0 of toIterableIterator(iterable)) {\n\t\tconst result1 = iterator1.next();\n\t\tif (result1.done || !callbackFn(value0, result1.value)) return false;\n\t}\n\n\treturn iterator1.next().done === true;\n}\n\nexport { equalBy as eqBy };\n"]}
|
|
@@ -19,4 +19,4 @@ import { IterableResolvable } from './from.mjs';
|
|
|
19
19
|
declare function filter<const ElementType, const FilteredType extends ElementType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => element is FilteredType): IterableIterator<FilteredType>;
|
|
20
20
|
declare function filter<const ElementType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => boolean): IterableIterator<ElementType>;
|
|
21
21
|
|
|
22
|
-
export { filter
|
|
22
|
+
export { filter };
|
package/dist/esm/lib/filter.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/filter.ts"],"names":[],"mappings":";;;;AA4BO,UAAU,MAAA,CAChB,UACA,UACgC,EAAA;AAChC,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,IAAA,IAAI,UAAW,CAAA,KAAA,EAAO,KAAO,EAAA,CAAA,EAAS,MAAA,KAAA,CAAA;AAAA,GACvC;AACD,CAAA;AAViB,MAAA,CAAA,MAAA,EAAA,QAAA,CAAA","file":"filter.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterable with the elements that pass the test implemented by the provided function.\n *\n * @param iterable The iterator to filter.\n * @param callbackFn A function to execute for each element produced by the iterator. It should return a truthy value to make the element yielded by the iterator helper, and a falsy value otherwise.\n * @returns An iterator that produces elements from the given iterator that satisfy the specified test.\n *\n * @example\n * ```typescript\n * import { filter } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...filter(iterable, (value) => value % 2 === 0)]);\n * // Output: [2, 4]\n * ```\n */\nexport function filter<const ElementType, const FilteredType extends ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => element is FilteredType\n): IterableIterator<FilteredType>;\nexport function filter<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): IterableIterator<ElementType>;\nexport function* filter<ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): IterableIterator<ElementType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tif (callbackFn(value, index++)) yield value;\n\t}\n}\n
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/filter.ts"],"names":[],"mappings":";;;;AA4BO,UAAU,MAAA,CAChB,UACA,UACgC,EAAA;AAChC,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,IAAA,IAAI,UAAW,CAAA,KAAA,EAAO,KAAO,EAAA,CAAA,EAAS,MAAA,KAAA,CAAA;AAAA,GACvC;AACD,CAAA;AAViB,MAAA,CAAA,MAAA,EAAA,QAAA,CAAA","file":"filter.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterable with the elements that pass the test implemented by the provided function.\n *\n * @param iterable The iterator to filter.\n * @param callbackFn A function to execute for each element produced by the iterator. It should return a truthy value to make the element yielded by the iterator helper, and a falsy value otherwise.\n * @returns An iterator that produces elements from the given iterator that satisfy the specified test.\n *\n * @example\n * ```typescript\n * import { filter } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...filter(iterable, (value) => value % 2 === 0)]);\n * // Output: [2, 4]\n * ```\n */\nexport function filter<const ElementType, const FilteredType extends ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => element is FilteredType\n): IterableIterator<FilteredType>;\nexport function filter<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): IterableIterator<ElementType>;\nexport function* filter<ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): IterableIterator<ElementType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tif (callbackFn(value, index++)) yield value;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterator which ends after the first `done` result from the original iterator.
|
|
5
|
+
*
|
|
6
|
+
* After an iterator returns a `done` result, future calls may or may not yield additional results again. This function
|
|
7
|
+
* adapts an iterator, ensuring that after a `done` result is given, it will always return a `done` result forever.
|
|
8
|
+
*
|
|
9
|
+
* @param iterable An iterator to fuse.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { fuse } from '@sapphire/iterator-utilities';
|
|
14
|
+
*
|
|
15
|
+
* const iterable = {
|
|
16
|
+
* state: 0,
|
|
17
|
+
* next() {
|
|
18
|
+
* const value = this.state;
|
|
19
|
+
* this.state += 1;
|
|
20
|
+
*
|
|
21
|
+
* return value % 2 === 0 //
|
|
22
|
+
* ? { done: false, value }
|
|
23
|
+
* : { done: true, value: undefined };
|
|
24
|
+
* }
|
|
25
|
+
* };
|
|
26
|
+
*
|
|
27
|
+
* // We can see our iterator going back and forth
|
|
28
|
+
* assert(iterable.next(), { done: false, value: 0 });
|
|
29
|
+
* assert(iterable.next(), { done: true, value: undefined });
|
|
30
|
+
* assert(iterable.next(), { done: false, value: 2 });
|
|
31
|
+
* assert(iterable.next(), { done: true, value: undefined });
|
|
32
|
+
*
|
|
33
|
+
* // However, once we fuse it...
|
|
34
|
+
* const fused = fuse(iterable);
|
|
35
|
+
*
|
|
36
|
+
* assert(fused.next(), { done: false, value: 4 });
|
|
37
|
+
* assert(fused.next(), { done: true, value: undefined });
|
|
38
|
+
*
|
|
39
|
+
* // It will always return a `done` result after the first time
|
|
40
|
+
* assert(fused.next(), { done: true, value: undefined });
|
|
41
|
+
* assert(fused.next(), { done: true, value: undefined });
|
|
42
|
+
* assert(fused.next(), { done: true, value: undefined });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function fuse<const ElementType>(iterable: IterableResolvable<ElementType>): IterableIterator<ElementType>;
|
|
46
|
+
|
|
47
|
+
export { fuse };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __name } from '../chunk-PAWJFY3S.mjs';
|
|
2
|
+
import { makeIterableIterator } from './shared/_makeIterableIterator.mjs';
|
|
3
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
4
|
+
|
|
5
|
+
function fuse(iterable) {
|
|
6
|
+
let ended = false;
|
|
7
|
+
const iterator = toIterableIterator(iterable);
|
|
8
|
+
return makeIterableIterator(() => {
|
|
9
|
+
if (ended) {
|
|
10
|
+
return { done: true, value: void 0 };
|
|
11
|
+
}
|
|
12
|
+
const result = iterator.next();
|
|
13
|
+
if (result.done) {
|
|
14
|
+
ended = true;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
__name(fuse, "fuse");
|
|
20
|
+
|
|
21
|
+
export { fuse };
|
|
22
|
+
//# sourceMappingURL=fuse.mjs.map
|
|
23
|
+
//# sourceMappingURL=fuse.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/fuse.ts"],"names":[],"mappings":";;;;AA8CO,SAAS,KAAwB,QAA0E,EAAA;AACjH,EAAA,IAAI,KAAQ,GAAA,KAAA,CAAA;AACZ,EAAM,MAAA,QAAA,GAAW,mBAAmB,QAAQ,CAAA,CAAA;AAC5C,EAAA,OAAO,qBAAqB,MAAM;AACjC,IAAA,IAAI,KAAO,EAAA;AACV,MAAA,OAAO,EAAE,IAAA,EAAM,IAAM,EAAA,KAAA,EAAO,KAAU,CAAA,EAAA,CAAA;AAAA,KACvC;AAEA,IAAM,MAAA,MAAA,GAAS,SAAS,IAAK,EAAA,CAAA;AAC7B,IAAA,IAAI,OAAO,IAAM,EAAA;AAChB,MAAQ,KAAA,GAAA,IAAA,CAAA;AAAA,KACT;AAEA,IAAO,OAAA,MAAA,CAAA;AAAA,GACP,CAAA,CAAA;AACF,CAAA;AAfgB,MAAA,CAAA,IAAA,EAAA,MAAA,CAAA","file":"fuse.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { makeIterableIterator } from './shared/_makeIterableIterator';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterator which ends after the first `done` result from the original iterator.\n *\n * After an iterator returns a `done` result, future calls may or may not yield additional results again. This function\n * adapts an iterator, ensuring that after a `done` result is given, it will always return a `done` result forever.\n *\n * @param iterable An iterator to fuse.\n *\n * @example\n * ```typescript\n * import { fuse } from '@sapphire/iterator-utilities';\n *\n * const iterable = {\n * state: 0,\n * next() {\n * const value = this.state;\n * this.state += 1;\n *\n * return value % 2 === 0 //\n * ? { done: false, value }\n * : { done: true, value: undefined };\n * }\n * };\n *\n * // We can see our iterator going back and forth\n * assert(iterable.next(), { done: false, value: 0 });\n * assert(iterable.next(), { done: true, value: undefined });\n * assert(iterable.next(), { done: false, value: 2 });\n * assert(iterable.next(), { done: true, value: undefined });\n *\n * // However, once we fuse it...\n * const fused = fuse(iterable);\n *\n * assert(fused.next(), { done: false, value: 4 });\n * assert(fused.next(), { done: true, value: undefined });\n *\n * // It will always return a `done` result after the first time\n * assert(fused.next(), { done: true, value: undefined });\n * assert(fused.next(), { done: true, value: undefined });\n * assert(fused.next(), { done: true, value: undefined });\n * ```\n */\nexport function fuse<const ElementType>(iterable: IterableResolvable<ElementType>): IterableIterator<ElementType> {\n\tlet ended = false;\n\tconst iterator = toIterableIterator(iterable);\n\treturn makeIterableIterator(() => {\n\t\tif (ended) {\n\t\t\treturn { done: true, value: undefined };\n\t\t}\n\n\t\tconst result = iterator.next();\n\t\tif (result.done) {\n\t\t\tended = true;\n\t\t}\n\n\t\treturn result;\n\t});\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Determines if the elements of `iterable` are {@link LexicographicComparison lexicographically} greater or equal than
|
|
5
|
+
* those of another.
|
|
6
|
+
*
|
|
7
|
+
* @param iterable The iterator to compare.
|
|
8
|
+
* @param other The iterator to compare against.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { greaterOrEqualThan } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const x = [1, 2, 3, 4];
|
|
15
|
+
* const y = [1, 4, 9, 16];
|
|
16
|
+
* console.log(greaterOrEqualThan([1], [1]));
|
|
17
|
+
* // Output: true
|
|
18
|
+
* console.log(greaterOrEqualThan([1], [1, 2]));
|
|
19
|
+
* // Output: false
|
|
20
|
+
* console.log(greaterOrEqualThan([1, 2], [1]));
|
|
21
|
+
* // Output: true
|
|
22
|
+
* console.log(greaterOrEqualThan([1, 2], [1, 2]));
|
|
23
|
+
* // Output: true
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
*
|
|
28
|
+
* This function consumes the entire iterator.
|
|
29
|
+
*/
|
|
30
|
+
declare function greaterOrEqualThan<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean;
|
|
31
|
+
|
|
32
|
+
export { greaterOrEqualThan as ge, greaterOrEqualThan };
|