@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,13 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { compare } from './compare.mjs';
3
+ import { orderingIsLess } from './shared/_compare.mjs';
4
+
5
+ function greaterOrEqualThan(iterable, other) {
6
+ const result = compare(iterable, other);
7
+ return !orderingIsLess(result);
8
+ }
9
+ __name(greaterOrEqualThan, "greaterOrEqualThan");
10
+
11
+ export { greaterOrEqualThan as ge, greaterOrEqualThan };
12
+ //# sourceMappingURL=greaterOrEqualThan.mjs.map
13
+ //# sourceMappingURL=greaterOrEqualThan.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/greaterOrEqualThan.ts"],"names":[],"mappings":";;;;AA+BO,SAAS,kBAAA,CAAsC,UAA2C,KAAiD,EAAA;AACjJ,EAAM,MAAA,MAAA,GAAS,OAAQ,CAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AACtC,EAAO,OAAA,CAAC,eAAe,MAAM,CAAA,CAAA;AAC9B,CAAA;AAHgB,MAAA,CAAA,kBAAA,EAAA,oBAAA,CAAA","file":"greaterOrEqualThan.mjs","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} greater 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 { greaterOrEqualThan } from '@sapphire/iterator-utilities';\n *\n * const x = [1, 2, 3, 4];\n * const y = [1, 4, 9, 16];\n * console.log(greaterOrEqualThan([1], [1]));\n * // Output: true\n * console.log(greaterOrEqualThan([1], [1, 2]));\n * // Output: false\n * console.log(greaterOrEqualThan([1, 2], [1]));\n * // Output: true\n * console.log(greaterOrEqualThan([1, 2], [1, 2]));\n * // Output: true\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function greaterOrEqualThan<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean {\n\tconst result = compare(iterable, other);\n\treturn !orderingIsLess(result);\n}\n\nexport { greaterOrEqualThan as ge };\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 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 { greaterThan } from '@sapphire/iterator-utilities';
13
+ *
14
+ * const x = [1, 2, 3, 4];
15
+ * const y = [1, 4, 9, 16];
16
+ * console.log(greaterThan([1], [1]));
17
+ * // Output: false
18
+ * console.log(greaterThan([1], [1, 2]));
19
+ * // Output: false
20
+ * console.log(greaterThan([1, 2], [1]));
21
+ * // Output: true
22
+ * console.log(greaterThan([1, 2], [1, 2]));
23
+ * // Output: false
24
+ * ```
25
+ *
26
+ * @remarks
27
+ *
28
+ * This function consumes the entire iterator.
29
+ */
30
+ declare function greaterThan<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean;
31
+
32
+ export { greaterThan, greaterThan as gt };
@@ -0,0 +1,13 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { compare } from './compare.mjs';
3
+ import { orderingIsGreater } from './shared/_compare.mjs';
4
+
5
+ function greaterThan(iterable, other) {
6
+ const result = compare(iterable, other);
7
+ return orderingIsGreater(result);
8
+ }
9
+ __name(greaterThan, "greaterThan");
10
+
11
+ export { greaterThan, greaterThan as gt };
12
+ //# sourceMappingURL=greaterThan.mjs.map
13
+ //# sourceMappingURL=greaterThan.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/greaterThan.ts"],"names":[],"mappings":";;;;AA+BO,SAAS,WAAA,CAA+B,UAA2C,KAAiD,EAAA;AAC1I,EAAM,MAAA,MAAA,GAAS,OAAQ,CAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AACtC,EAAA,OAAO,kBAAkB,MAAM,CAAA,CAAA;AAChC,CAAA;AAHgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"greaterThan.mjs","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} greater 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 { greaterThan } from '@sapphire/iterator-utilities';\n *\n * const x = [1, 2, 3, 4];\n * const y = [1, 4, 9, 16];\n * console.log(greaterThan([1], [1]));\n * // Output: false\n * console.log(greaterThan([1], [1, 2]));\n * // Output: false\n * console.log(greaterThan([1, 2], [1]));\n * // Output: true\n * console.log(greaterThan([1, 2], [1, 2]));\n * // Output: false\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function greaterThan<const ElementType>(iterable: IterableResolvable<ElementType>, other: IterableResolvable<ElementType>): boolean {\n\tconst result = compare(iterable, other);\n\treturn orderingIsGreater(result);\n}\n\nexport { greaterThan as gt };\n"]}
@@ -22,4 +22,4 @@ import { IterableResolvable } from './from.mjs';
22
22
  */
23
23
  declare function indexOf<const ElementType>(iterable: IterableResolvable<ElementType>, value: ElementType): number;
24
24
 
25
- export { indexOf, indexOf as position };
25
+ export { indexOf };
@@ -13,6 +13,6 @@ function indexOf(iterable, value) {
13
13
  }
14
14
  __name(indexOf, "indexOf");
15
15
 
16
- export { indexOf, indexOf as position };
16
+ export { indexOf };
17
17
  //# sourceMappingURL=indexOf.mjs.map
18
18
  //# sourceMappingURL=indexOf.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/indexOf.ts"],"names":[],"mappings":";;;AAuBO,SAAS,OAAA,CAA2B,UAA2C,KAA4B,EAAA;AACjH,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAW,KAAA,MAAA,OAAA,IAAW,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACnD,IAAA,IAAI,YAAY,KAAO,EAAA;AACtB,MAAO,OAAA,KAAA,CAAA;AAAA,KACR;AAEA,IAAA,KAAA,EAAA,CAAA;AAAA,GACD;AAEA,EAAO,OAAA,CAAA,CAAA,CAAA;AACR,CAAA;AAXgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA","file":"indexOf.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Advances the iterable until it finds the element, returning its index if it's found and `-1` otherwise.\n *\n * @param iterable An iterator to search for a value in.\n * @param value The value to search for.\n * @returns The index of the first occurrence of the value in the iterator, or `-1` if the value is not found.\n *\n * @example\n * ```typescript\n * import { indexOf } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(indexOf(iterable, 3));\n * // Output: 2\n * ```\n *\n * @remarks\n *\n * This function consumes the iterator until the value is found or the iterator is exhausted.\n */\nexport function indexOf<const ElementType>(iterable: IterableResolvable<ElementType>, value: ElementType): number {\n\tlet index = 0;\n\tfor (const element of toIterableIterator(iterable)) {\n\t\tif (element === value) {\n\t\t\treturn index;\n\t\t}\n\n\t\tindex++;\n\t}\n\n\treturn -1;\n}\n\nexport { indexOf as position };\n"]}
1
+ {"version":3,"sources":["../../../src/lib/indexOf.ts"],"names":[],"mappings":";;;AAuBO,SAAS,OAAA,CAA2B,UAA2C,KAA4B,EAAA;AACjH,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAW,KAAA,MAAA,OAAA,IAAW,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACnD,IAAA,IAAI,YAAY,KAAO,EAAA;AACtB,MAAO,OAAA,KAAA,CAAA;AAAA,KACR;AAEA,IAAA,KAAA,EAAA,CAAA;AAAA,GACD;AAEA,EAAO,OAAA,CAAA,CAAA,CAAA;AACR,CAAA;AAXgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA","file":"indexOf.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Advances the iterable until it finds the element, returning its index if it's found and `-1` otherwise.\n *\n * @param iterable An iterator to search for a value in.\n * @param value The value to search for.\n * @returns The index of the first occurrence of the value in the iterator, or `-1` if the value is not found.\n *\n * @example\n * ```typescript\n * import { indexOf } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(indexOf(iterable, 3));\n * // Output: 2\n * ```\n *\n * @remarks\n *\n * This function consumes the iterator until the value is found or the iterator is exhausted.\n */\nexport function indexOf<const ElementType>(iterable: IterableResolvable<ElementType>, value: ElementType): number {\n\tlet index = 0;\n\tfor (const element of toIterableIterator(iterable)) {\n\t\tif (element === value) {\n\t\t\treturn index;\n\t\t}\n\n\t\tindex++;\n\t}\n\n\treturn -1;\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import { IterableResolvable } from './from.mjs';
2
+
3
+ /**
4
+ * Does something with each element of an iterator, passing the value on.
5
+ *
6
+ * When using iterators, you'll often chain several of them together. While working on such code, you might want to
7
+ * check out what's happening at various parts in the pipeline. To do that, insert a call to this function.
8
+ *
9
+ * It's more common for this function to be used as a debugging tool than to exist in your final code, but applications
10
+ * may find it useful in certain situations when errors need to be logged before being discarded.
11
+ *
12
+ * @param iterable An iterator to inspect.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { inspect } from '@sapphire/iterator-utilities';
17
+ *
18
+ * const iterable = [1, 4, 2, 3];
19
+ *
20
+ * let iter = inspect(iter, (value) => console.log(`about to filter: ${value}`));
21
+ * iter = filter(iterable, (value) => value % 2 === 0);
22
+ * iter = inspect(iter, (value) => console.log(`made it through filter: ${value}`));
23
+ *
24
+ * const sum = reduce(iter, (acc, value) => acc + value, 0);
25
+ * console.log(sum);
26
+ *
27
+ * // Output:
28
+ * // about to filter: 1
29
+ * // about to filter: 4
30
+ * // made it through filter: 4
31
+ * // about to filter: 2
32
+ * // made it through filter: 2
33
+ * // about to filter: 3
34
+ * // 6
35
+ * ```
36
+ */
37
+ declare function inspect<const ElementType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => void): IterableIterator<ElementType>;
38
+
39
+ export { inspect };
@@ -0,0 +1,22 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { from } from './from.mjs';
3
+ import { assertFunction } from './shared/_assertFunction.mjs';
4
+ import { makeIterableIterator } from './shared/_makeIterableIterator.mjs';
5
+
6
+ function inspect(iterable, callbackFn) {
7
+ callbackFn = assertFunction(callbackFn);
8
+ let index = 0;
9
+ const iterator = from(iterable);
10
+ return makeIterableIterator(() => {
11
+ const result = iterator.next();
12
+ if (!result.done) {
13
+ callbackFn(result.value, index++);
14
+ }
15
+ return result;
16
+ });
17
+ }
18
+ __name(inspect, "inspect");
19
+
20
+ export { inspect };
21
+ //# sourceMappingURL=inspect.mjs.map
22
+ //# sourceMappingURL=inspect.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/inspect.ts"],"names":[],"mappings":";;;;;AAsCO,SAAS,OAAA,CACf,UACA,UACgC,EAAA;AAChC,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAM,MAAA,QAAA,GAAW,KAAK,QAAQ,CAAA,CAAA;AAC9B,EAAA,OAAO,qBAAkC,MAAM;AAC9C,IAAM,MAAA,MAAA,GAAS,SAAS,IAAK,EAAA,CAAA;AAC7B,IAAI,IAAA,CAAC,OAAO,IAAM,EAAA;AACjB,MAAW,UAAA,CAAA,MAAA,CAAO,OAAO,KAAO,EAAA,CAAA,CAAA;AAAA,KACjC;AAEA,IAAO,OAAA,MAAA,CAAA;AAAA,GACP,CAAA,CAAA;AACF,CAAA;AAhBgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA","file":"inspect.mjs","sourcesContent":["import { from, type IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { makeIterableIterator } from './shared/_makeIterableIterator';\n\n/**\n * Does something with each element of an iterator, passing the value on.\n *\n * When using iterators, you'll often chain several of them together. While working on such code, you might want to\n * check out what's happening at various parts in the pipeline. To do that, insert a call to this function.\n *\n * It's more common for this function to be used as a debugging tool than to exist in your final code, but applications\n * may find it useful in certain situations when errors need to be logged before being discarded.\n *\n * @param iterable An iterator to inspect.\n *\n * @example\n * ```typescript\n * import { inspect } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 4, 2, 3];\n *\n * let iter = inspect(iter, (value) => console.log(`about to filter: ${value}`));\n * iter = filter(iterable, (value) => value % 2 === 0);\n * iter = inspect(iter, (value) => console.log(`made it through filter: ${value}`));\n *\n * const sum = reduce(iter, (acc, value) => acc + value, 0);\n * console.log(sum);\n *\n * // Output:\n * // about to filter: 1\n * // about to filter: 4\n * // made it through filter: 4\n * // about to filter: 2\n * // made it through filter: 2\n * // about to filter: 3\n * // 6\n * ```\n */\nexport function inspect<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => void\n): IterableIterator<ElementType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tconst iterator = from(iterable);\n\treturn makeIterableIterator<ElementType>(() => {\n\t\tconst result = iterator.next();\n\t\tif (!result.done) {\n\t\t\tcallbackFn(result.value, index++);\n\t\t}\n\n\t\treturn result;\n\t});\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { IterableResolvable } from './from.mjs';
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,32 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { from } from './from.mjs';
3
+ import { makeIterableIterator } from './shared/_makeIterableIterator.mjs';
4
+
5
+ function intersperse(iterable, separator) {
6
+ let started = false;
7
+ let nextItem;
8
+ let nextItemTaken = false;
9
+ const iterator = from(iterable);
10
+ return makeIterableIterator(() => {
11
+ if (started) {
12
+ if (nextItemTaken) {
13
+ nextItemTaken = false;
14
+ return { done: false, value: nextItem };
15
+ }
16
+ const result = iterator.next();
17
+ if (result.done) {
18
+ return { done: true, value: void 0 };
19
+ }
20
+ nextItem = result.value;
21
+ nextItemTaken = true;
22
+ return { done: false, value: separator };
23
+ }
24
+ started = true;
25
+ return iterator.next();
26
+ });
27
+ }
28
+ __name(intersperse, "intersperse");
29
+
30
+ export { intersperse };
31
+ //# sourceMappingURL=intersperse.mjs.map
32
+ //# sourceMappingURL=intersperse.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/intersperse.ts"],"names":[],"mappings":";;;;AA4BO,SAAS,WAAA,CAA+B,UAA2C,SAAuD,EAAA;AAChJ,EAAA,IAAI,OAAU,GAAA,KAAA,CAAA;AACd,EAAI,IAAA,QAAA,CAAA;AACJ,EAAA,IAAI,aAAgB,GAAA,KAAA,CAAA;AAEpB,EAAM,MAAA,QAAA,GAAW,KAAK,QAAQ,CAAA,CAAA;AAC9B,EAAA,OAAO,qBAAkC,MAAM;AAC9C,IAAA,IAAI,OAAS,EAAA;AACZ,MAAA,IAAI,aAAe,EAAA;AAClB,QAAgB,aAAA,GAAA,KAAA,CAAA;AAChB,QAAA,OAAO,EAAE,IAAA,EAAM,KAAO,EAAA,KAAA,EAAO,QAAS,EAAA,CAAA;AAAA,OACvC;AAEA,MAAM,MAAA,MAAA,GAAS,SAAS,IAAK,EAAA,CAAA;AAC7B,MAAA,IAAI,OAAO,IAAM,EAAA;AAChB,QAAA,OAAO,EAAE,IAAA,EAAM,IAAM,EAAA,KAAA,EAAO,KAAU,CAAA,EAAA,CAAA;AAAA,OACvC;AAEA,MAAA,QAAA,GAAW,MAAO,CAAA,KAAA,CAAA;AAClB,MAAgB,aAAA,GAAA,IAAA,CAAA;AAChB,MAAA,OAAO,EAAE,IAAA,EAAM,KAAO,EAAA,KAAA,EAAO,SAAU,EAAA,CAAA;AAAA,KACxC;AAEA,IAAU,OAAA,GAAA,IAAA,CAAA;AACV,IAAA,OAAO,SAAS,IAAK,EAAA,CAAA;AAAA,GACrB,CAAA,CAAA;AACF,CAAA;AA1BgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"intersperse.mjs","sourcesContent":["import { from, type IterableResolvable } from './from';\nimport { makeIterableIterator } from './shared/_makeIterableIterator';\n\n/**\n * Creates a new iterator which places `separator` between adjacent items of the original iterator.\n *\n * @param iterable An iterator to map over.\n * @param separator The separator to place between adjacent items.\n *\n * @example\n * ```typescript\n * import { intersperse } from '@sapphire/iterator-utilities';\n *\n * const iterable = [0, 1, 2];\n * console.log([...intersperse(iterable, 100)]);\n * // Output: [0, 100, 1, 100, 2]\n * ```\n *\n * @example\n * `intersperse` can be very useful to join an iterator's items using a common element:\n * ```typescript\n * import { intersperse } from '@sapphire/iterator-utilities';\n *\n * const iterable = ['Hello', 'World', '!'];\n * console.log([...intersperse(iterable, ', ')].join(''));\n * // Output: 'Hello, World, !'\n * ```\n */\nexport function intersperse<const ElementType>(iterable: IterableResolvable<ElementType>, separator: ElementType): IterableIterator<ElementType> {\n\tlet started = false;\n\tlet nextItem: ElementType;\n\tlet nextItemTaken = false;\n\n\tconst iterator = from(iterable);\n\treturn makeIterableIterator<ElementType>(() => {\n\t\tif (started) {\n\t\t\tif (nextItemTaken) {\n\t\t\t\tnextItemTaken = false;\n\t\t\t\treturn { done: false, value: nextItem };\n\t\t\t}\n\n\t\t\tconst result = iterator.next();\n\t\t\tif (result.done) {\n\t\t\t\treturn { done: true, value: undefined };\n\t\t\t}\n\n\t\t\tnextItem = result.value;\n\t\t\tnextItemTaken = true;\n\t\t\treturn { done: false, value: separator };\n\t\t}\n\n\t\tstarted = true;\n\t\treturn iterator.next();\n\t});\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { IterableResolvable } from './from.mjs';
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,12 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { isSortedBy } from './isSortedBy.mjs';
3
+ import { defaultCompare } from './shared/comparators.mjs';
4
+
5
+ function isSorted(iterable) {
6
+ return isSortedBy(iterable, defaultCompare);
7
+ }
8
+ __name(isSorted, "isSorted");
9
+
10
+ export { isSorted };
11
+ //# sourceMappingURL=isSorted.mjs.map
12
+ //# sourceMappingURL=isSorted.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/isSorted.ts"],"names":[],"mappings":";;;;AAmCO,SAAS,SAA4B,QAAoD,EAAA;AAC/F,EAAO,OAAA,UAAA,CAAW,UAAU,cAAc,CAAA,CAAA;AAC3C,CAAA;AAFgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"isSorted.mjs","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,32 @@
1
+ import { IterableResolvable } from './from.mjs';
2
+ import { CompareByComparator } from './shared/_compare.mjs';
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,23 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { assertFunction } from './shared/_assertFunction.mjs';
3
+ import { compareIteratorElements, orderingIsGreater } from './shared/_compare.mjs';
4
+ import { toIterableIterator } from './toIterableIterator.mjs';
5
+
6
+ function isSortedBy(iterable, comparator) {
7
+ comparator = assertFunction(comparator);
8
+ const iterator = toIterableIterator(iterable);
9
+ const result = iterator.next();
10
+ if (result.done) return true;
11
+ let previous = result.value;
12
+ for (const current of iterator) {
13
+ const comparison = compareIteratorElements(previous, current, comparator);
14
+ if (orderingIsGreater(comparison)) return false;
15
+ previous = current;
16
+ }
17
+ return true;
18
+ }
19
+ __name(isSortedBy, "isSortedBy");
20
+
21
+ export { isSortedBy };
22
+ //# sourceMappingURL=isSortedBy.mjs.map
23
+ //# sourceMappingURL=isSortedBy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/isSortedBy.ts"],"names":[],"mappings":";;;;;AAiCO,SAAS,UAAA,CAA8B,UAA2C,UAAuD,EAAA;AAC/I,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAW,mBAAmB,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,GAAA,uBAAA,CAAqC,QAAU,EAAA,OAAA,EAAS,UAAU,CAAA,CAAA;AACrF,IAAI,IAAA,iBAAA,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.mjs","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,30 @@
1
+ import { IterableResolvable } from './from.mjs';
2
+ import { CompareByComparator } from './shared/_compare.mjs';
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,26 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { assertFunction } from './shared/_assertFunction.mjs';
3
+ import { compareIteratorElements, orderingIsGreater } from './shared/_compare.mjs';
4
+ import { defaultCompare } from './shared/comparators.mjs';
5
+ import { toIterableIterator } from './toIterableIterator.mjs';
6
+
7
+ function isSortedByKey(iterable, callbackFn, comparator = defaultCompare) {
8
+ callbackFn = assertFunction(callbackFn);
9
+ const iterator = toIterableIterator(iterable);
10
+ const result = iterator.next();
11
+ if (result.done) return true;
12
+ let previousKey = callbackFn(result.value, 0);
13
+ let index = 1;
14
+ for (const current of iterator) {
15
+ const currentKey = callbackFn(current, index++);
16
+ const comparison = compareIteratorElements(previousKey, currentKey, comparator);
17
+ if (orderingIsGreater(comparison)) return false;
18
+ previousKey = currentKey;
19
+ }
20
+ return true;
21
+ }
22
+ __name(isSortedByKey, "isSortedByKey");
23
+
24
+ export { isSortedByKey };
25
+ //# sourceMappingURL=isSortedByKey.mjs.map
26
+ //# sourceMappingURL=isSortedByKey.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/isSortedByKey.ts"],"names":[],"mappings":";;;;;;AAgCO,SAAS,aACf,CAAA,QAAA,EACA,UACA,EAAA,UAAA,GAA8C,cACpC,EAAA;AACV,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAW,mBAAmB,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,GAAA,uBAAA,CAAoC,WAAa,EAAA,UAAA,EAAY,UAAU,CAAA,CAAA;AAC1F,IAAI,IAAA,iBAAA,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.mjs","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,32 @@
1
+ import { IterableResolvable } from './from.mjs';
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,13 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { compare } from './compare.mjs';
3
+ import { orderingIsGreater } from './shared/_compare.mjs';
4
+
5
+ function lessOrEqualThan(iterable, other) {
6
+ const result = compare(iterable, other);
7
+ return !orderingIsGreater(result);
8
+ }
9
+ __name(lessOrEqualThan, "lessOrEqualThan");
10
+
11
+ export { lessOrEqualThan as le, lessOrEqualThan };
12
+ //# sourceMappingURL=lessOrEqualThan.mjs.map
13
+ //# sourceMappingURL=lessOrEqualThan.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/lessOrEqualThan.ts"],"names":[],"mappings":";;;;AA+BO,SAAS,eAAA,CAAmC,UAA2C,KAAiD,EAAA;AAC9I,EAAM,MAAA,MAAA,GAAS,OAAQ,CAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AACtC,EAAO,OAAA,CAAC,kBAAkB,MAAM,CAAA,CAAA;AACjC,CAAA;AAHgB,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA","file":"lessOrEqualThan.mjs","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.mjs';
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 };
@@ -0,0 +1,13 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { compare } from './compare.mjs';
3
+ import { orderingIsLess } from './shared/_compare.mjs';
4
+
5
+ function lessThan(iterable, other) {
6
+ const result = compare(iterable, other);
7
+ return orderingIsLess(result);
8
+ }
9
+ __name(lessThan, "lessThan");
10
+
11
+ export { lessThan, lessThan as lt };
12
+ //# sourceMappingURL=lessThan.mjs.map
13
+ //# sourceMappingURL=lessThan.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/lessThan.ts"],"names":[],"mappings":";;;;AA+BO,SAAS,QAAA,CAA4B,UAA2C,KAAiD,EAAA;AACvI,EAAM,MAAA,MAAA,GAAS,OAAQ,CAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AACtC,EAAA,OAAO,eAAe,MAAM,CAAA,CAAA;AAC7B,CAAA;AAHgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"lessThan.mjs","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"]}
@@ -1,8 +1,13 @@
1
1
  import { IterableResolvable } from './from.mjs';
2
- import { NumberResolvable } from './shared/_toNumberOrThrow.mjs';
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.mjs';
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 };
@@ -1,13 +1,9 @@
1
1
  import { __name } from '../chunk-PAWJFY3S.mjs';
2
- import { map } from './map.mjs';
3
- import { toNumberOrThrow } from './shared/_toNumberOrThrow.mjs';
2
+ import { maxBy } from './maxBy.mjs';
3
+ import { defaultCompare } from './shared/comparators.mjs';
4
4
 
5
5
  function max(iterable) {
6
- let max2 = null;
7
- for (const value of map(iterable, toNumberOrThrow)) {
8
- if (max2 === null || value > max2) max2 = value;
9
- }
10
- return max2;
6
+ return maxBy(iterable, defaultCompare);
11
7
  }
12
8
  __name(max, "max");
13
9
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/max.ts"],"names":["max"],"mappings":";;;;AAuBO,SAAS,IAAI,QAA+D,EAAA;AAClF,EAAA,IAAIA,IAAqB,GAAA,IAAA,CAAA;AACzB,EAAA,KAAA,MAAW,KAAS,IAAA,GAAA,CAAI,QAAU,EAAA,eAAe,CAAG,EAAA;AACnD,IAAA,IAAIA,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.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { map } from './map';\nimport { toNumberOrThrow, type NumberResolvable } from './shared/_toNumberOrThrow';\n\n/**\n * Consumes the iterable and returns the 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":[],"mappings":";;;;AA8BO,SAAS,IAAuB,QAA+D,EAAA;AACrG,EAAO,OAAA,KAAA,CAAM,UAAU,cAAc,CAAA,CAAA;AACtC,CAAA;AAFgB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"max.mjs","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"]}
@@ -0,0 +1,31 @@
1
+ import { IterableResolvable } from './from.mjs';
2
+ import { CompareByComparator } from './shared/_compare.mjs';
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 };