@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.
Files changed (245) hide show
  1. package/dist/cjs/index.cjs +217 -0
  2. package/dist/cjs/index.d.cts +32 -9
  3. package/dist/cjs/lib/all.cjs +12 -0
  4. package/dist/cjs/lib/all.cjs.map +1 -0
  5. package/dist/cjs/lib/all.d.cts +2 -0
  6. package/dist/cjs/lib/any.cjs +12 -0
  7. package/dist/cjs/lib/any.cjs.map +1 -0
  8. package/dist/cjs/lib/any.d.cts +2 -0
  9. package/dist/cjs/lib/collect.cjs +12 -0
  10. package/dist/cjs/lib/collect.cjs.map +1 -0
  11. package/dist/cjs/lib/collect.d.cts +2 -0
  12. package/dist/cjs/lib/collectInto.cjs +17 -0
  13. package/dist/cjs/lib/collectInto.cjs.map +1 -0
  14. package/dist/cjs/lib/collectInto.d.cts +29 -0
  15. package/dist/cjs/lib/compare.cjs +15 -0
  16. package/dist/cjs/lib/compare.cjs.map +1 -0
  17. package/dist/cjs/lib/compare.d.cts +32 -0
  18. package/dist/cjs/lib/compareBy.cjs +26 -0
  19. package/dist/cjs/lib/compareBy.cjs.map +1 -0
  20. package/dist/cjs/lib/compareBy.d.cts +31 -0
  21. package/dist/cjs/lib/drop.cjs +0 -1
  22. package/dist/cjs/lib/drop.cjs.map +1 -1
  23. package/dist/cjs/lib/drop.d.cts +1 -1
  24. package/dist/cjs/lib/dropLast.cjs +0 -1
  25. package/dist/cjs/lib/dropLast.cjs.map +1 -1
  26. package/dist/cjs/lib/dropLast.d.cts +1 -1
  27. package/dist/cjs/lib/dropWhile.cjs +0 -1
  28. package/dist/cjs/lib/dropWhile.cjs.map +1 -1
  29. package/dist/cjs/lib/dropWhile.d.cts +1 -1
  30. package/dist/cjs/lib/equal.cjs +15 -0
  31. package/dist/cjs/lib/equal.cjs.map +1 -0
  32. package/dist/cjs/lib/equal.d.cts +26 -0
  33. package/dist/cjs/lib/equalBy.cjs +23 -0
  34. package/dist/cjs/lib/equalBy.cjs.map +1 -0
  35. package/dist/cjs/lib/equalBy.d.cts +27 -0
  36. package/dist/cjs/lib/filter.cjs +0 -1
  37. package/dist/cjs/lib/filter.cjs.map +1 -1
  38. package/dist/cjs/lib/filter.d.cts +1 -1
  39. package/dist/cjs/lib/fuse.cjs +26 -0
  40. package/dist/cjs/lib/fuse.cjs.map +1 -0
  41. package/dist/cjs/lib/fuse.d.cts +47 -0
  42. package/dist/cjs/lib/greaterOrEqualThan.cjs +17 -0
  43. package/dist/cjs/lib/greaterOrEqualThan.cjs.map +1 -0
  44. package/dist/cjs/lib/greaterOrEqualThan.d.cts +32 -0
  45. package/dist/cjs/lib/greaterThan.cjs +17 -0
  46. package/dist/cjs/lib/greaterThan.cjs.map +1 -0
  47. package/dist/cjs/lib/greaterThan.d.cts +32 -0
  48. package/dist/cjs/lib/indexOf.cjs +0 -1
  49. package/dist/cjs/lib/indexOf.cjs.map +1 -1
  50. package/dist/cjs/lib/indexOf.d.cts +1 -1
  51. package/dist/cjs/lib/inspect.cjs +25 -0
  52. package/dist/cjs/lib/inspect.cjs.map +1 -0
  53. package/dist/cjs/lib/inspect.d.cts +39 -0
  54. package/dist/cjs/lib/intersperse.cjs +35 -0
  55. package/dist/cjs/lib/intersperse.cjs.map +1 -0
  56. package/dist/cjs/lib/intersperse.d.cts +30 -0
  57. package/dist/cjs/lib/isSorted.cjs +15 -0
  58. package/dist/cjs/lib/isSorted.cjs.map +1 -0
  59. package/dist/cjs/lib/isSorted.d.cts +35 -0
  60. package/dist/cjs/lib/isSortedBy.cjs +26 -0
  61. package/dist/cjs/lib/isSortedBy.cjs.map +1 -0
  62. package/dist/cjs/lib/isSortedBy.d.cts +32 -0
  63. package/dist/cjs/lib/isSortedByKey.cjs +29 -0
  64. package/dist/cjs/lib/isSortedByKey.cjs.map +1 -0
  65. package/dist/cjs/lib/isSortedByKey.d.cts +30 -0
  66. package/dist/cjs/lib/lessOrEqualThan.cjs +17 -0
  67. package/dist/cjs/lib/lessOrEqualThan.cjs.map +1 -0
  68. package/dist/cjs/lib/lessOrEqualThan.d.cts +32 -0
  69. package/dist/cjs/lib/lessThan.cjs +17 -0
  70. package/dist/cjs/lib/lessThan.cjs.map +1 -0
  71. package/dist/cjs/lib/lessThan.d.cts +32 -0
  72. package/dist/cjs/lib/max.cjs +3 -7
  73. package/dist/cjs/lib/max.cjs.map +1 -1
  74. package/dist/cjs/lib/max.d.cts +8 -3
  75. package/dist/cjs/lib/maxBy.cjs +27 -0
  76. package/dist/cjs/lib/maxBy.cjs.map +1 -0
  77. package/dist/cjs/lib/maxBy.d.cts +31 -0
  78. package/dist/cjs/lib/maxByKey.cjs +32 -0
  79. package/dist/cjs/lib/maxByKey.cjs.map +1 -0
  80. package/dist/cjs/lib/maxByKey.d.cts +32 -0
  81. package/dist/cjs/lib/min.cjs +3 -7
  82. package/dist/cjs/lib/min.cjs.map +1 -1
  83. package/dist/cjs/lib/min.d.cts +8 -3
  84. package/dist/cjs/lib/minBy.cjs +27 -0
  85. package/dist/cjs/lib/minBy.cjs.map +1 -0
  86. package/dist/cjs/lib/minBy.d.cts +31 -0
  87. package/dist/cjs/lib/minByKey.cjs +32 -0
  88. package/dist/cjs/lib/minByKey.cjs.map +1 -0
  89. package/dist/cjs/lib/minByKey.d.cts +31 -0
  90. package/dist/cjs/lib/notEqual.cjs +15 -0
  91. package/dist/cjs/lib/notEqual.cjs.map +1 -0
  92. package/dist/cjs/lib/notEqual.d.cts +26 -0
  93. package/dist/cjs/lib/nth.cjs +12 -0
  94. package/dist/cjs/lib/nth.cjs.map +1 -0
  95. package/dist/cjs/lib/nth.d.cts +2 -0
  96. package/dist/cjs/lib/position.cjs +12 -0
  97. package/dist/cjs/lib/position.cjs.map +1 -0
  98. package/dist/cjs/lib/position.d.cts +2 -0
  99. package/dist/cjs/lib/reverse.cjs +2 -5
  100. package/dist/cjs/lib/reverse.cjs.map +1 -1
  101. package/dist/cjs/lib/shared/_compare.cjs +36 -0
  102. package/dist/cjs/lib/shared/_compare.cjs.map +1 -0
  103. package/dist/cjs/lib/shared/_compare.d.cts +20 -0
  104. package/dist/cjs/lib/shared/comparators.cjs +28 -0
  105. package/dist/cjs/lib/shared/comparators.cjs.map +1 -0
  106. package/dist/cjs/lib/shared/comparators.d.cts +34 -0
  107. package/dist/cjs/lib/skip.cjs +12 -0
  108. package/dist/cjs/lib/skip.cjs.map +1 -0
  109. package/dist/cjs/lib/skip.d.cts +2 -0
  110. package/dist/cjs/lib/skipLast.cjs +12 -0
  111. package/dist/cjs/lib/skipLast.cjs.map +1 -0
  112. package/dist/cjs/lib/skipLast.d.cts +2 -0
  113. package/dist/cjs/lib/skipWhile.cjs +12 -0
  114. package/dist/cjs/lib/skipWhile.cjs.map +1 -0
  115. package/dist/cjs/lib/skipWhile.d.cts +2 -0
  116. package/dist/cjs/lib/stepBy.cjs +29 -0
  117. package/dist/cjs/lib/stepBy.cjs.map +1 -0
  118. package/dist/cjs/lib/stepBy.d.cts +24 -0
  119. package/dist/cjs/lib/takeWhile.cjs +12 -0
  120. package/dist/cjs/lib/takeWhile.cjs.map +1 -0
  121. package/dist/cjs/lib/takeWhile.d.cts +2 -0
  122. package/dist/esm/index.d.mts +32 -9
  123. package/dist/esm/index.mjs +31 -0
  124. package/dist/esm/lib/all.d.mts +2 -0
  125. package/dist/esm/lib/all.mjs +4 -0
  126. package/dist/esm/lib/all.mjs.map +1 -0
  127. package/dist/esm/lib/any.d.mts +2 -0
  128. package/dist/esm/lib/any.mjs +4 -0
  129. package/dist/esm/lib/any.mjs.map +1 -0
  130. package/dist/esm/lib/collect.d.mts +2 -0
  131. package/dist/esm/lib/collect.mjs +4 -0
  132. package/dist/esm/lib/collect.mjs.map +1 -0
  133. package/dist/esm/lib/collectInto.d.mts +29 -0
  134. package/dist/esm/lib/collectInto.mjs +14 -0
  135. package/dist/esm/lib/collectInto.mjs.map +1 -0
  136. package/dist/esm/lib/compare.d.mts +32 -0
  137. package/dist/esm/lib/compare.mjs +12 -0
  138. package/dist/esm/lib/compare.mjs.map +1 -0
  139. package/dist/esm/lib/compareBy.d.mts +31 -0
  140. package/dist/esm/lib/compareBy.mjs +23 -0
  141. package/dist/esm/lib/compareBy.mjs.map +1 -0
  142. package/dist/esm/lib/drop.d.mts +1 -1
  143. package/dist/esm/lib/drop.mjs +1 -1
  144. package/dist/esm/lib/drop.mjs.map +1 -1
  145. package/dist/esm/lib/dropLast.d.mts +1 -1
  146. package/dist/esm/lib/dropLast.mjs +1 -1
  147. package/dist/esm/lib/dropLast.mjs.map +1 -1
  148. package/dist/esm/lib/dropWhile.d.mts +1 -1
  149. package/dist/esm/lib/dropWhile.mjs +1 -1
  150. package/dist/esm/lib/dropWhile.mjs.map +1 -1
  151. package/dist/esm/lib/equal.d.mts +26 -0
  152. package/dist/esm/lib/equal.mjs +11 -0
  153. package/dist/esm/lib/equal.mjs.map +1 -0
  154. package/dist/esm/lib/equalBy.d.mts +27 -0
  155. package/dist/esm/lib/equalBy.mjs +19 -0
  156. package/dist/esm/lib/equalBy.mjs.map +1 -0
  157. package/dist/esm/lib/filter.d.mts +1 -1
  158. package/dist/esm/lib/filter.mjs +1 -1
  159. package/dist/esm/lib/filter.mjs.map +1 -1
  160. package/dist/esm/lib/fuse.d.mts +47 -0
  161. package/dist/esm/lib/fuse.mjs +23 -0
  162. package/dist/esm/lib/fuse.mjs.map +1 -0
  163. package/dist/esm/lib/greaterOrEqualThan.d.mts +32 -0
  164. package/dist/esm/lib/greaterOrEqualThan.mjs +13 -0
  165. package/dist/esm/lib/greaterOrEqualThan.mjs.map +1 -0
  166. package/dist/esm/lib/greaterThan.d.mts +32 -0
  167. package/dist/esm/lib/greaterThan.mjs +13 -0
  168. package/dist/esm/lib/greaterThan.mjs.map +1 -0
  169. package/dist/esm/lib/indexOf.d.mts +1 -1
  170. package/dist/esm/lib/indexOf.mjs +1 -1
  171. package/dist/esm/lib/indexOf.mjs.map +1 -1
  172. package/dist/esm/lib/inspect.d.mts +39 -0
  173. package/dist/esm/lib/inspect.mjs +22 -0
  174. package/dist/esm/lib/inspect.mjs.map +1 -0
  175. package/dist/esm/lib/intersperse.d.mts +30 -0
  176. package/dist/esm/lib/intersperse.mjs +32 -0
  177. package/dist/esm/lib/intersperse.mjs.map +1 -0
  178. package/dist/esm/lib/isSorted.d.mts +35 -0
  179. package/dist/esm/lib/isSorted.mjs +12 -0
  180. package/dist/esm/lib/isSorted.mjs.map +1 -0
  181. package/dist/esm/lib/isSortedBy.d.mts +32 -0
  182. package/dist/esm/lib/isSortedBy.mjs +23 -0
  183. package/dist/esm/lib/isSortedBy.mjs.map +1 -0
  184. package/dist/esm/lib/isSortedByKey.d.mts +30 -0
  185. package/dist/esm/lib/isSortedByKey.mjs +26 -0
  186. package/dist/esm/lib/isSortedByKey.mjs.map +1 -0
  187. package/dist/esm/lib/lessOrEqualThan.d.mts +32 -0
  188. package/dist/esm/lib/lessOrEqualThan.mjs +13 -0
  189. package/dist/esm/lib/lessOrEqualThan.mjs.map +1 -0
  190. package/dist/esm/lib/lessThan.d.mts +32 -0
  191. package/dist/esm/lib/lessThan.mjs +13 -0
  192. package/dist/esm/lib/lessThan.mjs.map +1 -0
  193. package/dist/esm/lib/max.d.mts +8 -3
  194. package/dist/esm/lib/max.mjs +3 -7
  195. package/dist/esm/lib/max.mjs.map +1 -1
  196. package/dist/esm/lib/maxBy.d.mts +31 -0
  197. package/dist/esm/lib/maxBy.mjs +24 -0
  198. package/dist/esm/lib/maxBy.mjs.map +1 -0
  199. package/dist/esm/lib/maxByKey.d.mts +32 -0
  200. package/dist/esm/lib/maxByKey.mjs +29 -0
  201. package/dist/esm/lib/maxByKey.mjs.map +1 -0
  202. package/dist/esm/lib/min.d.mts +8 -3
  203. package/dist/esm/lib/min.mjs +3 -7
  204. package/dist/esm/lib/min.mjs.map +1 -1
  205. package/dist/esm/lib/minBy.d.mts +31 -0
  206. package/dist/esm/lib/minBy.mjs +24 -0
  207. package/dist/esm/lib/minBy.mjs.map +1 -0
  208. package/dist/esm/lib/minByKey.d.mts +31 -0
  209. package/dist/esm/lib/minByKey.mjs +29 -0
  210. package/dist/esm/lib/minByKey.mjs.map +1 -0
  211. package/dist/esm/lib/notEqual.d.mts +26 -0
  212. package/dist/esm/lib/notEqual.mjs +11 -0
  213. package/dist/esm/lib/notEqual.mjs.map +1 -0
  214. package/dist/esm/lib/nth.d.mts +2 -0
  215. package/dist/esm/lib/nth.mjs +4 -0
  216. package/dist/esm/lib/nth.mjs.map +1 -0
  217. package/dist/esm/lib/position.d.mts +2 -0
  218. package/dist/esm/lib/position.mjs +4 -0
  219. package/dist/esm/lib/position.mjs.map +1 -0
  220. package/dist/esm/lib/reverse.mjs +2 -5
  221. package/dist/esm/lib/reverse.mjs.map +1 -1
  222. package/dist/esm/lib/shared/_compare.d.mts +20 -0
  223. package/dist/esm/lib/shared/_compare.mjs +30 -0
  224. package/dist/esm/lib/shared/_compare.mjs.map +1 -0
  225. package/dist/esm/lib/shared/comparators.d.mts +34 -0
  226. package/dist/esm/lib/shared/comparators.mjs +21 -0
  227. package/dist/esm/lib/shared/comparators.mjs.map +1 -0
  228. package/dist/esm/lib/skip.d.mts +2 -0
  229. package/dist/esm/lib/skip.mjs +4 -0
  230. package/dist/esm/lib/skip.mjs.map +1 -0
  231. package/dist/esm/lib/skipLast.d.mts +2 -0
  232. package/dist/esm/lib/skipLast.mjs +4 -0
  233. package/dist/esm/lib/skipLast.mjs.map +1 -0
  234. package/dist/esm/lib/skipWhile.d.mts +2 -0
  235. package/dist/esm/lib/skipWhile.mjs +4 -0
  236. package/dist/esm/lib/skipWhile.mjs.map +1 -0
  237. package/dist/esm/lib/stepBy.d.mts +24 -0
  238. package/dist/esm/lib/stepBy.mjs +26 -0
  239. package/dist/esm/lib/stepBy.mjs.map +1 -0
  240. package/dist/esm/lib/takeWhile.d.mts +2 -0
  241. package/dist/esm/lib/takeWhile.mjs +4 -0
  242. package/dist/esm/lib/takeWhile.mjs.map +1 -0
  243. package/dist/iife/index.global.js +391 -49
  244. package/dist/iife/index.global.js.map +1 -1
  245. package/package.json +292 -22
@@ -0,0 +1,30 @@
1
+ import { IterableResolvable } from './from.cjs';
2
+
3
+ /**
4
+ * Creates a new iterator which places `separator` between adjacent items of the original iterator.
5
+ *
6
+ * @param iterable An iterator to map over.
7
+ * @param separator The separator to place between adjacent items.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { intersperse } from '@sapphire/iterator-utilities';
12
+ *
13
+ * const iterable = [0, 1, 2];
14
+ * console.log([...intersperse(iterable, 100)]);
15
+ * // Output: [0, 100, 1, 100, 2]
16
+ * ```
17
+ *
18
+ * @example
19
+ * `intersperse` can be very useful to join an iterator's items using a common element:
20
+ * ```typescript
21
+ * import { intersperse } from '@sapphire/iterator-utilities';
22
+ *
23
+ * const iterable = ['Hello', 'World', '!'];
24
+ * console.log([...intersperse(iterable, ', ')].join(''));
25
+ * // Output: 'Hello, World, !'
26
+ * ```
27
+ */
28
+ declare function intersperse<const ElementType>(iterable: IterableResolvable<ElementType>, separator: ElementType): IterableIterator<ElementType>;
29
+
30
+ export { intersperse };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var isSortedBy_cjs = require('./isSortedBy.cjs');
4
+ var comparators_cjs = require('./shared/comparators.cjs');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ function isSorted(iterable) {
9
+ return isSortedBy_cjs.isSortedBy(iterable, comparators_cjs.defaultCompare);
10
+ }
11
+ __name(isSorted, "isSorted");
12
+
13
+ exports.isSorted = isSorted;
14
+ //# sourceMappingURL=isSorted.cjs.map
15
+ //# sourceMappingURL=isSorted.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/isSorted.ts"],"names":["isSortedBy","defaultCompare"],"mappings":";;;;;;;AAmCO,SAAS,SAA4B,QAAoD,EAAA;AAC/F,EAAO,OAAAA,yBAAA,CAAW,UAAUC,8BAAc,CAAA,CAAA;AAC3C,CAAA;AAFgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"isSorted.cjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { isSortedBy } from './isSortedBy';\nimport type { isSortedByKey } from './isSortedByKey';\nimport { defaultCompare } from './shared/comparators';\n\n/**\n * Checks if the elements of this iterator are sorted in ascending order.\n *\n * That is, for each element `a` and its following element `b`, `a <= b` must hold. If the iterator yields exactly zero\n * or one element, `true` is returned.\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 isSortedBy} instead.\n *\n * @seealso {@link isSortedBy} for a version that allows custom comparators.\n * @seealso {@link isSortedByKey} for a version that allows custom key extractors.\n *\n * @param iterable The iterator to compare.\n *\n * @example\n * ```typescript\n * import { isSorted } from '@sapphire/iterator-utilities';\n *\n * assert(isSorted([1, 2, 2, 9]);\n * assert(!isSorted([1, 3, 2, 4]);\n *\n * assert(isSorted([0]);\n * assert(isSorted([]);\n * assert(isSorted([0, 1, NaN]);\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function isSorted<const ElementType>(iterable: IterableResolvable<ElementType>): boolean {\n\treturn isSortedBy(iterable, defaultCompare);\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { IterableResolvable } from './from.cjs';
2
+
3
+ /**
4
+ * Checks if the elements of this iterator are sorted in ascending order.
5
+ *
6
+ * That is, for each element `a` and its following element `b`, `a <= b` must hold. If the iterator yields exactly zero
7
+ * or one element, `true` is returned.
8
+ *
9
+ * This function uses the default comparator (lexicographically), which means it will compare the elements as strings.
10
+ * If this is undesirable, use {@link isSortedBy} instead.
11
+ *
12
+ * @seealso {@link isSortedBy} for a version that allows custom comparators.
13
+ * @seealso {@link isSortedByKey} for a version that allows custom key extractors.
14
+ *
15
+ * @param iterable The iterator to compare.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { isSorted } from '@sapphire/iterator-utilities';
20
+ *
21
+ * assert(isSorted([1, 2, 2, 9]);
22
+ * assert(!isSorted([1, 3, 2, 4]);
23
+ *
24
+ * assert(isSorted([0]);
25
+ * assert(isSorted([]);
26
+ * assert(isSorted([0, 1, NaN]);
27
+ * ```
28
+ *
29
+ * @remarks
30
+ *
31
+ * This function consumes the entire iterator.
32
+ */
33
+ declare function isSorted<const ElementType>(iterable: IterableResolvable<ElementType>): boolean;
34
+
35
+ export { isSorted };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ var _assertFunction_cjs = require('./shared/_assertFunction.cjs');
4
+ var _compare_cjs = require('./shared/_compare.cjs');
5
+ var toIterableIterator_cjs = require('./toIterableIterator.cjs');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ function isSortedBy(iterable, comparator) {
10
+ comparator = _assertFunction_cjs.assertFunction(comparator);
11
+ const iterator = toIterableIterator_cjs.toIterableIterator(iterable);
12
+ const result = iterator.next();
13
+ if (result.done) return true;
14
+ let previous = result.value;
15
+ for (const current of iterator) {
16
+ const comparison = _compare_cjs.compareIteratorElements(previous, current, comparator);
17
+ if (_compare_cjs.orderingIsGreater(comparison)) return false;
18
+ previous = current;
19
+ }
20
+ return true;
21
+ }
22
+ __name(isSortedBy, "isSortedBy");
23
+
24
+ exports.isSortedBy = isSortedBy;
25
+ //# sourceMappingURL=isSortedBy.cjs.map
26
+ //# sourceMappingURL=isSortedBy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/isSortedBy.ts"],"names":["assertFunction","toIterableIterator","compareIteratorElements","orderingIsGreater"],"mappings":";;;;;;;;AAiCO,SAAS,UAAA,CAA8B,UAA2C,UAAuD,EAAA;AAC/I,EAAA,UAAA,GAAaA,mCAAe,UAAU,CAAA,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAWC,0CAAmB,QAAQ,CAAA,CAAA;AAC5C,EAAM,MAAA,MAAA,GAAS,SAAS,IAAK,EAAA,CAAA;AAC7B,EAAI,IAAA,MAAA,CAAO,MAAa,OAAA,IAAA,CAAA;AAExB,EAAA,IAAI,WAAW,MAAO,CAAA,KAAA,CAAA;AACtB,EAAA,KAAA,MAAW,WAAW,QAAU,EAAA;AAC/B,IAAA,MAAM,UAAa,GAAAC,oCAAA,CAAqC,QAAU,EAAA,OAAA,EAAS,UAAU,CAAA,CAAA;AACrF,IAAI,IAAAC,8BAAA,CAAkB,UAAU,CAAA,EAAU,OAAA,KAAA,CAAA;AAE1C,IAAW,QAAA,GAAA,OAAA,CAAA;AAAA,GACZ;AAEA,EAAO,OAAA,IAAA,CAAA;AACR,CAAA;AAhBgB,MAAA,CAAA,UAAA,EAAA,YAAA,CAAA","file":"isSortedBy.cjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport type { isSorted } from './isSorted';\nimport type { isSortedByKey } from './isSortedByKey';\nimport { assertFunction } from './shared/_assertFunction';\nimport { compareIteratorElements, orderingIsGreater, type CompareByComparator } from './shared/_compare';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Checks if the elements of this iterator are sorted using the given comparator function.\n *\n * @seealso {@link isSorted} for a version that uses the default comparator.\n * @seealso {@link isSortedByKey} for a version that allows custom key extractors.\n *\n * @param iterable The iterator to compare.\n *\n * @example\n * ```typescript\n * import { ascNumber, isSortedBy } from '@sapphire/iterator-utilities';\n *\n * assert(isSortedBy([1, 2, 2, 9], ascNumber));\n * assert(!isSortedBy([1, 2, 2, 9], ascNumber));\n *\n * assert(isSortedBy([0], () => true));\n * assert(isSortedBy([0], () => false));\n *\n * assert(isSortedBy([], () => true));\n * assert(isSortedBy([], () => false));\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function isSortedBy<const ElementType>(iterable: IterableResolvable<ElementType>, comparator: CompareByComparator<ElementType>): boolean {\n\tcomparator = assertFunction(comparator);\n\n\tconst iterator = toIterableIterator(iterable);\n\tconst result = iterator.next();\n\tif (result.done) return true;\n\n\tlet previous = result.value;\n\tfor (const current of iterator) {\n\t\tconst comparison = compareIteratorElements<ElementType>(previous, current, comparator);\n\t\tif (orderingIsGreater(comparison)) return false;\n\n\t\tprevious = current;\n\t}\n\n\treturn true;\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import { IterableResolvable } from './from.cjs';
2
+ import { CompareByComparator } from './shared/_compare.js';
3
+
4
+ /**
5
+ * Checks if the elements of this iterator are sorted using the given comparator function.
6
+ *
7
+ * @seealso {@link isSorted} for a version that uses the default comparator.
8
+ * @seealso {@link isSortedByKey} for a version that allows custom key extractors.
9
+ *
10
+ * @param iterable The iterator to compare.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { ascNumber, isSortedBy } from '@sapphire/iterator-utilities';
15
+ *
16
+ * assert(isSortedBy([1, 2, 2, 9], ascNumber));
17
+ * assert(!isSortedBy([1, 2, 2, 9], ascNumber));
18
+ *
19
+ * assert(isSortedBy([0], () => true));
20
+ * assert(isSortedBy([0], () => false));
21
+ *
22
+ * assert(isSortedBy([], () => true));
23
+ * assert(isSortedBy([], () => false));
24
+ * ```
25
+ *
26
+ * @remarks
27
+ *
28
+ * This function consumes the entire iterator.
29
+ */
30
+ declare function isSortedBy<const ElementType>(iterable: IterableResolvable<ElementType>, comparator: CompareByComparator<ElementType>): boolean;
31
+
32
+ export { isSortedBy };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var _assertFunction_cjs = require('./shared/_assertFunction.cjs');
4
+ var _compare_cjs = require('./shared/_compare.cjs');
5
+ var comparators_cjs = require('./shared/comparators.cjs');
6
+ var toIterableIterator_cjs = require('./toIterableIterator.cjs');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ function isSortedByKey(iterable, callbackFn, comparator = comparators_cjs.defaultCompare) {
11
+ callbackFn = _assertFunction_cjs.assertFunction(callbackFn);
12
+ const iterator = toIterableIterator_cjs.toIterableIterator(iterable);
13
+ const result = iterator.next();
14
+ if (result.done) return true;
15
+ let previousKey = callbackFn(result.value, 0);
16
+ let index = 1;
17
+ for (const current of iterator) {
18
+ const currentKey = callbackFn(current, index++);
19
+ const comparison = _compare_cjs.compareIteratorElements(previousKey, currentKey, comparator);
20
+ if (_compare_cjs.orderingIsGreater(comparison)) return false;
21
+ previousKey = currentKey;
22
+ }
23
+ return true;
24
+ }
25
+ __name(isSortedByKey, "isSortedByKey");
26
+
27
+ exports.isSortedByKey = isSortedByKey;
28
+ //# sourceMappingURL=isSortedByKey.cjs.map
29
+ //# sourceMappingURL=isSortedByKey.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/isSortedByKey.ts"],"names":["defaultCompare","assertFunction","toIterableIterator","compareIteratorElements","orderingIsGreater"],"mappings":";;;;;;;;;AAgCO,SAAS,aACf,CAAA,QAAA,EACA,UACA,EAAA,UAAA,GAA8CA,8BACpC,EAAA;AACV,EAAA,UAAA,GAAaC,mCAAe,UAAU,CAAA,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAWC,0CAAmB,QAAQ,CAAA,CAAA;AAC5C,EAAM,MAAA,MAAA,GAAS,SAAS,IAAK,EAAA,CAAA;AAC7B,EAAI,IAAA,MAAA,CAAO,MAAa,OAAA,IAAA,CAAA;AAExB,EAAA,IAAI,WAAc,GAAA,UAAA,CAAW,MAAO,CAAA,KAAA,EAAO,CAAC,CAAA,CAAA;AAC5C,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAA,KAAA,MAAW,WAAW,QAAU,EAAA;AAC/B,IAAM,MAAA,UAAA,GAAa,UAAW,CAAA,OAAA,EAAS,KAAO,EAAA,CAAA,CAAA;AAC9C,IAAA,MAAM,UAAa,GAAAC,oCAAA,CAAoC,WAAa,EAAA,UAAA,EAAY,UAAU,CAAA,CAAA;AAC1F,IAAI,IAAAC,8BAAA,CAAkB,UAAU,CAAA,EAAU,OAAA,KAAA,CAAA;AAE1C,IAAc,WAAA,GAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAO,OAAA,IAAA,CAAA;AACR,CAAA;AAtBgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA","file":"isSortedByKey.cjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport type { isSorted } from './isSorted';\nimport type { isSortedBy } from './isSortedBy';\nimport { assertFunction } from './shared/_assertFunction';\nimport { compareIteratorElements, orderingIsGreater, type CompareByComparator } from './shared/_compare';\nimport { defaultCompare } from './shared/comparators';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Checks if the elements of this iterator are sorted using the given key extraction function.\n *\n * Instead of comparing the iterator's elements directly, this function compares the keys of the elements, as determined\n * by `callbackFn`. Apart from that, it's equivalent to {@link isSorted}; see its documentation for more information.\n *\n * @seealso {@link isSorted} for a version that uses the default comparator.\n * @seealso {@link isSortedBy} for a version that allows custom comparators.\n *\n * @param iterable The iterator to compare.\n * @param callbackFn The function to extract the key from an element.\n *\n * @example\n * ```typescript\n * import { isSortedByKey } from '@sapphire/iterator-utilities';\n *\n * assert(isSortedByKey(['c', 'bb', 'aaa'], (s) => s.length));\n * assert(!isSortedBy([-2, -1, 0, 3], (n) => Math.abs(n)));\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function isSortedByKey<const ElementType, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (a: ElementType, index: number) => MappedType,\n\tcomparator: CompareByComparator<MappedType> = defaultCompare\n): boolean {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tconst iterator = toIterableIterator(iterable);\n\tconst result = iterator.next();\n\tif (result.done) return true;\n\n\tlet previousKey = callbackFn(result.value, 0);\n\tlet index = 1;\n\tfor (const current of iterator) {\n\t\tconst currentKey = callbackFn(current, index++);\n\t\tconst comparison = compareIteratorElements<MappedType>(previousKey, currentKey, comparator);\n\t\tif (orderingIsGreater(comparison)) return false;\n\n\t\tpreviousKey = currentKey;\n\t}\n\n\treturn true;\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { IterableResolvable } from './from.cjs';
2
+ import { CompareByComparator } from './shared/_compare.js';
3
+
4
+ /**
5
+ * Checks if the elements of this iterator are sorted using the given key extraction function.
6
+ *
7
+ * Instead of comparing the iterator's elements directly, this function compares the keys of the elements, as determined
8
+ * by `callbackFn`. Apart from that, it's equivalent to {@link isSorted}; see its documentation for more information.
9
+ *
10
+ * @seealso {@link isSorted} for a version that uses the default comparator.
11
+ * @seealso {@link isSortedBy} for a version that allows custom comparators.
12
+ *
13
+ * @param iterable The iterator to compare.
14
+ * @param callbackFn The function to extract the key from an element.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { isSortedByKey } from '@sapphire/iterator-utilities';
19
+ *
20
+ * assert(isSortedByKey(['c', 'bb', 'aaa'], (s) => s.length));
21
+ * assert(!isSortedBy([-2, -1, 0, 3], (n) => Math.abs(n)));
22
+ * ```
23
+ *
24
+ * @remarks
25
+ *
26
+ * This function consumes the entire iterator.
27
+ */
28
+ declare function isSortedByKey<const ElementType, const MappedType>(iterable: IterableResolvable<ElementType>, callbackFn: (a: ElementType, index: number) => MappedType, comparator?: CompareByComparator<MappedType>): boolean;
29
+
30
+ export { isSortedByKey };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var compare_cjs = require('./compare.cjs');
4
+ var _compare_cjs = require('./shared/_compare.cjs');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ function lessOrEqualThan(iterable, other) {
9
+ const result = compare_cjs.compare(iterable, other);
10
+ return !_compare_cjs.orderingIsGreater(result);
11
+ }
12
+ __name(lessOrEqualThan, "lessOrEqualThan");
13
+
14
+ exports.le = lessOrEqualThan;
15
+ exports.lessOrEqualThan = lessOrEqualThan;
16
+ //# sourceMappingURL=lessOrEqualThan.cjs.map
17
+ //# sourceMappingURL=lessOrEqualThan.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/lessOrEqualThan.ts"],"names":["compare","orderingIsGreater"],"mappings":";;;;;;;AA+BO,SAAS,eAAA,CAAmC,UAA2C,KAAiD,EAAA;AAC9I,EAAM,MAAA,MAAA,GAASA,mBAAQ,CAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AACtC,EAAO,OAAA,CAACC,+BAAkB,MAAM,CAAA,CAAA;AACjC,CAAA;AAHgB,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA","file":"lessOrEqualThan.cjs","sourcesContent":["import { compare } from './compare';\nimport type { IterableResolvable } from './from';\nimport { orderingIsGreater, type LexicographicComparison } from './shared/_compare';\n\n/**\n * Determines if the elements of `iterable` are {@link LexicographicComparison lexicographically} less or equal than\n * those of another.\n *\n * @param iterable The iterator to compare.\n * @param other The iterator to compare against.\n *\n * @example\n * ```typescript\n * import { lessOrEqualThan } from '@sapphire/iterator-utilities';\n *\n * const x = [1, 2, 3, 4];\n * const y = [1, 4, 9, 16];\n * console.log(lessOrEqualThan([1], [1]));\n * // Output: false\n * console.log(lessOrEqualThan([1], [1, 2]));\n * // Output: true\n * console.log(lessOrEqualThan([1, 2], [1]));\n * // Output: false\n * console.log(lessOrEqualThan([1, 2], [1, 2]));\n * // Output: true\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function lessOrEqualThan<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean {\n\tconst result = compare(iterable, other);\n\treturn !orderingIsGreater(result);\n}\n\nexport { lessOrEqualThan as le };\n"]}
@@ -0,0 +1,32 @@
1
+ import { IterableResolvable } from './from.cjs';
2
+
3
+ /**
4
+ * Determines if the elements of `iterable` are {@link LexicographicComparison lexicographically} less 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 { lessOrEqualThan } from '@sapphire/iterator-utilities';
13
+ *
14
+ * const x = [1, 2, 3, 4];
15
+ * const y = [1, 4, 9, 16];
16
+ * console.log(lessOrEqualThan([1], [1]));
17
+ * // Output: false
18
+ * console.log(lessOrEqualThan([1], [1, 2]));
19
+ * // Output: true
20
+ * console.log(lessOrEqualThan([1, 2], [1]));
21
+ * // Output: false
22
+ * console.log(lessOrEqualThan([1, 2], [1, 2]));
23
+ * // Output: true
24
+ * ```
25
+ *
26
+ * @remarks
27
+ *
28
+ * This function consumes the entire iterator.
29
+ */
30
+ declare function lessOrEqualThan<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean;
31
+
32
+ export { lessOrEqualThan as le, lessOrEqualThan };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var compare_cjs = require('./compare.cjs');
4
+ var _compare_cjs = require('./shared/_compare.cjs');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ function lessThan(iterable, other) {
9
+ const result = compare_cjs.compare(iterable, other);
10
+ return _compare_cjs.orderingIsLess(result);
11
+ }
12
+ __name(lessThan, "lessThan");
13
+
14
+ exports.lessThan = lessThan;
15
+ exports.lt = lessThan;
16
+ //# sourceMappingURL=lessThan.cjs.map
17
+ //# sourceMappingURL=lessThan.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/lessThan.ts"],"names":["compare","orderingIsLess"],"mappings":";;;;;;;AA+BO,SAAS,QAAA,CAA4B,UAA2C,KAAiD,EAAA;AACvI,EAAM,MAAA,MAAA,GAASA,mBAAQ,CAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AACtC,EAAA,OAAOC,4BAAe,MAAM,CAAA,CAAA;AAC7B,CAAA;AAHgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"lessThan.cjs","sourcesContent":["import { compare } from './compare';\nimport type { IterableResolvable } from './from';\nimport { orderingIsLess, type LexicographicComparison } from './shared/_compare';\n\n/**\n * Determines if the elements of `iterable` are {@link LexicographicComparison lexicographically} less than those of\n * another.\n *\n * @param iterable The iterator to compare.\n * @param other The iterator to compare against.\n *\n * @example\n * ```typescript\n * import { lessThan } from '@sapphire/iterator-utilities';\n *\n * const x = [1, 2, 3, 4];\n * const y = [1, 4, 9, 16];\n * console.log(lessThan([1], [1]));\n * // Output: false\n * console.log(lessThan([1], [1, 2]));\n * // Output: true\n * console.log(lessThan([1, 2], [1]));\n * // Output: false\n * console.log(lessThan([1, 2], [1, 2]));\n * // Output: false\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function lessThan<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean {\n\tconst result = compare(iterable, other);\n\treturn orderingIsLess(result);\n}\n\nexport { lessThan as lt };\n"]}
@@ -0,0 +1,32 @@
1
+ import { IterableResolvable } from './from.cjs';
2
+
3
+ /**
4
+ * Determines if the elements of `iterable` are {@link LexicographicComparison lexicographically} less than those of
5
+ * another.
6
+ *
7
+ * @param iterable The iterator to compare.
8
+ * @param other The iterator to compare against.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { lessThan } from '@sapphire/iterator-utilities';
13
+ *
14
+ * const x = [1, 2, 3, 4];
15
+ * const y = [1, 4, 9, 16];
16
+ * console.log(lessThan([1], [1]));
17
+ * // Output: false
18
+ * console.log(lessThan([1], [1, 2]));
19
+ * // Output: true
20
+ * console.log(lessThan([1, 2], [1]));
21
+ * // Output: false
22
+ * console.log(lessThan([1, 2], [1, 2]));
23
+ * // Output: false
24
+ * ```
25
+ *
26
+ * @remarks
27
+ *
28
+ * This function consumes the entire iterator.
29
+ */
30
+ declare function lessThan<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean;
31
+
32
+ export { lessThan, lessThan as lt };
@@ -1,16 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var map_cjs = require('./map.cjs');
4
- var _toNumberOrThrow_cjs = require('./shared/_toNumberOrThrow.cjs');
3
+ var maxBy_cjs = require('./maxBy.cjs');
4
+ var comparators_cjs = require('./shared/comparators.cjs');
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
8
  function max(iterable) {
9
- let max2 = null;
10
- for (const value of map_cjs.map(iterable, _toNumberOrThrow_cjs.toNumberOrThrow)) {
11
- if (max2 === null || value > max2) max2 = value;
12
- }
13
- return max2;
9
+ return maxBy_cjs.maxBy(iterable, comparators_cjs.defaultCompare);
14
10
  }
15
11
  __name(max, "max");
16
12
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/max.ts"],"names":["max","map","toNumberOrThrow"],"mappings":";;;;;;;AAuBO,SAAS,IAAI,QAA+D,EAAA;AAClF,EAAA,IAAIA,IAAqB,GAAA,IAAA,CAAA;AACzB,EAAA,KAAA,MAAW,KAAS,IAAAC,WAAA,CAAI,QAAU,EAAAC,oCAAe,CAAG,EAAA;AACnD,IAAA,IAAIF,IAAQ,KAAA,IAAA,IAAQ,KAAQA,GAAAA,IAAAA,EAAKA,IAAM,GAAA,KAAA,CAAA;AAAA,GACxC;AAEA,EAAOA,OAAAA,IAAAA,CAAAA;AACR,CAAA;AAPgB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"max.cjs","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"]}
1
+ {"version":3,"sources":["../../../src/lib/max.ts"],"names":["maxBy","defaultCompare"],"mappings":";;;;;;;AA8BO,SAAS,IAAuB,QAA+D,EAAA;AACrG,EAAO,OAAAA,eAAA,CAAM,UAAUC,8BAAc,CAAA,CAAA;AACtC,CAAA;AAFgB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"max.cjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { maxBy } from './maxBy';\nimport type { maxByKey } from './maxByKey';\nimport { defaultCompare } from './shared/comparators';\n\n/**\n * Consumes the iterable and returns the highest number element. If the iterable is empty, it returns `null`.\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 maxBy} instead.\n *\n * @seealso {@link maxBy} for a version that allows custom comparators.\n * @seealso {@link maxByKey} for a version that allows custom key extractors.\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<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | null {\n\treturn maxBy(iterable, defaultCompare);\n}\n"]}
@@ -1,8 +1,13 @@
1
1
  import { IterableResolvable } from './from.cjs';
2
- import { NumberResolvable } from './shared/_toNumberOrThrow.js';
3
2
 
4
3
  /**
5
- * Consumes the iterable and returns the highest number element. If the iterable is empty, or contains only non-number values, it returns `null`.
4
+ * Consumes the iterable and returns the highest number element. If the iterable is empty, it returns `null`.
5
+ *
6
+ * This function uses the default comparator (lexicographically), which means it will compare the elements as strings.
7
+ * If this is undesirable, use {@link maxBy} instead.
8
+ *
9
+ * @seealso {@link maxBy} for a version that allows custom comparators.
10
+ * @seealso {@link maxByKey} for a version that allows custom key extractors.
6
11
  *
7
12
  * @param iterable An iterator of number values to determine the maximum value of.
8
13
  * @returns The maximum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.
@@ -20,6 +25,6 @@ import { NumberResolvable } from './shared/_toNumberOrThrow.js';
20
25
  *
21
26
  * This function consumes the entire iterator.
22
27
  */
23
- declare function max(iterable: IterableResolvable<NumberResolvable>): number | null;
28
+ declare function max<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | null;
24
29
 
25
30
  export { max };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var _assertFunction_cjs = require('./shared/_assertFunction.cjs');
4
+ var _compare_cjs = require('./shared/_compare.cjs');
5
+ var toIterableIterator_cjs = require('./toIterableIterator.cjs');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ function maxBy(iterable, comparator) {
10
+ comparator = _assertFunction_cjs.assertFunction(comparator);
11
+ const iterator = toIterableIterator_cjs.toIterableIterator(iterable);
12
+ const first = iterator.next();
13
+ if (first.done) return null;
14
+ let maximum = first.value;
15
+ for (const value of iterator) {
16
+ const comparison = _compare_cjs.compareIteratorElements(value, maximum, comparator);
17
+ if (!_compare_cjs.orderingIsLess(comparison)) {
18
+ maximum = value;
19
+ }
20
+ }
21
+ return maximum;
22
+ }
23
+ __name(maxBy, "maxBy");
24
+
25
+ exports.maxBy = maxBy;
26
+ //# sourceMappingURL=maxBy.cjs.map
27
+ //# sourceMappingURL=maxBy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/maxBy.ts"],"names":["assertFunction","toIterableIterator","compareIteratorElements","orderingIsLess"],"mappings":";;;;;;;;AAgCO,SAAS,KAAA,CACf,UACA,UACqB,EAAA;AACrB,EAAA,UAAA,GAAaA,mCAAe,UAAU,CAAA,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAWC,0CAAmB,QAAQ,CAAA,CAAA;AAC5C,EAAM,MAAA,KAAA,GAAQ,SAAS,IAAK,EAAA,CAAA;AAC5B,EAAI,IAAA,KAAA,CAAM,MAAa,OAAA,IAAA,CAAA;AAEvB,EAAA,IAAI,UAAU,KAAM,CAAA,KAAA,CAAA;AACpB,EAAA,KAAA,MAAW,SAAS,QAAU,EAAA;AAC7B,IAAA,MAAM,UAAa,GAAAC,oCAAA,CAAqC,KAAO,EAAA,OAAA,EAAS,UAAU,CAAA,CAAA;AAClF,IAAI,IAAA,CAACC,2BAAe,CAAA,UAAU,CAAG,EAAA;AAChC,MAAU,OAAA,GAAA,KAAA,CAAA;AAAA,KACX;AAAA,GACD;AAEA,EAAO,OAAA,OAAA,CAAA;AACR,CAAA;AAnBgB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA","file":"maxBy.cjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport type { max } from './max';\nimport type { maxByKey } from './maxByKey';\nimport { assertFunction } from './shared/_assertFunction';\nimport { compareIteratorElements, orderingIsLess, type CompareByComparator } from './shared/_compare';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Returns the element that gives the maximum value with respect to the specified comparison function.\n *\n * If several elements are equally maximum, the last element is returned. If the iterator is empty, `null` is returned.\n *\n * @seealso {@link max} for a version that uses the default comparator.\n * @seealso {@link maxByKey} for a version that allows custom key extractors.\n *\n * @param iterable An iterator of number values to determine the maximum value of.\n * @param comparator A function to execute for each element produced by the iterator. It should return a number value.\n * @returns The element that gives the maximum value from the specified function, or `null` if the iterator is empty.\n *\n * @example\n * ```typescript\n * import { ascNumber, maxBy } from '@sapphire/iterator-utilities';\n *\n * const iterable = [-3, 0, 1, 5, -10];\n * console.log(maxBy(iterable, ascNumber));\n * // Output: 5\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function maxBy<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcomparator: CompareByComparator<ElementType>\n): ElementType | null {\n\tcomparator = assertFunction(comparator);\n\n\tconst iterator = toIterableIterator(iterable);\n\tconst first = iterator.next();\n\tif (first.done) return null;\n\n\tlet maximum = first.value;\n\tfor (const value of iterator) {\n\t\tconst comparison = compareIteratorElements<ElementType>(value, maximum, comparator);\n\t\tif (!orderingIsLess(comparison)) {\n\t\t\tmaximum = value;\n\t\t}\n\t}\n\n\treturn maximum;\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import { IterableResolvable } from './from.cjs';
2
+ import { CompareByComparator } from './shared/_compare.js';
3
+
4
+ /**
5
+ * Returns the element that gives the maximum value with respect to the specified comparison function.
6
+ *
7
+ * If several elements are equally maximum, the last element is returned. If the iterator is empty, `null` is returned.
8
+ *
9
+ * @seealso {@link max} for a version that uses the default comparator.
10
+ * @seealso {@link maxByKey} for a version that allows custom key extractors.
11
+ *
12
+ * @param iterable An iterator of number values to determine the maximum value of.
13
+ * @param comparator A function to execute for each element produced by the iterator. It should return a number value.
14
+ * @returns The element that gives the maximum value from the specified function, or `null` if the iterator is empty.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { ascNumber, maxBy } from '@sapphire/iterator-utilities';
19
+ *
20
+ * const iterable = [-3, 0, 1, 5, -10];
21
+ * console.log(maxBy(iterable, ascNumber));
22
+ * // Output: 5
23
+ * ```
24
+ *
25
+ * @remarks
26
+ *
27
+ * This function consumes the entire iterator.
28
+ */
29
+ declare function maxBy<const ElementType>(iterable: IterableResolvable<ElementType>, comparator: CompareByComparator<ElementType>): ElementType | null;
30
+
31
+ export { maxBy };
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var _assertFunction_cjs = require('./shared/_assertFunction.cjs');
4
+ var _compare_cjs = require('./shared/_compare.cjs');
5
+ var comparators_cjs = require('./shared/comparators.cjs');
6
+ var toIterableIterator_cjs = require('./toIterableIterator.cjs');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ function maxByKey(iterable, callbackFn, comparator = comparators_cjs.defaultCompare) {
11
+ callbackFn = _assertFunction_cjs.assertFunction(callbackFn);
12
+ const iterator = toIterableIterator_cjs.toIterableIterator(iterable);
13
+ const first = iterator.next();
14
+ if (first.done) return null;
15
+ let maximum = first.value;
16
+ let maximumKey = callbackFn(maximum, 0);
17
+ let index = 1;
18
+ for (const value of iterator) {
19
+ const key = callbackFn(value, index++);
20
+ const comparison = _compare_cjs.compareIteratorElements(maximumKey, key, comparator);
21
+ if (!_compare_cjs.orderingIsGreater(comparison)) {
22
+ maximum = value;
23
+ maximumKey = key;
24
+ }
25
+ }
26
+ return maximum;
27
+ }
28
+ __name(maxByKey, "maxByKey");
29
+
30
+ exports.maxByKey = maxByKey;
31
+ //# sourceMappingURL=maxByKey.cjs.map
32
+ //# sourceMappingURL=maxByKey.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/maxByKey.ts"],"names":["defaultCompare","assertFunction","toIterableIterator","compareIteratorElements","orderingIsGreater"],"mappings":";;;;;;;;;AAkCO,SAAS,QACf,CAAA,QAAA,EACA,UACA,EAAA,UAAA,GAA8CA,8BACzB,EAAA;AACrB,EAAA,UAAA,GAAaC,mCAAe,UAAU,CAAA,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAWC,0CAAmB,QAAQ,CAAA,CAAA;AAC5C,EAAM,MAAA,KAAA,GAAQ,SAAS,IAAK,EAAA,CAAA;AAC5B,EAAI,IAAA,KAAA,CAAM,MAAa,OAAA,IAAA,CAAA;AAEvB,EAAA,IAAI,UAAU,KAAM,CAAA,KAAA,CAAA;AACpB,EAAI,IAAA,UAAA,GAAa,UAAW,CAAA,OAAA,EAAS,CAAC,CAAA,CAAA;AACtC,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAA,KAAA,MAAW,SAAS,QAAU,EAAA;AAC7B,IAAM,MAAA,GAAA,GAAM,UAAW,CAAA,KAAA,EAAO,KAAO,EAAA,CAAA,CAAA;AACrC,IAAA,MAAM,UAAa,GAAAC,oCAAA,CAAoC,UAAY,EAAA,GAAA,EAAK,UAAU,CAAA,CAAA;AAElF,IAAI,IAAA,CAACC,8BAAkB,CAAA,UAAU,CAAG,EAAA;AACnC,MAAU,OAAA,GAAA,KAAA,CAAA;AACV,MAAa,UAAA,GAAA,GAAA,CAAA;AAAA,KACd;AAAA,GACD;AAEA,EAAO,OAAA,OAAA,CAAA;AACR,CAAA;AAzBgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"maxByKey.cjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport type { max } from './max';\nimport type { maxBy } from './maxBy';\nimport { assertFunction } from './shared/_assertFunction';\nimport { compareIteratorElements, orderingIsGreater, type CompareByComparator } from './shared/_compare';\nimport { defaultCompare } from './shared/comparators';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Returns the element that gives the maximum value from the specified function.\n *\n * If several elements are equally maximum, the last element is returned. If the iterator is empty, `null` is returned.\n *\n * @seealso {@link max} for a version that uses the default comparator.\n * @seealso {@link maxBy} for a version that allows custom comparators.\n *\n * @param iterable An iterator of number values to determine the maximum value of.\n * @param callbackFn A function to execute for each element produced by the iterator, producing a key to compare with.\n * @param comparator A function to execute for each element produced by the iterator. It should return a number value.\n * @returns The element that gives the maximum value from the specified function, or `null` if the iterator is empty.\n *\n * @example\n * ```typescript\n * import { maxByKey } from '@sapphire/iterator-utilities';\n *\n * const iterable = [-3, 0, 1, 5, -10];\n * console.log(maxByKey(iterable, (value) => Math.abs(value)));\n * // Output: -10\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function maxByKey<const ElementType, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => MappedType,\n\tcomparator: CompareByComparator<MappedType> = defaultCompare\n): ElementType | null {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tconst iterator = toIterableIterator(iterable);\n\tconst first = iterator.next();\n\tif (first.done) return null;\n\n\tlet maximum = first.value;\n\tlet maximumKey = callbackFn(maximum, 0);\n\tlet index = 1;\n\tfor (const value of iterator) {\n\t\tconst key = callbackFn(value, index++);\n\t\tconst comparison = compareIteratorElements<MappedType>(maximumKey, key, comparator);\n\n\t\tif (!orderingIsGreater(comparison)) {\n\t\t\tmaximum = value;\n\t\t\tmaximumKey = key;\n\t\t}\n\t}\n\n\treturn maximum;\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import { IterableResolvable } from './from.cjs';
2
+ import { CompareByComparator } from './shared/_compare.js';
3
+
4
+ /**
5
+ * Returns the element that gives the maximum value from the specified function.
6
+ *
7
+ * If several elements are equally maximum, the last element is returned. If the iterator is empty, `null` is returned.
8
+ *
9
+ * @seealso {@link max} for a version that uses the default comparator.
10
+ * @seealso {@link maxBy} for a version that allows custom comparators.
11
+ *
12
+ * @param iterable An iterator of number values to determine the maximum value of.
13
+ * @param callbackFn A function to execute for each element produced by the iterator, producing a key to compare with.
14
+ * @param comparator A function to execute for each element produced by the iterator. It should return a number value.
15
+ * @returns The element that gives the maximum value from the specified function, or `null` if the iterator is empty.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { maxByKey } from '@sapphire/iterator-utilities';
20
+ *
21
+ * const iterable = [-3, 0, 1, 5, -10];
22
+ * console.log(maxByKey(iterable, (value) => Math.abs(value)));
23
+ * // Output: -10
24
+ * ```
25
+ *
26
+ * @remarks
27
+ *
28
+ * This function consumes the entire iterator.
29
+ */
30
+ declare function maxByKey<const ElementType, const MappedType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => MappedType, comparator?: CompareByComparator<MappedType>): ElementType | null;
31
+
32
+ export { maxByKey };
@@ -1,16 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var map_cjs = require('./map.cjs');
4
- var _toNumberOrThrow_cjs = require('./shared/_toNumberOrThrow.cjs');
3
+ var minBy_cjs = require('./minBy.cjs');
4
+ var comparators_cjs = require('./shared/comparators.cjs');
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
8
  function min(iterable) {
9
- let min2 = null;
10
- for (const value of map_cjs.map(iterable, _toNumberOrThrow_cjs.toNumberOrThrow)) {
11
- if (min2 === null || value < min2) min2 = value;
12
- }
13
- return min2;
9
+ return minBy_cjs.minBy(iterable, comparators_cjs.defaultCompare);
14
10
  }
15
11
  __name(min, "min");
16
12
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/min.ts"],"names":["min","map","toNumberOrThrow"],"mappings":";;;;;;;AAuBO,SAAS,IAAI,QAA+D,EAAA;AAClF,EAAA,IAAIA,IAAqB,GAAA,IAAA,CAAA;AACzB,EAAA,KAAA,MAAW,KAAS,IAAAC,WAAA,CAAI,QAAU,EAAAC,oCAAe,CAAG,EAAA;AACnD,IAAA,IAAIF,IAAQ,KAAA,IAAA,IAAQ,KAAQA,GAAAA,IAAAA,EAAKA,IAAM,GAAA,KAAA,CAAA;AAAA,GACxC;AAEA,EAAOA,OAAAA,IAAAA,CAAAA;AACR,CAAA;AAPgB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"min.cjs","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"]}
1
+ {"version":3,"sources":["../../../src/lib/min.ts"],"names":["minBy","defaultCompare"],"mappings":";;;;;;;AA8BO,SAAS,IAAuB,QAA+D,EAAA;AACrG,EAAO,OAAAA,eAAA,CAAM,UAAUC,8BAAc,CAAA,CAAA;AACtC,CAAA;AAFgB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"min.cjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { minBy } from './minBy';\nimport type { minByKey } from './minByKey';\nimport { defaultCompare } from './shared/comparators';\n\n/**\n * Consumes the iterable and returns the lowest number element. If the iterable is empty, it returns `null`.\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 minBy} instead.\n *\n * @seealso {@link minBy} for a version that allows custom comparators.\n * @seealso {@link minByKey} for a version that allows custom key extractors.\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<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | null {\n\treturn minBy(iterable, defaultCompare);\n}\n"]}
@@ -1,8 +1,13 @@
1
1
  import { IterableResolvable } from './from.cjs';
2
- import { NumberResolvable } from './shared/_toNumberOrThrow.js';
3
2
 
4
3
  /**
5
- * Consumes the iterable and returns the lowest number element. If the iterable is empty, or contains only non-number values, it returns `null`.
4
+ * Consumes the iterable and returns the lowest number element. If the iterable is empty, it returns `null`.
5
+ *
6
+ * This function uses the default comparator (lexicographically), which means it will compare the elements as strings.
7
+ * If this is undesirable, use {@link minBy} instead.
8
+ *
9
+ * @seealso {@link minBy} for a version that allows custom comparators.
10
+ * @seealso {@link minByKey} for a version that allows custom key extractors.
6
11
  *
7
12
  * @param iterable An iterator of number values to determine the minimum value of.
8
13
  * @returns The minimum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.
@@ -20,6 +25,6 @@ import { NumberResolvable } from './shared/_toNumberOrThrow.js';
20
25
  *
21
26
  * This function consumes the entire iterator.
22
27
  */
23
- declare function min(iterable: IterableResolvable<NumberResolvable>): number | null;
28
+ declare function min<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | null;
24
29
 
25
30
  export { min };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var _assertFunction_cjs = require('./shared/_assertFunction.cjs');
4
+ var _compare_cjs = require('./shared/_compare.cjs');
5
+ var toIterableIterator_cjs = require('./toIterableIterator.cjs');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ function minBy(iterable, comparator) {
10
+ comparator = _assertFunction_cjs.assertFunction(comparator);
11
+ const iterator = toIterableIterator_cjs.toIterableIterator(iterable);
12
+ const first = iterator.next();
13
+ if (first.done) return null;
14
+ let minimum = first.value;
15
+ for (const value of iterator) {
16
+ const comparison = _compare_cjs.compareIteratorElements(value, minimum, comparator);
17
+ if (!_compare_cjs.orderingIsGreater(comparison)) {
18
+ minimum = value;
19
+ }
20
+ }
21
+ return minimum;
22
+ }
23
+ __name(minBy, "minBy");
24
+
25
+ exports.minBy = minBy;
26
+ //# sourceMappingURL=minBy.cjs.map
27
+ //# sourceMappingURL=minBy.cjs.map