@sapphire/iterator-utilities 1.0.3-next.fc35dd86 → 2.0.0-next.09afdaab

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 (351) 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/append.cjs.map +1 -1
  10. package/dist/cjs/lib/at.cjs.map +1 -1
  11. package/dist/cjs/lib/average.cjs.map +1 -1
  12. package/dist/cjs/lib/chain.cjs.map +1 -1
  13. package/dist/cjs/lib/chunk.cjs.map +1 -1
  14. package/dist/cjs/lib/collect.cjs +12 -0
  15. package/dist/cjs/lib/collect.cjs.map +1 -0
  16. package/dist/cjs/lib/collect.d.cts +2 -0
  17. package/dist/cjs/lib/collectInto.cjs +17 -0
  18. package/dist/cjs/lib/collectInto.cjs.map +1 -0
  19. package/dist/cjs/lib/collectInto.d.cts +29 -0
  20. package/dist/cjs/lib/compact.cjs.map +1 -1
  21. package/dist/cjs/lib/compare.cjs +15 -0
  22. package/dist/cjs/lib/compare.cjs.map +1 -0
  23. package/dist/cjs/lib/compare.d.cts +32 -0
  24. package/dist/cjs/lib/compareBy.cjs +26 -0
  25. package/dist/cjs/lib/compareBy.cjs.map +1 -0
  26. package/dist/cjs/lib/compareBy.d.cts +31 -0
  27. package/dist/cjs/lib/compress.cjs.map +1 -1
  28. package/dist/cjs/lib/contains.cjs.map +1 -1
  29. package/dist/cjs/lib/count.cjs.map +1 -1
  30. package/dist/cjs/lib/cycle.cjs.map +1 -1
  31. package/dist/cjs/lib/difference.cjs.map +1 -1
  32. package/dist/cjs/lib/drop.cjs +0 -1
  33. package/dist/cjs/lib/drop.cjs.map +1 -1
  34. package/dist/cjs/lib/drop.d.cts +1 -1
  35. package/dist/cjs/lib/dropLast.cjs +0 -1
  36. package/dist/cjs/lib/dropLast.cjs.map +1 -1
  37. package/dist/cjs/lib/dropLast.d.cts +1 -1
  38. package/dist/cjs/lib/dropWhile.cjs +0 -1
  39. package/dist/cjs/lib/dropWhile.cjs.map +1 -1
  40. package/dist/cjs/lib/dropWhile.d.cts +1 -1
  41. package/dist/cjs/lib/empty.cjs.map +1 -1
  42. package/dist/cjs/lib/enumerate.cjs.map +1 -1
  43. package/dist/cjs/lib/equal.cjs +15 -0
  44. package/dist/cjs/lib/equal.cjs.map +1 -0
  45. package/dist/cjs/lib/equal.d.cts +26 -0
  46. package/dist/cjs/lib/equalBy.cjs +23 -0
  47. package/dist/cjs/lib/equalBy.cjs.map +1 -0
  48. package/dist/cjs/lib/equalBy.d.cts +27 -0
  49. package/dist/cjs/lib/every.cjs.map +1 -1
  50. package/dist/cjs/lib/filter.cjs +0 -1
  51. package/dist/cjs/lib/filter.cjs.map +1 -1
  52. package/dist/cjs/lib/filter.d.cts +1 -1
  53. package/dist/cjs/lib/find.cjs.map +1 -1
  54. package/dist/cjs/lib/findIndex.cjs.map +1 -1
  55. package/dist/cjs/lib/first.cjs.map +1 -1
  56. package/dist/cjs/lib/flat.cjs.map +1 -1
  57. package/dist/cjs/lib/flatMap.cjs.map +1 -1
  58. package/dist/cjs/lib/forEach.cjs.map +1 -1
  59. package/dist/cjs/lib/from.cjs.map +1 -1
  60. package/dist/cjs/lib/fuse.cjs +26 -0
  61. package/dist/cjs/lib/fuse.cjs.map +1 -0
  62. package/dist/cjs/lib/fuse.d.cts +47 -0
  63. package/dist/cjs/lib/greaterOrEqualThan.cjs +17 -0
  64. package/dist/cjs/lib/greaterOrEqualThan.cjs.map +1 -0
  65. package/dist/cjs/lib/greaterOrEqualThan.d.cts +32 -0
  66. package/dist/cjs/lib/greaterThan.cjs +17 -0
  67. package/dist/cjs/lib/greaterThan.cjs.map +1 -0
  68. package/dist/cjs/lib/greaterThan.d.cts +32 -0
  69. package/dist/cjs/lib/indexOf.cjs +0 -1
  70. package/dist/cjs/lib/indexOf.cjs.map +1 -1
  71. package/dist/cjs/lib/indexOf.d.cts +1 -1
  72. package/dist/cjs/lib/inspect.cjs +25 -0
  73. package/dist/cjs/lib/inspect.cjs.map +1 -0
  74. package/dist/cjs/lib/inspect.d.cts +39 -0
  75. package/dist/cjs/lib/intersect.cjs.map +1 -1
  76. package/dist/cjs/lib/intersperse.cjs +35 -0
  77. package/dist/cjs/lib/intersperse.cjs.map +1 -0
  78. package/dist/cjs/lib/intersperse.d.cts +30 -0
  79. package/dist/cjs/lib/isEmpty.cjs.map +1 -1
  80. package/dist/cjs/lib/isSorted.cjs +15 -0
  81. package/dist/cjs/lib/isSorted.cjs.map +1 -0
  82. package/dist/cjs/lib/isSorted.d.cts +35 -0
  83. package/dist/cjs/lib/isSortedBy.cjs +26 -0
  84. package/dist/cjs/lib/isSortedBy.cjs.map +1 -0
  85. package/dist/cjs/lib/isSortedBy.d.cts +32 -0
  86. package/dist/cjs/lib/isSortedByKey.cjs +29 -0
  87. package/dist/cjs/lib/isSortedByKey.cjs.map +1 -0
  88. package/dist/cjs/lib/isSortedByKey.d.cts +30 -0
  89. package/dist/cjs/lib/last.cjs.map +1 -1
  90. package/dist/cjs/lib/lessOrEqualThan.cjs +17 -0
  91. package/dist/cjs/lib/lessOrEqualThan.cjs.map +1 -0
  92. package/dist/cjs/lib/lessOrEqualThan.d.cts +32 -0
  93. package/dist/cjs/lib/lessThan.cjs +17 -0
  94. package/dist/cjs/lib/lessThan.cjs.map +1 -0
  95. package/dist/cjs/lib/lessThan.d.cts +32 -0
  96. package/dist/cjs/lib/map.cjs.map +1 -1
  97. package/dist/cjs/lib/max.cjs +3 -7
  98. package/dist/cjs/lib/max.cjs.map +1 -1
  99. package/dist/cjs/lib/max.d.cts +8 -3
  100. package/dist/cjs/lib/maxBy.cjs +27 -0
  101. package/dist/cjs/lib/maxBy.cjs.map +1 -0
  102. package/dist/cjs/lib/maxBy.d.cts +31 -0
  103. package/dist/cjs/lib/maxByKey.cjs +32 -0
  104. package/dist/cjs/lib/maxByKey.cjs.map +1 -0
  105. package/dist/cjs/lib/maxByKey.d.cts +32 -0
  106. package/dist/cjs/lib/min.cjs +3 -7
  107. package/dist/cjs/lib/min.cjs.map +1 -1
  108. package/dist/cjs/lib/min.d.cts +8 -3
  109. package/dist/cjs/lib/minBy.cjs +27 -0
  110. package/dist/cjs/lib/minBy.cjs.map +1 -0
  111. package/dist/cjs/lib/minBy.d.cts +31 -0
  112. package/dist/cjs/lib/minByKey.cjs +32 -0
  113. package/dist/cjs/lib/minByKey.cjs.map +1 -0
  114. package/dist/cjs/lib/minByKey.d.cts +31 -0
  115. package/dist/cjs/lib/notEqual.cjs +15 -0
  116. package/dist/cjs/lib/notEqual.cjs.map +1 -0
  117. package/dist/cjs/lib/notEqual.d.cts +26 -0
  118. package/dist/cjs/lib/nth.cjs +12 -0
  119. package/dist/cjs/lib/nth.cjs.map +1 -0
  120. package/dist/cjs/lib/nth.d.cts +2 -0
  121. package/dist/cjs/lib/partition.cjs.map +1 -1
  122. package/dist/cjs/lib/peekable.cjs.map +1 -1
  123. package/dist/cjs/lib/position.cjs +12 -0
  124. package/dist/cjs/lib/position.cjs.map +1 -0
  125. package/dist/cjs/lib/position.d.cts +2 -0
  126. package/dist/cjs/lib/prepend.cjs.map +1 -1
  127. package/dist/cjs/lib/product.cjs.map +1 -1
  128. package/dist/cjs/lib/range.cjs.map +1 -1
  129. package/dist/cjs/lib/reduce.cjs.map +1 -1
  130. package/dist/cjs/lib/repeat.cjs.map +1 -1
  131. package/dist/cjs/lib/reverse.cjs +2 -5
  132. package/dist/cjs/lib/reverse.cjs.map +1 -1
  133. package/dist/cjs/lib/shared/_assertFunction.cjs.map +1 -1
  134. package/dist/cjs/lib/shared/_assertNotNegative.cjs.map +1 -1
  135. package/dist/cjs/lib/shared/_assertPositive.cjs.map +1 -1
  136. package/dist/cjs/lib/shared/_compare.cjs +36 -0
  137. package/dist/cjs/lib/shared/_compare.cjs.map +1 -0
  138. package/dist/cjs/lib/shared/_compare.d.cts +20 -0
  139. package/dist/cjs/lib/shared/_makeIterableIterator.cjs.map +1 -1
  140. package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs.map +1 -1
  141. package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs.map +1 -1
  142. package/dist/cjs/lib/shared/_toNumberOrThrow.cjs.map +1 -1
  143. package/dist/cjs/lib/shared/comparators.cjs +28 -0
  144. package/dist/cjs/lib/shared/comparators.cjs.map +1 -0
  145. package/dist/cjs/lib/shared/comparators.d.cts +34 -0
  146. package/dist/cjs/lib/skip.cjs +12 -0
  147. package/dist/cjs/lib/skip.cjs.map +1 -0
  148. package/dist/cjs/lib/skip.d.cts +2 -0
  149. package/dist/cjs/lib/skipLast.cjs +12 -0
  150. package/dist/cjs/lib/skipLast.cjs.map +1 -0
  151. package/dist/cjs/lib/skipLast.d.cts +2 -0
  152. package/dist/cjs/lib/skipWhile.cjs +12 -0
  153. package/dist/cjs/lib/skipWhile.cjs.map +1 -0
  154. package/dist/cjs/lib/skipWhile.d.cts +2 -0
  155. package/dist/cjs/lib/slice.cjs.map +1 -1
  156. package/dist/cjs/lib/some.cjs.map +1 -1
  157. package/dist/cjs/lib/sorted.cjs.map +1 -1
  158. package/dist/cjs/lib/starMap.cjs.map +1 -1
  159. package/dist/cjs/lib/stepBy.cjs +29 -0
  160. package/dist/cjs/lib/stepBy.cjs.map +1 -0
  161. package/dist/cjs/lib/stepBy.d.cts +24 -0
  162. package/dist/cjs/lib/sum.cjs.map +1 -1
  163. package/dist/cjs/lib/take.cjs.map +1 -1
  164. package/dist/cjs/lib/takeLast.cjs.map +1 -1
  165. package/dist/cjs/lib/takeWhile.cjs +12 -0
  166. package/dist/cjs/lib/takeWhile.cjs.map +1 -0
  167. package/dist/cjs/lib/takeWhile.d.cts +2 -0
  168. package/dist/cjs/lib/tee.cjs.map +1 -1
  169. package/dist/cjs/lib/toArray.cjs.map +1 -1
  170. package/dist/cjs/lib/toIterableIterator.cjs.map +1 -1
  171. package/dist/cjs/lib/union.cjs.map +1 -1
  172. package/dist/cjs/lib/unique.cjs.map +1 -1
  173. package/dist/cjs/lib/unzip.cjs.map +1 -1
  174. package/dist/cjs/lib/zip.cjs.map +1 -1
  175. package/dist/esm/index.d.mts +32 -9
  176. package/dist/esm/index.mjs +31 -0
  177. package/dist/esm/lib/all.d.mts +2 -0
  178. package/dist/esm/lib/all.mjs +4 -0
  179. package/dist/esm/lib/all.mjs.map +1 -0
  180. package/dist/esm/lib/any.d.mts +2 -0
  181. package/dist/esm/lib/any.mjs +4 -0
  182. package/dist/esm/lib/any.mjs.map +1 -0
  183. package/dist/esm/lib/append.mjs.map +1 -1
  184. package/dist/esm/lib/at.mjs.map +1 -1
  185. package/dist/esm/lib/average.mjs.map +1 -1
  186. package/dist/esm/lib/chain.mjs.map +1 -1
  187. package/dist/esm/lib/chunk.mjs.map +1 -1
  188. package/dist/esm/lib/collect.d.mts +2 -0
  189. package/dist/esm/lib/collect.mjs +4 -0
  190. package/dist/esm/lib/collect.mjs.map +1 -0
  191. package/dist/esm/lib/collectInto.d.mts +29 -0
  192. package/dist/esm/lib/collectInto.mjs +14 -0
  193. package/dist/esm/lib/collectInto.mjs.map +1 -0
  194. package/dist/esm/lib/compact.mjs.map +1 -1
  195. package/dist/esm/lib/compare.d.mts +32 -0
  196. package/dist/esm/lib/compare.mjs +12 -0
  197. package/dist/esm/lib/compare.mjs.map +1 -0
  198. package/dist/esm/lib/compareBy.d.mts +31 -0
  199. package/dist/esm/lib/compareBy.mjs +23 -0
  200. package/dist/esm/lib/compareBy.mjs.map +1 -0
  201. package/dist/esm/lib/compress.mjs.map +1 -1
  202. package/dist/esm/lib/contains.mjs.map +1 -1
  203. package/dist/esm/lib/count.mjs.map +1 -1
  204. package/dist/esm/lib/cycle.mjs.map +1 -1
  205. package/dist/esm/lib/difference.mjs.map +1 -1
  206. package/dist/esm/lib/drop.d.mts +1 -1
  207. package/dist/esm/lib/drop.mjs +1 -1
  208. package/dist/esm/lib/drop.mjs.map +1 -1
  209. package/dist/esm/lib/dropLast.d.mts +1 -1
  210. package/dist/esm/lib/dropLast.mjs +1 -1
  211. package/dist/esm/lib/dropLast.mjs.map +1 -1
  212. package/dist/esm/lib/dropWhile.d.mts +1 -1
  213. package/dist/esm/lib/dropWhile.mjs +1 -1
  214. package/dist/esm/lib/dropWhile.mjs.map +1 -1
  215. package/dist/esm/lib/empty.mjs.map +1 -1
  216. package/dist/esm/lib/enumerate.mjs.map +1 -1
  217. package/dist/esm/lib/equal.d.mts +26 -0
  218. package/dist/esm/lib/equal.mjs +11 -0
  219. package/dist/esm/lib/equal.mjs.map +1 -0
  220. package/dist/esm/lib/equalBy.d.mts +27 -0
  221. package/dist/esm/lib/equalBy.mjs +19 -0
  222. package/dist/esm/lib/equalBy.mjs.map +1 -0
  223. package/dist/esm/lib/every.mjs.map +1 -1
  224. package/dist/esm/lib/filter.d.mts +1 -1
  225. package/dist/esm/lib/filter.mjs +1 -1
  226. package/dist/esm/lib/filter.mjs.map +1 -1
  227. package/dist/esm/lib/find.mjs.map +1 -1
  228. package/dist/esm/lib/findIndex.mjs.map +1 -1
  229. package/dist/esm/lib/first.mjs.map +1 -1
  230. package/dist/esm/lib/flat.mjs.map +1 -1
  231. package/dist/esm/lib/flatMap.mjs.map +1 -1
  232. package/dist/esm/lib/forEach.mjs.map +1 -1
  233. package/dist/esm/lib/from.mjs.map +1 -1
  234. package/dist/esm/lib/fuse.d.mts +47 -0
  235. package/dist/esm/lib/fuse.mjs +23 -0
  236. package/dist/esm/lib/fuse.mjs.map +1 -0
  237. package/dist/esm/lib/greaterOrEqualThan.d.mts +32 -0
  238. package/dist/esm/lib/greaterOrEqualThan.mjs +13 -0
  239. package/dist/esm/lib/greaterOrEqualThan.mjs.map +1 -0
  240. package/dist/esm/lib/greaterThan.d.mts +32 -0
  241. package/dist/esm/lib/greaterThan.mjs +13 -0
  242. package/dist/esm/lib/greaterThan.mjs.map +1 -0
  243. package/dist/esm/lib/indexOf.d.mts +1 -1
  244. package/dist/esm/lib/indexOf.mjs +1 -1
  245. package/dist/esm/lib/indexOf.mjs.map +1 -1
  246. package/dist/esm/lib/inspect.d.mts +39 -0
  247. package/dist/esm/lib/inspect.mjs +22 -0
  248. package/dist/esm/lib/inspect.mjs.map +1 -0
  249. package/dist/esm/lib/intersect.mjs.map +1 -1
  250. package/dist/esm/lib/intersperse.d.mts +30 -0
  251. package/dist/esm/lib/intersperse.mjs +32 -0
  252. package/dist/esm/lib/intersperse.mjs.map +1 -0
  253. package/dist/esm/lib/isEmpty.mjs.map +1 -1
  254. package/dist/esm/lib/isSorted.d.mts +35 -0
  255. package/dist/esm/lib/isSorted.mjs +12 -0
  256. package/dist/esm/lib/isSorted.mjs.map +1 -0
  257. package/dist/esm/lib/isSortedBy.d.mts +32 -0
  258. package/dist/esm/lib/isSortedBy.mjs +23 -0
  259. package/dist/esm/lib/isSortedBy.mjs.map +1 -0
  260. package/dist/esm/lib/isSortedByKey.d.mts +30 -0
  261. package/dist/esm/lib/isSortedByKey.mjs +26 -0
  262. package/dist/esm/lib/isSortedByKey.mjs.map +1 -0
  263. package/dist/esm/lib/last.mjs.map +1 -1
  264. package/dist/esm/lib/lessOrEqualThan.d.mts +32 -0
  265. package/dist/esm/lib/lessOrEqualThan.mjs +13 -0
  266. package/dist/esm/lib/lessOrEqualThan.mjs.map +1 -0
  267. package/dist/esm/lib/lessThan.d.mts +32 -0
  268. package/dist/esm/lib/lessThan.mjs +13 -0
  269. package/dist/esm/lib/lessThan.mjs.map +1 -0
  270. package/dist/esm/lib/map.mjs.map +1 -1
  271. package/dist/esm/lib/max.d.mts +8 -3
  272. package/dist/esm/lib/max.mjs +3 -7
  273. package/dist/esm/lib/max.mjs.map +1 -1
  274. package/dist/esm/lib/maxBy.d.mts +31 -0
  275. package/dist/esm/lib/maxBy.mjs +24 -0
  276. package/dist/esm/lib/maxBy.mjs.map +1 -0
  277. package/dist/esm/lib/maxByKey.d.mts +32 -0
  278. package/dist/esm/lib/maxByKey.mjs +29 -0
  279. package/dist/esm/lib/maxByKey.mjs.map +1 -0
  280. package/dist/esm/lib/min.d.mts +8 -3
  281. package/dist/esm/lib/min.mjs +3 -7
  282. package/dist/esm/lib/min.mjs.map +1 -1
  283. package/dist/esm/lib/minBy.d.mts +31 -0
  284. package/dist/esm/lib/minBy.mjs +24 -0
  285. package/dist/esm/lib/minBy.mjs.map +1 -0
  286. package/dist/esm/lib/minByKey.d.mts +31 -0
  287. package/dist/esm/lib/minByKey.mjs +29 -0
  288. package/dist/esm/lib/minByKey.mjs.map +1 -0
  289. package/dist/esm/lib/notEqual.d.mts +26 -0
  290. package/dist/esm/lib/notEqual.mjs +11 -0
  291. package/dist/esm/lib/notEqual.mjs.map +1 -0
  292. package/dist/esm/lib/nth.d.mts +2 -0
  293. package/dist/esm/lib/nth.mjs +4 -0
  294. package/dist/esm/lib/nth.mjs.map +1 -0
  295. package/dist/esm/lib/partition.mjs.map +1 -1
  296. package/dist/esm/lib/peekable.mjs.map +1 -1
  297. package/dist/esm/lib/position.d.mts +2 -0
  298. package/dist/esm/lib/position.mjs +4 -0
  299. package/dist/esm/lib/position.mjs.map +1 -0
  300. package/dist/esm/lib/prepend.mjs.map +1 -1
  301. package/dist/esm/lib/product.mjs.map +1 -1
  302. package/dist/esm/lib/range.mjs.map +1 -1
  303. package/dist/esm/lib/reduce.mjs.map +1 -1
  304. package/dist/esm/lib/repeat.mjs.map +1 -1
  305. package/dist/esm/lib/reverse.mjs +2 -5
  306. package/dist/esm/lib/reverse.mjs.map +1 -1
  307. package/dist/esm/lib/shared/_assertFunction.mjs.map +1 -1
  308. package/dist/esm/lib/shared/_assertNotNegative.mjs.map +1 -1
  309. package/dist/esm/lib/shared/_assertPositive.mjs.map +1 -1
  310. package/dist/esm/lib/shared/_compare.d.mts +20 -0
  311. package/dist/esm/lib/shared/_compare.mjs +30 -0
  312. package/dist/esm/lib/shared/_compare.mjs.map +1 -0
  313. package/dist/esm/lib/shared/_makeIterableIterator.mjs.map +1 -1
  314. package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs.map +1 -1
  315. package/dist/esm/lib/shared/_toIntegerOrThrow.mjs.map +1 -1
  316. package/dist/esm/lib/shared/_toNumberOrThrow.mjs.map +1 -1
  317. package/dist/esm/lib/shared/comparators.d.mts +34 -0
  318. package/dist/esm/lib/shared/comparators.mjs +21 -0
  319. package/dist/esm/lib/shared/comparators.mjs.map +1 -0
  320. package/dist/esm/lib/skip.d.mts +2 -0
  321. package/dist/esm/lib/skip.mjs +4 -0
  322. package/dist/esm/lib/skip.mjs.map +1 -0
  323. package/dist/esm/lib/skipLast.d.mts +2 -0
  324. package/dist/esm/lib/skipLast.mjs +4 -0
  325. package/dist/esm/lib/skipLast.mjs.map +1 -0
  326. package/dist/esm/lib/skipWhile.d.mts +2 -0
  327. package/dist/esm/lib/skipWhile.mjs +4 -0
  328. package/dist/esm/lib/skipWhile.mjs.map +1 -0
  329. package/dist/esm/lib/slice.mjs.map +1 -1
  330. package/dist/esm/lib/some.mjs.map +1 -1
  331. package/dist/esm/lib/sorted.mjs.map +1 -1
  332. package/dist/esm/lib/starMap.mjs.map +1 -1
  333. package/dist/esm/lib/stepBy.d.mts +24 -0
  334. package/dist/esm/lib/stepBy.mjs +26 -0
  335. package/dist/esm/lib/stepBy.mjs.map +1 -0
  336. package/dist/esm/lib/sum.mjs.map +1 -1
  337. package/dist/esm/lib/take.mjs.map +1 -1
  338. package/dist/esm/lib/takeLast.mjs.map +1 -1
  339. package/dist/esm/lib/takeWhile.d.mts +2 -0
  340. package/dist/esm/lib/takeWhile.mjs +4 -0
  341. package/dist/esm/lib/takeWhile.mjs.map +1 -0
  342. package/dist/esm/lib/tee.mjs.map +1 -1
  343. package/dist/esm/lib/toArray.mjs.map +1 -1
  344. package/dist/esm/lib/toIterableIterator.mjs.map +1 -1
  345. package/dist/esm/lib/union.mjs.map +1 -1
  346. package/dist/esm/lib/unique.mjs.map +1 -1
  347. package/dist/esm/lib/unzip.mjs.map +1 -1
  348. package/dist/esm/lib/zip.mjs.map +1 -1
  349. package/dist/iife/index.global.js +391 -49
  350. package/dist/iife/index.global.js.map +1 -1
  351. package/package.json +295 -25
@@ -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;AAC3C;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;AAEtC,EAAM,MAAA,QAAA,GAAW,mBAAmB,QAAQ,CAAA;AAC5C,EAAM,MAAA,MAAA,GAAS,SAAS,IAAK,EAAA;AAC7B,EAAI,IAAA,MAAA,CAAO,MAAa,OAAA,IAAA;AAExB,EAAA,IAAI,WAAW,MAAO,CAAA,KAAA;AACtB,EAAA,KAAA,MAAW,WAAW,QAAU,EAAA;AAC/B,IAAA,MAAM,UAAa,GAAA,uBAAA,CAAqC,QAAU,EAAA,OAAA,EAAS,UAAU,CAAA;AACrF,IAAI,IAAA,iBAAA,CAAkB,UAAU,CAAA,EAAU,OAAA,KAAA;AAE1C,IAAW,QAAA,GAAA,OAAA;AAAA;AAGZ,EAAO,OAAA,IAAA;AACR;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;AAEtC,EAAM,MAAA,QAAA,GAAW,mBAAmB,QAAQ,CAAA;AAC5C,EAAM,MAAA,MAAA,GAAS,SAAS,IAAK,EAAA;AAC7B,EAAI,IAAA,MAAA,CAAO,MAAa,OAAA,IAAA;AAExB,EAAA,IAAI,WAAc,GAAA,UAAA,CAAW,MAAO,CAAA,KAAA,EAAO,CAAC,CAAA;AAC5C,EAAA,IAAI,KAAQ,GAAA,CAAA;AACZ,EAAA,KAAA,MAAW,WAAW,QAAU,EAAA;AAC/B,IAAM,MAAA,UAAA,GAAa,UAAW,CAAA,OAAA,EAAS,KAAO,EAAA,CAAA;AAC9C,IAAA,MAAM,UAAa,GAAA,uBAAA,CAAoC,WAAa,EAAA,UAAA,EAAY,UAAU,CAAA;AAC1F,IAAI,IAAA,iBAAA,CAAkB,UAAU,CAAA,EAAU,OAAA,KAAA;AAE1C,IAAc,WAAA,GAAA,UAAA;AAAA;AAGf,EAAO,OAAA,IAAA;AACR;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"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/last.ts"],"names":["last"],"mappings":";;;AAsBO,SAAS,KAAwB,QAAoE,EAAA;AAC3G,EAAIA,IAAAA,KAAAA,CAAAA;AACJ,EAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,IAAAA,KAAO,GAAA,KAAA,CAAA;AAAA,GACR;AAEA,EAAOA,OAAAA,KAAAA,CAAAA;AACR,CAAA;AAPgB,MAAA,CAAA,IAAA,EAAA,MAAA,CAAA","file":"last.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable until it's exhausted, returning the last element.\n *\n * @param iterable An iterator to return the last value of.\n * @returns The value at the last position in the source iterator, or `undefined` if the iterator is empty.\n *\n * @example\n * ```typescript\n * import { last } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(last(iterable));\n * // Output: 5\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator to find the last value.\n */\nexport function last<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | undefined {\n\tlet last: ElementType | undefined;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tlast = value;\n\t}\n\n\treturn last;\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/last.ts"],"names":["last"],"mappings":";;;AAsBO,SAAS,KAAwB,QAAoE,EAAA;AAC3G,EAAIA,IAAAA,KAAAA;AACJ,EAAW,KAAA,MAAA,KAAA,IAAS,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACjD,IAAAA,KAAO,GAAA,KAAA;AAAA;AAGR,EAAOA,OAAAA,KAAAA;AACR;AAPgB,MAAA,CAAA,IAAA,EAAA,MAAA,CAAA","file":"last.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable until it's exhausted, returning the last element.\n *\n * @param iterable An iterator to return the last value of.\n * @returns The value at the last position in the source iterator, or `undefined` if the iterator is empty.\n *\n * @example\n * ```typescript\n * import { last } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(last(iterable));\n * // Output: 5\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator to find the last value.\n */\nexport function last<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | undefined {\n\tlet last: ElementType | undefined;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tlast = value;\n\t}\n\n\treturn last;\n}\n"]}
@@ -0,0 +1,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;AACtC,EAAO,OAAA,CAAC,kBAAkB,MAAM,CAAA;AACjC;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;AACtC,EAAA,OAAO,eAAe,MAAM,CAAA;AAC7B;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 +1 @@
1
- {"version":3,"sources":["../../../src/lib/map.ts"],"names":[],"mappings":";;;;AAmBO,UAAU,GAAA,CAChB,UACA,UAC+B,EAAA;AAC/B,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA,CAAA;AAEtC,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAW,KAAA,MAAA,OAAA,IAAW,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACnD,IAAM,MAAA,UAAA,CAAW,SAAS,KAAO,EAAA,CAAA,CAAA;AAAA,GAClC;AACD,CAAA;AAViB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"map.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterable with the results of calling a provided function on each element.\n *\n * @param iterable An iterator to map over.\n * @param callbackFn A function to execute for each element produced by the iterator. Its return value is yielded by the iterator helper.\n *\n * @example\n * ```typescript\n * import { map } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...map(iterable, (value) => value * 2)]);\n * // Output: [2, 4, 6, 8, 10]\n * ```\n */\nexport function* map<const ElementType, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => MappedType\n): IterableIterator<MappedType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const element of toIterableIterator(iterable)) {\n\t\tyield callbackFn(element, index++);\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/map.ts"],"names":[],"mappings":";;;;AAmBO,UAAU,GAAA,CAChB,UACA,UAC+B,EAAA;AAC/B,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA;AAEtC,EAAA,IAAI,KAAQ,GAAA,CAAA;AACZ,EAAW,KAAA,MAAA,OAAA,IAAW,kBAAmB,CAAA,QAAQ,CAAG,EAAA;AACnD,IAAM,MAAA,UAAA,CAAW,SAAS,KAAO,EAAA,CAAA;AAAA;AAEnC;AAViB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"map.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterable with the results of calling a provided function on each element.\n *\n * @param iterable An iterator to map over.\n * @param callbackFn A function to execute for each element produced by the iterator. Its return value is yielded by the iterator helper.\n *\n * @example\n * ```typescript\n * import { map } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...map(iterable, (value) => value * 2)]);\n * // Output: [2, 4, 6, 8, 10]\n * ```\n */\nexport function* map<const ElementType, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => MappedType\n): IterableIterator<MappedType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const element of toIterableIterator(iterable)) {\n\t\tyield callbackFn(element, index++);\n\t}\n}\n"]}
@@ -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;AACtC;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 };
@@ -0,0 +1,24 @@
1
+ import { __name } from '../chunk-PAWJFY3S.mjs';
2
+ import { assertFunction } from './shared/_assertFunction.mjs';
3
+ import { compareIteratorElements, orderingIsLess } from './shared/_compare.mjs';
4
+ import { toIterableIterator } from './toIterableIterator.mjs';
5
+
6
+ function maxBy(iterable, comparator) {
7
+ comparator = assertFunction(comparator);
8
+ const iterator = toIterableIterator(iterable);
9
+ const first = iterator.next();
10
+ if (first.done) return null;
11
+ let maximum = first.value;
12
+ for (const value of iterator) {
13
+ const comparison = compareIteratorElements(value, maximum, comparator);
14
+ if (!orderingIsLess(comparison)) {
15
+ maximum = value;
16
+ }
17
+ }
18
+ return maximum;
19
+ }
20
+ __name(maxBy, "maxBy");
21
+
22
+ export { maxBy };
23
+ //# sourceMappingURL=maxBy.mjs.map
24
+ //# sourceMappingURL=maxBy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/maxBy.ts"],"names":[],"mappings":";;;;;AAgCO,SAAS,KAAA,CACf,UACA,UACqB,EAAA;AACrB,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAW,mBAAmB,QAAQ,CAAA;AAC5C,EAAM,MAAA,KAAA,GAAQ,SAAS,IAAK,EAAA;AAC5B,EAAI,IAAA,KAAA,CAAM,MAAa,OAAA,IAAA;AAEvB,EAAA,IAAI,UAAU,KAAM,CAAA,KAAA;AACpB,EAAA,KAAA,MAAW,SAAS,QAAU,EAAA;AAC7B,IAAA,MAAM,UAAa,GAAA,uBAAA,CAAqC,KAAO,EAAA,OAAA,EAAS,UAAU,CAAA;AAClF,IAAI,IAAA,CAAC,cAAe,CAAA,UAAU,CAAG,EAAA;AAChC,MAAU,OAAA,GAAA,KAAA;AAAA;AACX;AAGD,EAAO,OAAA,OAAA;AACR;AAnBgB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA","file":"maxBy.mjs","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,32 @@
1
+ import { IterableResolvable } from './from.mjs';
2
+ import { CompareByComparator } from './shared/_compare.mjs';
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 };
@@ -0,0 +1,29 @@
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 maxByKey(iterable, callbackFn, comparator = defaultCompare) {
8
+ callbackFn = assertFunction(callbackFn);
9
+ const iterator = toIterableIterator(iterable);
10
+ const first = iterator.next();
11
+ if (first.done) return null;
12
+ let maximum = first.value;
13
+ let maximumKey = callbackFn(maximum, 0);
14
+ let index = 1;
15
+ for (const value of iterator) {
16
+ const key = callbackFn(value, index++);
17
+ const comparison = compareIteratorElements(maximumKey, key, comparator);
18
+ if (!orderingIsGreater(comparison)) {
19
+ maximum = value;
20
+ maximumKey = key;
21
+ }
22
+ }
23
+ return maximum;
24
+ }
25
+ __name(maxByKey, "maxByKey");
26
+
27
+ export { maxByKey };
28
+ //# sourceMappingURL=maxByKey.mjs.map
29
+ //# sourceMappingURL=maxByKey.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/maxByKey.ts"],"names":[],"mappings":";;;;;;AAkCO,SAAS,QACf,CAAA,QAAA,EACA,UACA,EAAA,UAAA,GAA8C,cACzB,EAAA;AACrB,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAW,mBAAmB,QAAQ,CAAA;AAC5C,EAAM,MAAA,KAAA,GAAQ,SAAS,IAAK,EAAA;AAC5B,EAAI,IAAA,KAAA,CAAM,MAAa,OAAA,IAAA;AAEvB,EAAA,IAAI,UAAU,KAAM,CAAA,KAAA;AACpB,EAAI,IAAA,UAAA,GAAa,UAAW,CAAA,OAAA,EAAS,CAAC,CAAA;AACtC,EAAA,IAAI,KAAQ,GAAA,CAAA;AACZ,EAAA,KAAA,MAAW,SAAS,QAAU,EAAA;AAC7B,IAAM,MAAA,GAAA,GAAM,UAAW,CAAA,KAAA,EAAO,KAAO,EAAA,CAAA;AACrC,IAAA,MAAM,UAAa,GAAA,uBAAA,CAAoC,UAAY,EAAA,GAAA,EAAK,UAAU,CAAA;AAElF,IAAI,IAAA,CAAC,iBAAkB,CAAA,UAAU,CAAG,EAAA;AACnC,MAAU,OAAA,GAAA,KAAA;AACV,MAAa,UAAA,GAAA,GAAA;AAAA;AACd;AAGD,EAAO,OAAA,OAAA;AACR;AAzBgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"maxByKey.mjs","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"]}
@@ -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 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.mjs';
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 };
@@ -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 { minBy } from './minBy.mjs';
3
+ import { defaultCompare } from './shared/comparators.mjs';
4
4
 
5
5
  function min(iterable) {
6
- let min2 = null;
7
- for (const value of map(iterable, toNumberOrThrow)) {
8
- if (min2 === null || value < min2) min2 = value;
9
- }
10
- return min2;
6
+ return minBy(iterable, defaultCompare);
11
7
  }
12
8
  __name(min, "min");
13
9
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/min.ts"],"names":["min"],"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":"min.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 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":[],"mappings":";;;;AA8BO,SAAS,IAAuB,QAA+D,EAAA;AACrG,EAAO,OAAA,KAAA,CAAM,UAAU,cAAc,CAAA;AACtC;AAFgB,MAAA,CAAA,GAAA,EAAA,KAAA,CAAA","file":"min.mjs","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"]}
@@ -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 minimum value with respect to the specified comparison function.
6
+ *
7
+ * If several elements are equally minimum, the last element is returned. If the iterator is empty, `null` is returned.
8
+ *
9
+ * @seealso {@link min} for a version that uses the default comparator.
10
+ * @seealso {@link minByKey} for a version that allows custom key extractors.
11
+ *
12
+ * @param iterable An iterator of number values to determine the minimum value of.
13
+ * @param callbackFn A function to execute for each element produced by the iterator. It should return a number value.
14
+ * @returns The element that gives the minimum value from the specified function, or `null` if the iterator is empty.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { ascNumber, minBy } from '@sapphire/iterator-utilities';
19
+ *
20
+ * const iterable = [-3, 0, 1, 5, -10];
21
+ * console.log(minBy(iterable, ascNumber));
22
+ * // Output: -10
23
+ * ```
24
+ *
25
+ * @remarks
26
+ *
27
+ * This function consumes the entire iterator.
28
+ */
29
+ declare function minBy<const ElementType>(iterable: IterableResolvable<ElementType>, comparator: CompareByComparator<ElementType>): ElementType | null;
30
+
31
+ export { minBy };
@@ -0,0 +1,24 @@
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 minBy(iterable, comparator) {
7
+ comparator = assertFunction(comparator);
8
+ const iterator = toIterableIterator(iterable);
9
+ const first = iterator.next();
10
+ if (first.done) return null;
11
+ let minimum = first.value;
12
+ for (const value of iterator) {
13
+ const comparison = compareIteratorElements(value, minimum, comparator);
14
+ if (!orderingIsGreater(comparison)) {
15
+ minimum = value;
16
+ }
17
+ }
18
+ return minimum;
19
+ }
20
+ __name(minBy, "minBy");
21
+
22
+ export { minBy };
23
+ //# sourceMappingURL=minBy.mjs.map
24
+ //# sourceMappingURL=minBy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/minBy.ts"],"names":[],"mappings":";;;;;AAgCO,SAAS,KAAA,CACf,UACA,UACqB,EAAA;AACrB,EAAA,UAAA,GAAa,eAAe,UAAU,CAAA;AAEtC,EAAM,MAAA,QAAA,GAAW,mBAAmB,QAAQ,CAAA;AAC5C,EAAM,MAAA,KAAA,GAAQ,SAAS,IAAK,EAAA;AAC5B,EAAI,IAAA,KAAA,CAAM,MAAa,OAAA,IAAA;AAEvB,EAAA,IAAI,UAAU,KAAM,CAAA,KAAA;AACpB,EAAA,KAAA,MAAW,SAAS,QAAU,EAAA;AAC7B,IAAA,MAAM,UAAa,GAAA,uBAAA,CAAqC,KAAO,EAAA,OAAA,EAAS,UAAU,CAAA;AAElF,IAAI,IAAA,CAAC,iBAAkB,CAAA,UAAU,CAAG,EAAA;AACnC,MAAU,OAAA,GAAA,KAAA;AAAA;AACX;AAGD,EAAO,OAAA,OAAA;AACR;AApBgB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA","file":"minBy.mjs","sourcesContent":["import type { IterableResolvable } from './from';\nimport type { min } from './min';\nimport type { minByKey } from './minByKey';\nimport { assertFunction } from './shared/_assertFunction';\nimport { compareIteratorElements, orderingIsGreater, type CompareByComparator } from './shared/_compare';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Returns the element that gives the minimum value with respect to the specified comparison function.\n *\n * If several elements are equally minimum, the last element is returned. If the iterator is empty, `null` is returned.\n *\n * @seealso {@link min} for a version that uses the default comparator.\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 * @param callbackFn A function to execute for each element produced by the iterator. It should return a number value.\n * @returns The element that gives the minimum value from the specified function, or `null` if the iterator is empty.\n *\n * @example\n * ```typescript\n * import { ascNumber, minBy } from '@sapphire/iterator-utilities';\n *\n * const iterable = [-3, 0, 1, 5, -10];\n * console.log(minBy(iterable, ascNumber));\n * // Output: -10\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function minBy<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 minimum = first.value;\n\tfor (const value of iterator) {\n\t\tconst comparison = compareIteratorElements<ElementType>(value, minimum, comparator);\n\n\t\tif (!orderingIsGreater(comparison)) {\n\t\t\tminimum = value;\n\t\t}\n\t}\n\n\treturn minimum;\n}\n"]}