ts-data-forge 14.6.0 → 14.6.2

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 (409) hide show
  1. package/dist/array/impl/array-utils-creation.mjs +126 -26
  2. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  3. package/dist/array/impl/array-utils-element-access.mjs +63 -30
  4. package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
  5. package/dist/array/impl/array-utils-iterators.mjs +69 -53
  6. package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
  7. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +109 -73
  8. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
  9. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +71 -33
  10. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
  11. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +102 -73
  12. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
  13. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +77 -33
  14. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
  15. package/dist/array/impl/array-utils-modification.mjs +75 -122
  16. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  17. package/dist/array/impl/array-utils-reducing-value.mjs +100 -150
  18. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  19. package/dist/array/impl/array-utils-search.mjs +110 -134
  20. package/dist/array/impl/array-utils-search.mjs.map +1 -1
  21. package/dist/array/impl/array-utils-set-op.mjs +146 -38
  22. package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
  23. package/dist/array/impl/array-utils-size.mjs +10 -8
  24. package/dist/array/impl/array-utils-size.mjs.map +1 -1
  25. package/dist/array/impl/array-utils-slice-clamped.mjs +13 -50
  26. package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
  27. package/dist/array/impl/array-utils-slicing.mjs +94 -78
  28. package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
  29. package/dist/array/impl/array-utils-transformation.mjs +291 -199
  30. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  31. package/dist/array/impl/array-utils-validation.mjs +54 -56
  32. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  33. package/dist/array/impl/index.mjs +17 -17
  34. package/dist/array/impl/index.mjs.map +1 -1
  35. package/dist/array/index.mjs +2 -3
  36. package/dist/array/index.mjs.map +1 -1
  37. package/dist/collections/imap-mapped.mjs +335 -291
  38. package/dist/collections/imap-mapped.mjs.map +1 -1
  39. package/dist/collections/imap.mjs +280 -239
  40. package/dist/collections/imap.mjs.map +1 -1
  41. package/dist/collections/index.mjs +7 -7
  42. package/dist/collections/index.mjs.map +1 -1
  43. package/dist/collections/iset-mapped.d.mts.map +1 -1
  44. package/dist/collections/iset-mapped.mjs +448 -263
  45. package/dist/collections/iset-mapped.mjs.map +1 -1
  46. package/dist/collections/iset.mjs +328 -201
  47. package/dist/collections/iset.mjs.map +1 -1
  48. package/dist/collections/queue.mjs +183 -151
  49. package/dist/collections/queue.mjs.map +1 -1
  50. package/dist/collections/stack.mjs +169 -140
  51. package/dist/collections/stack.mjs.map +1 -1
  52. package/dist/entry-point.mjs +4 -77
  53. package/dist/entry-point.mjs.map +1 -1
  54. package/dist/expect-type.mjs +70 -4
  55. package/dist/expect-type.mjs.map +1 -1
  56. package/dist/functional/async-result/async-result.mjs +2 -3
  57. package/dist/functional/async-result/async-result.mjs.map +1 -1
  58. package/dist/functional/async-result/impl/async-result-flat-map.mjs +19 -21
  59. package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +1 -1
  60. package/dist/functional/async-result/impl/async-result-from-promise.mjs +9 -10
  61. package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +1 -1
  62. package/dist/functional/async-result/impl/async-result-from-throwable.mjs +12 -14
  63. package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +1 -1
  64. package/dist/functional/async-result/impl/async-result-map-err.mjs +16 -19
  65. package/dist/functional/async-result/impl/async-result-map-err.mjs.map +1 -1
  66. package/dist/functional/async-result/impl/async-result-map.mjs +16 -19
  67. package/dist/functional/async-result/impl/async-result-map.mjs.map +1 -1
  68. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +36 -9
  69. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +1 -1
  70. package/dist/functional/async-result/impl/index.mjs +8 -7
  71. package/dist/functional/async-result/impl/index.mjs.map +1 -1
  72. package/dist/functional/async-result/impl/types.mjs +2 -2
  73. package/dist/functional/async-result/impl/types.mjs.map +1 -1
  74. package/dist/functional/async-result/index.mjs +2 -3
  75. package/dist/functional/async-result/index.mjs.map +1 -1
  76. package/dist/functional/index.mjs +7 -11
  77. package/dist/functional/index.mjs.map +1 -1
  78. package/dist/functional/match.mjs +27 -13
  79. package/dist/functional/match.mjs.map +1 -1
  80. package/dist/functional/optional/impl/index.mjs +19 -18
  81. package/dist/functional/optional/impl/index.mjs.map +1 -1
  82. package/dist/functional/optional/impl/optional-expect-to-be.mjs +16 -18
  83. package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
  84. package/dist/functional/optional/impl/optional-filter.mjs +17 -19
  85. package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
  86. package/dist/functional/optional/impl/optional-flat-map.mjs +13 -15
  87. package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
  88. package/dist/functional/optional/impl/optional-from-nullable.mjs +26 -5
  89. package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
  90. package/dist/functional/optional/impl/optional-is-none.mjs +21 -5
  91. package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
  92. package/dist/functional/optional/impl/optional-is-optional.mjs +26 -8
  93. package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
  94. package/dist/functional/optional/impl/optional-is-some.mjs +22 -5
  95. package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
  96. package/dist/functional/optional/impl/optional-map.mjs +16 -18
  97. package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
  98. package/dist/functional/optional/impl/optional-match.mjs +16 -18
  99. package/dist/functional/optional/impl/optional-match.mjs.map +1 -1
  100. package/dist/functional/optional/impl/optional-none.mjs +18 -5
  101. package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
  102. package/dist/functional/optional/impl/optional-or-else.mjs +13 -15
  103. package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
  104. package/dist/functional/optional/impl/optional-some.mjs +23 -7
  105. package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
  106. package/dist/functional/optional/impl/optional-to-nullable.mjs +28 -5
  107. package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
  108. package/dist/functional/optional/impl/optional-unwrap-or.mjs +12 -14
  109. package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
  110. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +34 -9
  111. package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
  112. package/dist/functional/optional/impl/optional-unwrap.mjs +6 -9
  113. package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
  114. package/dist/functional/optional/impl/optional-zip.mjs +36 -5
  115. package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
  116. package/dist/functional/optional/impl/tag.mjs +4 -5
  117. package/dist/functional/optional/impl/tag.mjs.map +1 -1
  118. package/dist/functional/optional/impl/types.mjs +2 -2
  119. package/dist/functional/optional/impl/types.mjs.map +1 -1
  120. package/dist/functional/optional/index.mjs +2 -3
  121. package/dist/functional/optional/index.mjs.map +1 -1
  122. package/dist/functional/optional/optional.mjs +2 -3
  123. package/dist/functional/optional/optional.mjs.map +1 -1
  124. package/dist/functional/pipe.mjs +42 -14
  125. package/dist/functional/pipe.mjs.map +1 -1
  126. package/dist/functional/result/impl/index.mjs +28 -27
  127. package/dist/functional/result/impl/index.mjs.map +1 -1
  128. package/dist/functional/result/impl/result-err.mjs +29 -7
  129. package/dist/functional/result/impl/result-err.mjs.map +1 -1
  130. package/dist/functional/result/impl/result-expect-to-be.mjs +17 -18
  131. package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
  132. package/dist/functional/result/impl/result-flat-map.mjs +18 -21
  133. package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
  134. package/dist/functional/result/impl/result-fold.mjs +18 -21
  135. package/dist/functional/result/impl/result-fold.mjs.map +1 -1
  136. package/dist/functional/result/impl/result-from-optional.mjs +17 -20
  137. package/dist/functional/result/impl/result-from-optional.mjs.map +1 -1
  138. package/dist/functional/result/impl/result-from-promise.mjs +37 -8
  139. package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
  140. package/dist/functional/result/impl/result-from-throwable.mjs +41 -14
  141. package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
  142. package/dist/functional/result/impl/result-is-err.mjs +21 -5
  143. package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
  144. package/dist/functional/result/impl/result-is-ok.mjs +21 -5
  145. package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
  146. package/dist/functional/result/impl/result-is-result.mjs +25 -7
  147. package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
  148. package/dist/functional/result/impl/result-map-err.mjs +18 -21
  149. package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
  150. package/dist/functional/result/impl/result-map.mjs +18 -21
  151. package/dist/functional/result/impl/result-map.mjs.map +1 -1
  152. package/dist/functional/result/impl/result-match.mjs +17 -21
  153. package/dist/functional/result/impl/result-match.mjs.map +1 -1
  154. package/dist/functional/result/impl/result-ok.mjs +29 -7
  155. package/dist/functional/result/impl/result-ok.mjs.map +1 -1
  156. package/dist/functional/result/impl/result-or-else.mjs +14 -15
  157. package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
  158. package/dist/functional/result/impl/result-safe-try.mjs +32 -21
  159. package/dist/functional/result/impl/result-safe-try.mjs.map +1 -1
  160. package/dist/functional/result/impl/result-safe-unwrap.mjs +40 -12
  161. package/dist/functional/result/impl/result-safe-unwrap.mjs.map +1 -1
  162. package/dist/functional/result/impl/result-swap.mjs +23 -8
  163. package/dist/functional/result/impl/result-swap.mjs.map +1 -1
  164. package/dist/functional/result/impl/result-to-optional.mjs +30 -7
  165. package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
  166. package/dist/functional/result/impl/result-unwrap-err-or.mjs +13 -14
  167. package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
  168. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +43 -20
  169. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
  170. package/dist/functional/result/impl/result-unwrap-err.mjs +33 -8
  171. package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
  172. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +13 -14
  173. package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
  174. package/dist/functional/result/impl/result-unwrap-ok.mjs +6 -9
  175. package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
  176. package/dist/functional/result/impl/result-unwrap-throw.mjs +38 -11
  177. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
  178. package/dist/functional/result/impl/result-zip.mjs +35 -5
  179. package/dist/functional/result/impl/result-zip.mjs.map +1 -1
  180. package/dist/functional/result/impl/tag.mjs +4 -5
  181. package/dist/functional/result/impl/tag.mjs.map +1 -1
  182. package/dist/functional/result/impl/types.mjs +2 -2
  183. package/dist/functional/result/impl/types.mjs.map +1 -1
  184. package/dist/functional/result/index.mjs +2 -3
  185. package/dist/functional/result/index.mjs.map +1 -1
  186. package/dist/functional/result/result.mjs +2 -3
  187. package/dist/functional/result/result.mjs.map +1 -1
  188. package/dist/functional/ternary-result/impl/index.mjs +29 -28
  189. package/dist/functional/ternary-result/impl/index.mjs.map +1 -1
  190. package/dist/functional/ternary-result/impl/tag.mjs +6 -6
  191. package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
  192. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +17 -7
  193. package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
  194. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +15 -18
  195. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
  196. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +28 -32
  197. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
  198. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +24 -26
  199. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
  200. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +21 -8
  201. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
  202. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +28 -13
  203. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
  204. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +19 -5
  205. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
  206. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +21 -5
  207. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
  208. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +28 -8
  209. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
  210. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +20 -5
  211. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
  212. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +17 -18
  213. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
  214. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +20 -23
  215. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
  216. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +24 -26
  217. package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
  218. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +18 -7
  219. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
  220. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +11 -14
  221. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
  222. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +24 -10
  223. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
  224. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +11 -14
  225. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
  226. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +30 -19
  227. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
  228. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +20 -8
  229. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
  230. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +11 -14
  231. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
  232. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +7 -9
  233. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
  234. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +30 -22
  235. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
  236. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +11 -14
  237. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
  238. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +27 -17
  239. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
  240. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +20 -8
  241. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
  242. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +21 -8
  243. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
  244. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +47 -19
  245. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
  246. package/dist/functional/ternary-result/impl/types.mjs +2 -2
  247. package/dist/functional/ternary-result/impl/types.mjs.map +1 -1
  248. package/dist/functional/ternary-result/impl/variant-name.mjs +12 -14
  249. package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
  250. package/dist/functional/ternary-result/index.mjs +2 -3
  251. package/dist/functional/ternary-result/index.mjs.map +1 -1
  252. package/dist/functional/ternary-result/ternary-result.mjs +2 -3
  253. package/dist/functional/ternary-result/ternary-result.mjs.map +1 -1
  254. package/dist/guard/has-key.mjs +43 -4
  255. package/dist/guard/has-key.mjs.map +1 -1
  256. package/dist/guard/index.mjs +8 -8
  257. package/dist/guard/index.mjs.map +1 -1
  258. package/dist/guard/is-non-empty-string.mjs +39 -4
  259. package/dist/guard/is-non-empty-string.mjs.map +1 -1
  260. package/dist/guard/is-non-null-object.mjs +36 -4
  261. package/dist/guard/is-non-null-object.mjs.map +1 -1
  262. package/dist/guard/is-primitive.mjs +46 -15
  263. package/dist/guard/is-primitive.mjs.map +1 -1
  264. package/dist/guard/is-record.mjs +89 -6
  265. package/dist/guard/is-record.mjs.map +1 -1
  266. package/dist/guard/is-type.mjs +404 -19
  267. package/dist/guard/is-type.mjs.map +1 -1
  268. package/dist/guard/key-is-in.mjs +42 -4
  269. package/dist/guard/key-is-in.mjs.map +1 -1
  270. package/dist/index.mjs +12 -65
  271. package/dist/index.mjs.map +1 -1
  272. package/dist/iterator/index.mjs +2 -2
  273. package/dist/iterator/index.mjs.map +1 -1
  274. package/dist/iterator/range.mjs +19 -57
  275. package/dist/iterator/range.mjs.map +1 -1
  276. package/dist/json/index.mjs +2 -2
  277. package/dist/json/index.mjs.map +1 -1
  278. package/dist/json/json.mjs +346 -105
  279. package/dist/json/json.mjs.map +1 -1
  280. package/dist/number/branded-types/finite-number.mjs +148 -137
  281. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  282. package/dist/number/branded-types/index.mjs +33 -33
  283. package/dist/number/branded-types/index.mjs.map +1 -1
  284. package/dist/number/branded-types/int.mjs +245 -209
  285. package/dist/number/branded-types/int.mjs.map +1 -1
  286. package/dist/number/branded-types/int16.mjs +141 -131
  287. package/dist/number/branded-types/int16.mjs.map +1 -1
  288. package/dist/number/branded-types/int32.mjs +141 -131
  289. package/dist/number/branded-types/int32.mjs.map +1 -1
  290. package/dist/number/branded-types/negative-finite-number.mjs +155 -149
  291. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  292. package/dist/number/branded-types/negative-int.mjs +125 -110
  293. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  294. package/dist/number/branded-types/negative-safe-int.mjs +126 -115
  295. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  296. package/dist/number/branded-types/non-negative-finite-number.mjs +164 -154
  297. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  298. package/dist/number/branded-types/non-negative-int16.mjs +137 -125
  299. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  300. package/dist/number/branded-types/non-negative-int32.mjs +137 -125
  301. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  302. package/dist/number/branded-types/non-positive-finite-number.mjs +143 -139
  303. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  304. package/dist/number/branded-types/non-positive-int.mjs +116 -99
  305. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  306. package/dist/number/branded-types/non-positive-safe-int.mjs +118 -107
  307. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  308. package/dist/number/branded-types/non-zero-finite-number.mjs +144 -129
  309. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  310. package/dist/number/branded-types/non-zero-int.mjs +102 -82
  311. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  312. package/dist/number/branded-types/non-zero-int16.mjs +118 -105
  313. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  314. package/dist/number/branded-types/non-zero-int32.mjs +118 -105
  315. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  316. package/dist/number/branded-types/non-zero-safe-int.mjs +122 -108
  317. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  318. package/dist/number/branded-types/non-zero-uint16.mjs +118 -104
  319. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  320. package/dist/number/branded-types/non-zero-uint32.mjs +118 -104
  321. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  322. package/dist/number/branded-types/positive-finite-number.mjs +167 -160
  323. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  324. package/dist/number/branded-types/positive-int.mjs +260 -224
  325. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  326. package/dist/number/branded-types/positive-int16.mjs +134 -122
  327. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  328. package/dist/number/branded-types/positive-int32.mjs +134 -122
  329. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  330. package/dist/number/branded-types/positive-safe-int.mjs +292 -258
  331. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  332. package/dist/number/branded-types/positive-uint16.mjs +134 -122
  333. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  334. package/dist/number/branded-types/positive-uint32.mjs +134 -122
  335. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  336. package/dist/number/branded-types/safe-int.mjs +284 -255
  337. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  338. package/dist/number/branded-types/safe-uint.mjs +135 -124
  339. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  340. package/dist/number/branded-types/uint.mjs +248 -211
  341. package/dist/number/branded-types/uint.mjs.map +1 -1
  342. package/dist/number/branded-types/uint16.mjs +132 -121
  343. package/dist/number/branded-types/uint16.mjs.map +1 -1
  344. package/dist/number/branded-types/uint32.mjs +132 -121
  345. package/dist/number/branded-types/uint32.mjs.map +1 -1
  346. package/dist/number/enum/index.mjs +3 -3
  347. package/dist/number/enum/index.mjs.map +1 -1
  348. package/dist/number/enum/int8.mjs +146 -131
  349. package/dist/number/enum/int8.mjs.map +1 -1
  350. package/dist/number/enum/uint8.mjs +133 -119
  351. package/dist/number/enum/uint8.mjs.map +1 -1
  352. package/dist/number/index.mjs +6 -37
  353. package/dist/number/index.mjs.map +1 -1
  354. package/dist/number/num-arithmetic-types.mjs +42 -1
  355. package/dist/number/num-arithmetic-types.mjs.map +1 -1
  356. package/dist/number/num.mjs +541 -83
  357. package/dist/number/num.mjs.map +1 -1
  358. package/dist/number/refined-number-utils.mjs +294 -133
  359. package/dist/number/refined-number-utils.mjs.map +1 -1
  360. package/dist/object/index.mjs +2 -2
  361. package/dist/object/index.mjs.map +1 -1
  362. package/dist/object/object.mjs +355 -202
  363. package/dist/object/object.mjs.map +1 -1
  364. package/dist/others/cast-mutable.mjs +38 -11
  365. package/dist/others/cast-mutable.mjs.map +1 -1
  366. package/dist/others/cast-readonly.mjs +37 -11
  367. package/dist/others/cast-readonly.mjs.map +1 -1
  368. package/dist/others/debounce-function.mjs +22 -11
  369. package/dist/others/debounce-function.mjs.map +1 -1
  370. package/dist/others/fast-deep-equal.mjs +70 -51
  371. package/dist/others/fast-deep-equal.mjs.map +1 -1
  372. package/dist/others/if-then.mjs +32 -5
  373. package/dist/others/if-then.mjs.map +1 -1
  374. package/dist/others/index.mjs +10 -10
  375. package/dist/others/index.mjs.map +1 -1
  376. package/dist/others/map-nullable.mjs +11 -13
  377. package/dist/others/map-nullable.mjs.map +1 -1
  378. package/dist/others/memoize-function.mjs +14 -16
  379. package/dist/others/memoize-function.mjs.map +1 -1
  380. package/dist/others/tuple.mjs +52 -4
  381. package/dist/others/tuple.mjs.map +1 -1
  382. package/dist/others/unknown-to-string.mjs +91 -47
  383. package/dist/others/unknown-to-string.mjs.map +1 -1
  384. package/dist/promise/index.mjs +2 -2
  385. package/dist/promise/index.mjs.map +1 -1
  386. package/dist/promise/promise.mjs +51 -10
  387. package/dist/promise/promise.mjs.map +1 -1
  388. package/dist/string/index.mjs +2 -2
  389. package/dist/string/index.mjs.map +1 -1
  390. package/dist/string/str.mjs +250 -83
  391. package/dist/string/str.mjs.map +1 -1
  392. package/dist/types.mjs +3 -2
  393. package/dist/types.mjs.map +1 -1
  394. package/package.json +5 -6
  395. package/src/array/impl/array-utils-length-constraint-preservation.test.mts +2 -2
  396. package/src/collections/imap-mapped.mts +4 -4
  397. package/src/collections/imap.mts +1 -1
  398. package/src/collections/imap.test.mts +1 -1
  399. package/src/collections/iset-mapped.mts +2 -1
  400. package/src/collections/iset.mts +1 -1
  401. package/src/functional/async-result.test.mts +3 -2
  402. package/src/functional/optional.test.mts +2 -1
  403. package/src/functional/result.test.mts +0 -2
  404. package/src/guard/is-non-empty-string.test.mts +2 -2
  405. package/src/guard/is-non-null-object.test.mts +3 -3
  406. package/src/guard/is-primitive.test.mts +3 -3
  407. package/src/guard/is-type.test.mts +3 -3
  408. package/src/json/json.test.mts +1 -1
  409. package/src/number/enum/int8.mts +1 -1
@@ -1,19 +1,46 @@
1
1
  import { isError } from '@sindresorhus/is';
2
- import { unknownToString } from '../../../others/unknown-to-string.mjs';
2
+ import { unknownToString } from '../../../others/index.mjs';
3
3
  import { err } from './result-err.mjs';
4
4
  import { ok } from './result-ok.mjs';
5
-
6
- const fromThrowable = (fn) => {
7
- try {
8
- return ok(fn());
9
- } catch (error) {
10
- if (isError(error)) {
11
- return err(error);
5
+ /**
6
+ * Wraps a function that may throw an exception in a `Result`.
7
+ *
8
+ * This is a fundamental utility for converting traditional exception-based
9
+ * error handling into Result-based error handling. Any thrown value is
10
+ * converted to an Error object for consistent error handling.
11
+ *
12
+ * If the function executes successfully, returns `Result.Ok` with the result.
13
+ * If the function throws, returns `Result.Err` with the caught error.
14
+ *
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * const success = Result.fromThrowable(() => 1 + 1);
19
+ *
20
+ * const failure = Result.fromThrowable(() => {
21
+ * throw new Error('boom');
22
+ * });
23
+ *
24
+ * assert.deepStrictEqual(success, Result.ok(2));
25
+ *
26
+ * assert.isTrue(Result.isErr(failure));
27
+ * ```
28
+ *
29
+ * @template T The return type of the function.
30
+ * @param fn The function to execute that may throw.
31
+ * @returns A `Result<T, Error>` containing either the successful result or
32
+ * the caught error.
33
+ */
34
+ export const fromThrowable = (fn) => {
35
+ try {
36
+ return ok(fn());
37
+ }
38
+ catch (error) {
39
+ if (isError(error)) {
40
+ return err(error);
41
+ }
42
+ const msg = unknownToString(error);
43
+ return err(new Error(msg));
12
44
  }
13
- const msg = unknownToString(error);
14
- return err(new Error(msg));
15
- }
16
45
  };
17
-
18
- export { fromThrowable };
19
- //# sourceMappingURL=result-from-throwable.mjs.map
46
+ //# sourceMappingURL=result-from-throwable.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-from-throwable.mjs","sources":["../../../../src/functional/result/impl/result-from-throwable.mts"],"sourcesContent":["import { isError } from '@sindresorhus/is';\nimport { unknownToString } from '../../../others/index.mjs';\nimport { type Result } from '../result.mjs';\nimport { err } from './result-err.mjs';\nimport { ok } from './result-ok.mjs';\n\n/**\n * Wraps a function that may throw an exception in a `Result`.\n *\n * This is a fundamental utility for converting traditional exception-based\n * error handling into Result-based error handling. Any thrown value is\n * converted to an Error object for consistent error handling.\n *\n * If the function executes successfully, returns `Result.Ok` with the result.\n * If the function throws, returns `Result.Err` with the caught error.\n *\n * @example\n *\n * ```ts\n * const success = Result.fromThrowable(() => 1 + 1);\n *\n * const failure = Result.fromThrowable(() => {\n * throw new Error('boom');\n * });\n *\n * assert.deepStrictEqual(success, Result.ok(2));\n *\n * assert.isTrue(Result.isErr(failure));\n * ```\n *\n * @template T The return type of the function.\n * @param fn The function to execute that may throw.\n * @returns A `Result<T, Error>` containing either the successful result or\n * the caught error.\n */\nexport const fromThrowable = <T,>(fn: () => T): Result<T, Error> => {\n try {\n return ok(fn());\n } catch (error) {\n if (isError(error)) {\n return err(error);\n }\n\n const msg = unknownToString(error);\n\n return err(new Error(msg));\n }\n};\n"],"names":[],"mappings":";;;;;AAmCO,MAAM,aAAA,GAAgB,CAAK,EAAA,KAAkC;AAClE,EAAA,IAAI;AACF,IAAA,OAAO,EAAA,CAAG,IAAI,CAAA;AAAA,EAChB,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,OAAA,CAAQ,KAAK,CAAA,EAAG;AAClB,MAAA,OAAO,IAAI,KAAK,CAAA;AAAA,IAClB;AAEA,IAAA,MAAM,GAAA,GAAM,gBAAgB,KAAK,CAAA;AAEjC,IAAA,OAAO,GAAA,CAAI,IAAI,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAC3B;AACF;;;;"}
1
+ {"version":3,"file":"result-from-throwable.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-from-throwable.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAK,EAAW,EAAoB,EAAE;IACjE,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACnB,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;QAED,MAAM,GAAG,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAEnC,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC,CAAC"}
@@ -1,6 +1,22 @@
1
1
  import { ErrTypeTagName } from './tag.mjs';
2
-
3
- const isErr = (result) => result.$$tag === ErrTypeTagName;
4
-
5
- export { isErr };
6
- //# sourceMappingURL=result-is-err.mjs.map
2
+ /**
3
+ * Type guard for the error variant.
4
+ *
5
+ * @example
6
+ *
7
+ * ```ts
8
+ * const operation = Result.ok(3);
9
+ *
10
+ * const failure = Result.err('error');
11
+ *
12
+ * if (Result.isOk(operation)) {
13
+ * const value: number = operation.value;
14
+ *
15
+ * assert.isTrue(value === 3);
16
+ * }
17
+ *
18
+ * assert.isTrue(Result.isErr(failure));
19
+ * ```
20
+ */
21
+ export const isErr = (result) => result.$$tag === ErrTypeTagName;
22
+ //# sourceMappingURL=result-is-err.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-is-err.mjs","sources":["../../../../src/functional/result/impl/result-is-err.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { ErrTypeTagName } from './tag.mjs';\nimport { type NarrowToErr } from './types.mjs';\n\n/**\n * Type guard for the error variant.\n *\n * @example\n *\n * ```ts\n * const operation = Result.ok(3);\n *\n * const failure = Result.err('error');\n *\n * if (Result.isOk(operation)) {\n * const value: number = operation.value;\n *\n * assert.isTrue(value === 3);\n * }\n *\n * assert.isTrue(Result.isErr(failure));\n * ```\n */\nexport const isErr = <R extends UnknownResult>(\n result: R,\n): result is NarrowToErr<R> => result.$$tag === ErrTypeTagName;\n"],"names":[],"mappings":";;AAuBO,MAAM,KAAA,GAAQ,CACnB,MAAA,KAC6B,MAAA,CAAO,KAAA,KAAU;;;;"}
1
+ {"version":3,"file":"result-is-err.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-err.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,MAAS,EACiB,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,cAAc,CAAC"}
@@ -1,6 +1,22 @@
1
1
  import { OkTypeTagName } from './tag.mjs';
2
-
3
- const isOk = (result) => result.$$tag === OkTypeTagName;
4
-
5
- export { isOk };
6
- //# sourceMappingURL=result-is-ok.mjs.map
2
+ /**
3
+ * Type guard for the ok variant.
4
+ *
5
+ * @example
6
+ *
7
+ * ```ts
8
+ * const operation = Result.ok(3);
9
+ *
10
+ * const failure = Result.err('error');
11
+ *
12
+ * if (Result.isOk(operation)) {
13
+ * const value: number = operation.value;
14
+ *
15
+ * assert.isTrue(value === 3);
16
+ * }
17
+ *
18
+ * assert.isTrue(Result.isErr(failure));
19
+ * ```
20
+ */
21
+ export const isOk = (result) => result.$$tag === OkTypeTagName;
22
+ //# sourceMappingURL=result-is-ok.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-is-ok.mjs","sources":["../../../../src/functional/result/impl/result-is-ok.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { OkTypeTagName } from './tag.mjs';\nimport { type NarrowToOk } from './types.mjs';\n\n/**\n * Type guard for the ok variant.\n *\n * @example\n *\n * ```ts\n * const operation = Result.ok(3);\n *\n * const failure = Result.err('error');\n *\n * if (Result.isOk(operation)) {\n * const value: number = operation.value;\n *\n * assert.isTrue(value === 3);\n * }\n *\n * assert.isTrue(Result.isErr(failure));\n * ```\n */\nexport const isOk = <R extends UnknownResult>(\n result: R,\n): result is NarrowToOk<R> => result.$$tag === OkTypeTagName;\n"],"names":[],"mappings":";;AAuBO,MAAM,IAAA,GAAO,CAClB,MAAA,KAC4B,MAAA,CAAO,KAAA,KAAU;;;;"}
1
+ {"version":3,"file":"result-is-ok.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-ok.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,MAAS,EACgB,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,aAAa,CAAC"}
@@ -1,8 +1,26 @@
1
- import { hasKey } from '../../../guard/has-key.mjs';
2
- import { isRecord } from '../../../guard/is-record.mjs';
1
+ import { hasKey, isRecord } from '../../../guard/index.mjs';
3
2
  import { ErrTypeTagName, OkTypeTagName } from './tag.mjs';
4
-
5
- const isResult = (maybeResult) => isRecord(maybeResult) && hasKey(maybeResult, "$$tag") && hasKey(maybeResult, "value") && (maybeResult.$$tag === ErrTypeTagName || maybeResult.$$tag === OkTypeTagName);
6
-
7
- export { isResult };
8
- //# sourceMappingURL=result-is-result.mjs.map
3
+ /**
4
+ * Checks whether the provided value is a {@link Result<S, E>}.
5
+ *
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * const okValue = Result.ok('success');
10
+ *
11
+ * const errValue = Result.err(new Error('failure'));
12
+ *
13
+ * const notResult = { $$tag: 'ts-data-forge::Result.ok' } as const;
14
+ *
15
+ * assert.isTrue(Result.isResult(okValue));
16
+ *
17
+ * assert.isTrue(Result.isResult(errValue));
18
+ *
19
+ * assert.isFalse(Result.isResult(notResult));
20
+ * ```
21
+ */
22
+ export const isResult = (maybeResult) => isRecord(maybeResult) &&
23
+ hasKey(maybeResult, '$$tag') &&
24
+ hasKey(maybeResult, 'value') &&
25
+ (maybeResult.$$tag === ErrTypeTagName || maybeResult.$$tag === OkTypeTagName);
26
+ //# sourceMappingURL=result-is-result.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-is-result.mjs","sources":["../../../../src/functional/result/impl/result-is-result.mts"],"sourcesContent":["import { hasKey, isRecord } from '../../../guard/index.mjs';\nimport { type UnknownResult } from '../result.mjs';\nimport { ErrTypeTagName, OkTypeTagName } from './tag.mjs';\n\n/**\n * Checks whether the provided value is a {@link Result<S, E>}.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok('success');\n *\n * const errValue = Result.err(new Error('failure'));\n *\n * const notResult = { $$tag: 'ts-data-forge::Result.ok' } as const;\n *\n * assert.isTrue(Result.isResult(okValue));\n *\n * assert.isTrue(Result.isResult(errValue));\n *\n * assert.isFalse(Result.isResult(notResult));\n * ```\n */\nexport const isResult = (maybeResult: unknown): maybeResult is UnknownResult =>\n isRecord(maybeResult) &&\n hasKey(maybeResult, '$$tag') &&\n hasKey(maybeResult, 'value') &&\n (maybeResult.$$tag === ErrTypeTagName || maybeResult.$$tag === OkTypeTagName);\n"],"names":[],"mappings":";;;;AAuBO,MAAM,WAAW,CAAC,WAAA,KACvB,SAAS,WAAW,CAAA,IACpB,OAAO,WAAA,EAAa,OAAO,CAAA,IAC3B,MAAA,CAAO,aAAa,OAAO,CAAA,KAC1B,YAAY,KAAA,KAAU,cAAA,IAAkB,YAAY,KAAA,KAAU,aAAA;;;;"}
1
+ {"version":3,"file":"result-is-result.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-result.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAAoB,EAAgC,EAAE,CAC7E,QAAQ,CAAC,WAAW,CAAC;IACrB,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC;IAC5B,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC;IAC5B,CAAC,WAAW,CAAC,KAAK,KAAK,cAAc,IAAI,WAAW,CAAC,KAAK,KAAK,aAAa,CAAC,CAAC"}
@@ -1,25 +1,22 @@
1
1
  import { err } from './result-err.mjs';
2
2
  import { isOk } from './result-is-ok.mjs';
3
-
4
- function mapErr(...args) {
5
- switch (args.length) {
6
- case 2: {
7
- const [result, mapFn] = args;
8
- return mapErrImpl(result, mapFn);
3
+ export function mapErr(...args) {
4
+ switch (args.length) {
5
+ case 2: {
6
+ // Direct version: first argument is result
7
+ const [result, mapFn] = args;
8
+ return mapErrImpl(result, mapFn);
9
+ }
10
+ case 1: {
11
+ // Curried version: first argument is mapping function
12
+ const [mapFn] = args;
13
+ return (result) => mapErrImpl(result, mapFn);
14
+ }
9
15
  }
10
- case 1: {
11
- const [mapFn] = args;
12
- return (result) => mapErrImpl(result, mapFn);
13
- }
14
- }
15
16
  }
16
- const mapErrImpl = (result, mapFn) => isOk(result) ? (
17
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
18
- result
19
- ) : (
20
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
21
- err(mapFn(result.value))
22
- );
23
-
24
- export { mapErr };
25
- //# sourceMappingURL=result-map-err.mjs.map
17
+ const mapErrImpl = (result, mapFn) => isOk(result)
18
+ ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
19
+ result
20
+ : // eslint-disable-next-line total-functions/no-unsafe-type-assertion
21
+ err(mapFn(result.value));
22
+ //# sourceMappingURL=result-map-err.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-map-err.mjs","sources":["../../../../src/functional/result/impl/result-map-err.mts"],"sourcesContent":["import { type Ok } from '../../../types.mjs';\nimport { type Result, type UnknownResult } from '../result.mjs';\nimport { err } from './result-err.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Maps a `Result<S, E>` to `Result<S, E2>` by applying a function to the\n * error value. If the `Result` is `Result.Ok`, returns the original `Ok`.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok(3) as Result<number, string>;\n *\n * const errValue = Result.err('missing');\n *\n * const untouchedOk = Result.mapErr(okValue, (error) => error.toUpperCase());\n *\n * const uppercasedErr = Result.mapErr(errValue, (error) =>\n * error.toUpperCase(),\n * );\n *\n * assert.deepStrictEqual(untouchedOk, Result.ok(3));\n *\n * assert.deepStrictEqual(uppercasedErr, Result.err('MISSING'));\n *\n * const mapError = Result.mapErr((error: Readonly<Error>) => error.message);\n *\n * const wrapped = mapError(Result.err(new Error('boom')));\n *\n * assert.deepStrictEqual(wrapped, Result.err('boom'));\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @template E2 The type of the error value returned by the mapping function.\n * @param result The `Result` to map.\n * @param mapFn The function to apply to the error value if present.\n * @returns A new `Result<UnwrapOk<R>, E2>`.\n */\nexport function mapErr<R extends UnknownResult, E2>(\n result: R,\n mapFn: (error: UnwrapErr<R>) => E2,\n): Result<UnwrapOk<R>, E2>;\n\n// Curried version\n//\n// The returned function is generic over the *whole* result, mirroring the\n// direct overload above, rather than fixing its parameter to `Result<S, E>`.\n// Fixing it makes the curried form unusable from a caller that is itself\n// generic over the result: with `E` bound to `UnwrapErr<R>` at currying time the\n// parameter becomes `Result<...>` in terms of `R`, and TypeScript cannot show\n// a bare `R extends UnknownResult` is assignable to that — although every\n// concrete instantiation of `R` is.\n//\n// The conditional is what keeps the check: `R` is inferred from the argument\n// and its error type still has to satisfy `E`, so the mismatched case stays an\n// error. The cost is the message it produces — \"not assignable to `never`\"\n// rather than naming the two results.\nexport function mapErr<E, E2>(\n mapFn: (error: E) => E2,\n): <R extends UnknownResult>(\n result: UnwrapErr<R> extends E ? R : never,\n) => Result<UnwrapOk<R>, E2>;\n\nexport function mapErr<R extends UnknownResult, E2>(\n ...args:\n | readonly [result: R, mapFn: (error: UnwrapErr<R>) => E2]\n | readonly [mapFn: (error: UnwrapErr<R>) => E2]\n): Result<UnwrapOk<R>, E2> | ((result: R) => Result<UnwrapOk<R>, E2>) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, mapFn] = args;\n\n return mapErrImpl(result, mapFn);\n }\n\n case 1: {\n // Curried version: first argument is mapping function\n const [mapFn] = args;\n\n return (result: R) => mapErrImpl(result, mapFn);\n }\n }\n}\n\nconst mapErrImpl = <R extends UnknownResult, E2>(\n result: R,\n mapFn: (error: UnwrapErr<R>) => E2,\n): Result<UnwrapOk<R>, E2> =>\n isOk(result)\n ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (result as Ok<UnwrapOk<R>>)\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n err(mapFn(result.value as UnwrapErr<R>));\n"],"names":[],"mappings":";;;AAiEO,SAAS,UACX,IAAA,EAGiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AAExB,MAAA,OAAO,UAAA,CAAW,QAAQ,KAAK,CAAA;AAAA,IACjC;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,KAAK,CAAA,GAAI,IAAA;AAEhB,MAAA,OAAO,CAAC,MAAA,KAAc,UAAA,CAAW,MAAA,EAAQ,KAAK,CAAA;AAAA,IAChD;AAAA;AAEJ;AAEA,MAAM,UAAA,GAAa,CACjB,MAAA,EACA,KAAA,KAEA,KAAK,MAAM,CAAA;AAAA;AAAA,EAEN;AAAA;AAAA;AAAA,EAED,GAAA,CAAI,KAAA,CAAM,MAAA,CAAO,KAAqB,CAAC;AAAA,CAAA;;;;"}
1
+ {"version":3,"file":"result-map-err.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-map-err.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AA8D1C,MAAM,UAAU,MAAM,CACpB,GAAG,IAE8C;IAEjD,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,2CAA2C;YAC3C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;YAE7B,OAAO,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,sDAAsD;YACtD,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;YAErB,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,MAAS,EACT,KAAkC,EACT,EAAE,CAC3B,IAAI,CAAC,MAAM,CAAC;IACV,CAAC,CAAC,oEAAoE;QACnE,MAA0B;IAC7B,CAAC,CAAC,oEAAoE;QACpE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAqB,CAAC,CAAC,CAAC"}
@@ -1,25 +1,22 @@
1
1
  import { isErr } from './result-is-err.mjs';
2
2
  import { ok } from './result-ok.mjs';
3
-
4
- function map(...args) {
5
- switch (args.length) {
6
- case 2: {
7
- const [result, mapFn] = args;
8
- return mapImpl(result, mapFn);
3
+ export function map(...args) {
4
+ switch (args.length) {
5
+ case 2: {
6
+ // Direct version: first argument is result
7
+ const [result, mapFn] = args;
8
+ return mapImpl(result, mapFn);
9
+ }
10
+ case 1: {
11
+ // Curried version
12
+ const [mapFn] = args;
13
+ return (result) => mapImpl(result, mapFn);
14
+ }
9
15
  }
10
- case 1: {
11
- const [mapFn] = args;
12
- return (result) => mapImpl(result, mapFn);
13
- }
14
- }
15
16
  }
16
- const mapImpl = (result, mapFn) => isErr(result) ? (
17
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
18
- result
19
- ) : (
20
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
21
- ok(mapFn(result.value))
22
- );
23
-
24
- export { map };
25
- //# sourceMappingURL=result-map.mjs.map
17
+ const mapImpl = (result, mapFn) => isErr(result)
18
+ ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
19
+ result
20
+ : // eslint-disable-next-line total-functions/no-unsafe-type-assertion
21
+ ok(mapFn(result.value));
22
+ //# sourceMappingURL=result-map.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-map.mjs","sources":["../../../../src/functional/result/impl/result-map.mts"],"sourcesContent":["import { type Err } from '../../../types.mjs';\nimport { type Result, type UnknownResult } from '../result.mjs';\nimport { isErr } from './result-is-err.mjs';\nimport { ok } from './result-ok.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Maps a `Result<S, E>` to `Result<S2, E>` by applying a function to the\n * success value. If the `Result` is `Result.Err`, returns the original\n * `Err`.\n *\n * @example\n *\n * ```ts\n * const okNumber = Result.ok(5);\n *\n * const errMessage = Result.err('error');\n *\n * const doubled = Result.map(okNumber, (value) => value * 2);\n *\n * const untouchedError = Result.map(errMessage, (value: number) => value * 2);\n *\n * assert.deepStrictEqual(doubled, Result.ok(10));\n *\n * assert.deepStrictEqual(untouchedError, errMessage);\n *\n * const mapToLength = Result.map((text: string) => text.length);\n *\n * assert.deepStrictEqual(mapToLength(Result.ok('abc')), Result.ok(3));\n *\n * assert.deepStrictEqual(mapToLength(Result.err('bad')), Result.err('bad'));\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @template S2 The type of the success value returned by the mapping\n * function.\n * @param result The `Result` to map.\n * @param mapFn The function to apply to the success value if present.\n * @returns A new `Result<S2, UnwrapErr<R>>`.\n */\nexport function map<R extends UnknownResult, S2>(\n result: R,\n mapFn: (value: UnwrapOk<R>) => S2,\n): Result<S2, UnwrapErr<R>>;\n\n// Curried version\n//\n// The returned function is generic over the *whole* result, mirroring the\n// direct overload above, rather than fixing its parameter to `Result<S, E>`.\n// Fixing it makes the curried form unusable from a caller that is itself\n// generic over the result: with `S` bound to `UnwrapOk<R>` at currying time the\n// parameter becomes `Result<...>` in terms of `R`, and TypeScript cannot show\n// a bare `R extends UnknownResult` is assignable to that — although every\n// concrete instantiation of `R` is.\n//\n// The conditional is what keeps the check: `R` is inferred from the argument\n// and its success type still has to satisfy `S`, so the mismatched case stays an\n// error. The cost is the message it produces — \"not assignable to `never`\"\n// rather than naming the two results.\nexport function map<S, S2>(\n mapFn: (value: S) => S2,\n): <R extends UnknownResult>(\n result: UnwrapOk<R> extends S ? R : never,\n) => Result<S2, UnwrapErr<R>>;\n\nexport function map<R extends UnknownResult, S2>(\n ...args:\n | readonly [result: R, mapFn: (value: UnwrapOk<R>) => S2]\n | readonly [mapFn: (value: UnwrapOk<R>) => S2]\n): Result<S2, UnwrapErr<R>> | ((result: R) => Result<S2, UnwrapErr<R>>) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, mapFn] = args;\n\n return mapImpl(result, mapFn);\n }\n\n case 1: {\n // Curried version\n const [mapFn] = args;\n\n return (result: R) => mapImpl(result, mapFn);\n }\n }\n}\n\nconst mapImpl = <R extends UnknownResult, S2>(\n result: R,\n mapFn: (value: UnwrapOk<R>) => S2,\n): Result<S2, UnwrapErr<R>> =>\n isErr(result)\n ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (result as Err<UnwrapErr<R>>)\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n ok(mapFn(result.value as UnwrapOk<R>));\n"],"names":[],"mappings":";;;AAiEO,SAAS,OACX,IAAA,EAGmE;AACtE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AAExB,MAAA,OAAO,OAAA,CAAQ,QAAQ,KAAK,CAAA;AAAA,IAC9B;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,KAAK,CAAA,GAAI,IAAA;AAEhB,MAAA,OAAO,CAAC,MAAA,KAAc,OAAA,CAAQ,MAAA,EAAQ,KAAK,CAAA;AAAA,IAC7C;AAAA;AAEJ;AAEA,MAAM,OAAA,GAAU,CACd,MAAA,EACA,KAAA,KAEA,MAAM,MAAM,CAAA;AAAA;AAAA,EAEP;AAAA;AAAA;AAAA,EAED,EAAA,CAAG,KAAA,CAAM,MAAA,CAAO,KAAoB,CAAC;AAAA,CAAA;;;;"}
1
+ {"version":3,"file":"result-map.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-map.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AA8DrC,MAAM,UAAU,GAAG,CACjB,GAAG,IAE6C;IAEhD,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,2CAA2C;YAC3C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;YAE7B,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,kBAAkB;YAClB,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;YAErB,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,OAAO,GAAG,CACd,MAAS,EACT,KAAiC,EACP,EAAE,CAC5B,KAAK,CAAC,MAAM,CAAC;IACX,CAAC,CAAC,oEAAoE;QACnE,MAA4B;IAC/B,CAAC,CAAC,oEAAoE;QACpE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAoB,CAAC,CAAC,CAAC"}
@@ -1,24 +1,20 @@
1
1
  import { isOk } from './result-is-ok.mjs';
2
-
3
- function match(...args) {
4
- switch (args.length) {
5
- case 2: {
6
- const [result, cases] = args;
7
- return matchImpl(result, cases);
2
+ export function match(...args) {
3
+ switch (args.length) {
4
+ case 2: {
5
+ const [result, cases] = args;
6
+ return matchImpl(result, cases);
7
+ }
8
+ case 1: {
9
+ // Curried version: the only argument is the case handlers
10
+ const [cases] = args;
11
+ return (result) => matchImpl(result, cases);
12
+ }
8
13
  }
9
- case 1: {
10
- const [cases] = args;
11
- return (result) => matchImpl(result, cases);
12
- }
13
- }
14
14
  }
15
- const matchImpl = (result, cases) => isOk(result) ? (
16
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
17
- cases.ok(result.value)
18
- ) : (
19
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
20
- cases.err(result.value)
21
- );
22
-
23
- export { match };
24
- //# sourceMappingURL=result-match.mjs.map
15
+ const matchImpl = (result, cases) => isOk(result)
16
+ ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
17
+ cases.ok(result.value)
18
+ : // eslint-disable-next-line total-functions/no-unsafe-type-assertion
19
+ cases.err(result.value);
20
+ //# sourceMappingURL=result-match.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-match.mjs","sources":["../../../../src/functional/result/impl/result-match.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Folds a `Result` into a plain value by applying one of two case handlers:\n * `ok` if the `Result` is `Ok`, `err` otherwise. This is the function form of\n * pattern matching on a `Result`.\n *\n * Unlike {@link Result.fold}, which maps both sides and returns another\n * `Result`, `match` unwraps: both branches produce the final value directly.\n *\n * @example\n *\n * ```ts\n * const doubledOrZero = Result.match(Result.ok(21), {\n * ok: (value) => value * 2,\n * err: () => 0,\n * });\n *\n * assert.deepStrictEqual(doubledOrZero, 42);\n *\n * const matcher = Result.match({\n * ok: (value: number) => value + 1,\n * err: (error: string) => error.length,\n * });\n *\n * assert.deepStrictEqual(matcher(Result.ok(1)), 2);\n *\n * assert.deepStrictEqual(matcher(Result.err('oops')), 4);\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @template S2 The type returned by the `ok` case.\n * @template E2 The type returned by the `err` case.\n * @param result The `Result` to match on.\n * @param cases An object with an `ok` handler receiving the success value and\n * an `err` handler receiving the error value.\n * @returns The value produced by whichever case handler was applied.\n */\nexport function match<R extends UnknownResult, S2, E2>(\n result: R,\n cases: Readonly<{\n ok: (value: UnwrapOk<R>) => S2;\n err: (error: UnwrapErr<R>) => E2;\n }>,\n): E2 | S2;\n\n// Curried version\n//\n// The returned function is generic over the *whole* result, mirroring the\n// direct overload above; see the comment on the curried overload of\n// `Result.map` for why the parameter is a conditional type instead of a plain\n// `Result<S, E>`. Both sides have to be checked here, hence the nested\n// conditional.\nexport function match<S, E, S2, E2>(\n cases: Readonly<{\n ok: (value: S) => S2;\n err: (error: E) => E2;\n }>,\n): <R extends UnknownResult>(\n result: UnwrapOk<R> extends S ? (UnwrapErr<R> extends E ? R : never) : never,\n) => E2 | S2;\n\nexport function match<R extends UnknownResult, S2, E2>(\n ...args:\n | readonly [\n result: R,\n cases: Readonly<{\n ok: (value: UnwrapOk<R>) => S2;\n err: (error: UnwrapErr<R>) => E2;\n }>,\n ]\n | readonly [\n cases: Readonly<{\n ok: (value: UnwrapOk<R>) => S2;\n err: (error: UnwrapErr<R>) => E2;\n }>,\n ]\n): E2 | S2 | ((result: R) => E2 | S2) {\n switch (args.length) {\n case 2: {\n const [result, cases] = args;\n\n return matchImpl(result, cases);\n }\n\n case 1: {\n // Curried version: the only argument is the case handlers\n const [cases] = args;\n\n return (result: R) => matchImpl(result, cases);\n }\n }\n}\n\nconst matchImpl = <R extends UnknownResult, S2, E2>(\n result: R,\n cases: Readonly<{\n ok: (value: UnwrapOk<R>) => S2;\n err: (error: UnwrapErr<R>) => E2;\n }>,\n): E2 | S2 =>\n isOk(result)\n ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n cases.ok(result.value as UnwrapOk<R>)\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n cases.err(result.value as UnwrapErr<R>);\n"],"names":[],"mappings":";;AAgEO,SAAS,SACX,IAAA,EAciC;AACpC,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AAExB,MAAA,OAAO,SAAA,CAAU,QAAQ,KAAK,CAAA;AAAA,IAChC;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,KAAK,CAAA,GAAI,IAAA;AAEhB,MAAA,OAAO,CAAC,MAAA,KAAc,SAAA,CAAU,MAAA,EAAQ,KAAK,CAAA;AAAA,IAC/C;AAAA;AAEJ;AAEA,MAAM,SAAA,GAAY,CAChB,MAAA,EACA,KAAA,KAKA,KAAK,MAAM,CAAA;AAAA;AAAA,EAEP,KAAA,CAAM,EAAA,CAAG,MAAA,CAAO,KAAoB;AAAA;AAAA;AAAA,EAEpC,KAAA,CAAM,GAAA,CAAI,MAAA,CAAO,KAAqB;AAAA,CAAA;;;;"}
1
+ {"version":3,"file":"result-match.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-match.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AA+D1C,MAAM,UAAU,KAAK,CACnB,GAAG,IAaE;IAEL,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;YAE7B,OAAO,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,0DAA0D;YAC1D,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;YAErB,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,SAAS,GAAG,CAChB,MAAS,EACT,KAGE,EACO,EAAE,CACX,IAAI,CAAC,MAAM,CAAC;IACV,CAAC,CAAC,oEAAoE;QACpE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAoB,CAAC;IACvC,CAAC,CAAC,oEAAoE;QACpE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAqB,CAAC,CAAC"}
@@ -1,9 +1,31 @@
1
1
  import { OkTypeTagName } from './tag.mjs';
2
-
3
- const ok = (value) => ({
4
- $$tag: OkTypeTagName,
5
- value
2
+ /**
3
+ * Creates a `Result.Ok` containing the given success value.
4
+ *
5
+ * Use this constructor when an operation succeeds and you want to wrap the
6
+ * successful result in a Result type for consistent error handling.
7
+ *
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * const success = Result.ok({ id: 1 });
12
+ *
13
+ * const failure = Result.err(new Error('missing data'));
14
+ *
15
+ * assert.deepStrictEqual(success, {
16
+ * $$tag: 'ts-data-forge::Result.ok',
17
+ * value: { id: 1 },
18
+ * });
19
+ *
20
+ * assert.isTrue(Result.isErr(failure));
21
+ * ```
22
+ *
23
+ * @template S The type of the success value.
24
+ * @param value The success value.
25
+ * @returns A `Result.Ok<S>` containing the value.
26
+ */
27
+ export const ok = (value) => ({
28
+ $$tag: OkTypeTagName,
29
+ value,
6
30
  });
7
-
8
- export { ok };
9
- //# sourceMappingURL=result-ok.mjs.map
31
+ //# sourceMappingURL=result-ok.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-ok.mjs","sources":["../../../../src/functional/result/impl/result-ok.mts"],"sourcesContent":["import { type Ok } from '../../../types.mjs';\nimport { OkTypeTagName } from './tag.mjs';\n\n/**\n * Creates a `Result.Ok` containing the given success value.\n *\n * Use this constructor when an operation succeeds and you want to wrap the\n * successful result in a Result type for consistent error handling.\n *\n * @example\n *\n * ```ts\n * const success = Result.ok({ id: 1 });\n *\n * const failure = Result.err(new Error('missing data'));\n *\n * assert.deepStrictEqual(success, {\n * $$tag: 'ts-data-forge::Result.ok',\n * value: { id: 1 },\n * });\n *\n * assert.isTrue(Result.isErr(failure));\n * ```\n *\n * @template S The type of the success value.\n * @param value The success value.\n * @returns A `Result.Ok<S>` containing the value.\n */\nexport const ok = <const S,>(value: S): Ok<S> =>\n ({\n $$tag: OkTypeTagName,\n value,\n }) as const;\n"],"names":[],"mappings":";;AA4BO,MAAM,EAAA,GAAK,CAAW,KAAA,MAC1B;AAAA,EACC,KAAA,EAAO,aAAA;AAAA,EACP;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"result-ok.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-ok.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAAW,KAAQ,EAAS,EAAE,CAC9C,CAAC;IACC,KAAK,EAAE,aAAa;IACpB,KAAK;CACN,CAAU,CAAC"}
@@ -1,18 +1,17 @@
1
1
  import { isOk } from './result-is-ok.mjs';
2
-
3
- function orElse(...args) {
4
- switch (args.length) {
5
- case 2: {
6
- const [result, alternative] = args;
7
- return orElseImpl(result, alternative);
2
+ export function orElse(...args) {
3
+ switch (args.length) {
4
+ case 2: {
5
+ // Direct version: first argument is result
6
+ const [result, alternative] = args;
7
+ return orElseImpl(result, alternative);
8
+ }
9
+ case 1: {
10
+ // Curried version
11
+ const [alternative] = args;
12
+ return (result) => orElseImpl(result, alternative);
13
+ }
8
14
  }
9
- case 1: {
10
- const [alternative] = args;
11
- return (result) => orElseImpl(result, alternative);
12
- }
13
- }
14
15
  }
15
- const orElseImpl = (result, alternative) => isOk(result) ? result : alternative;
16
-
17
- export { orElse };
18
- //# sourceMappingURL=result-or-else.mjs.map
16
+ const orElseImpl = (result, alternative) => (isOk(result) ? result : alternative);
17
+ //# sourceMappingURL=result-or-else.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-or-else.mjs","sources":["../../../../src/functional/result/impl/result-or-else.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { type NarrowToOk } from './types.mjs';\n\n/**\n * Returns the `Result` if it is `Ok`, otherwise returns the alternative.\n *\n * @example\n *\n * ```ts\n * const primary = Result.ok('primary');\n *\n * const fallback = Result.ok('fallback');\n *\n * const failure = Result.err('failure');\n *\n * assert.deepStrictEqual(Result.orElse(primary, fallback), primary);\n *\n * assert.deepStrictEqual(Result.orElse(failure, fallback), fallback);\n *\n * const orElseFallback = Result.orElse(Result.ok('default'));\n *\n * assert.deepStrictEqual(\n * orElseFallback(Result.err('missing')),\n * Result.ok('default'),\n * );\n *\n * assert.deepStrictEqual(\n * orElseFallback(Result.ok('value')),\n * Result.ok('value'),\n * );\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @param result The `Result` to check.\n * @param alternative The alternative `Result` to return if the first is\n * `Err`.\n * @returns The first `Result` if `Ok`, otherwise the alternative.\n */\nexport function orElse<R extends UnknownResult, R2 extends UnknownResult>(\n result: R,\n alternative: R2,\n): NarrowToOk<R> | R2;\n\n// Curried version\nexport function orElse<R2 extends UnknownResult>(\n alternative: R2,\n): <R extends UnknownResult>(result: R) => NarrowToOk<R> | R2;\n\nexport function orElse<R extends UnknownResult, R2 extends UnknownResult>(\n ...args: readonly [result: R, alternative: R2] | readonly [alternative: R2]\n): (NarrowToOk<R> | R2) | ((result: R) => R | R2) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, alternative] = args;\n\n return orElseImpl(result, alternative);\n }\n\n case 1: {\n // Curried version\n const [alternative] = args;\n\n return (result: R) => orElseImpl(result, alternative);\n }\n }\n}\n\nconst orElseImpl = <R extends UnknownResult, R2 extends UnknownResult>(\n result: R,\n alternative: R2,\n): NarrowToOk<R> | R2 => (isOk(result) ? result : alternative);\n"],"names":[],"mappings":";;AAiDO,SAAS,UACX,IAAA,EAC6C;AAChD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,WAAW,CAAA,GAAI,IAAA;AAE9B,MAAA,OAAO,UAAA,CAAW,QAAQ,WAAW,CAAA;AAAA,IACvC;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,WAAW,CAAA,GAAI,IAAA;AAEtB,MAAA,OAAO,CAAC,MAAA,KAAc,UAAA,CAAW,MAAA,EAAQ,WAAW,CAAA;AAAA,IACtD;AAAA;AAEJ;AAEA,MAAM,aAAa,CACjB,MAAA,EACA,gBACwB,IAAA,CAAK,MAAM,IAAI,MAAA,GAAS,WAAA;;;;"}
1
+ {"version":3,"file":"result-or-else.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-or-else.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAgD1C,MAAM,UAAU,MAAM,CACpB,GAAG,IAAwE;IAE3E,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,2CAA2C;YAC3C,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC;YAEnC,OAAO,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACzC,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,kBAAkB;YAClB,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;YAE3B,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,MAAS,EACT,WAAe,EACK,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC"}
@@ -1,24 +1,35 @@
1
- import { hasKey } from '../../../guard/has-key.mjs';
2
- import { isRecord } from '../../../guard/is-record.mjs';
3
-
4
- function safeTry(body) {
5
- const generator = body();
6
- const step = generator.next();
7
- if (isSyncStep(step)) {
8
- if (step.done !== true && isSyncGenerator(generator, step)) {
9
- generator.return(step.value);
1
+ import { hasKey, isRecord } from '../../../guard/index.mjs';
2
+ export function safeTry(body) {
3
+ const generator = body();
4
+ // A yielded `Err` and a returned `Result` are both already the final
5
+ // answer, so the first step's `value` is the result in either case: the
6
+ // generator is closed rather than resumed after yielding.
7
+ const step = generator.next();
8
+ if (isSyncStep(step)) {
9
+ // Dropping a suspended generator would skip the `finally` blocks and
10
+ // `using` disposals still pending in the body; closing it runs them
11
+ // before the short-circuited `Err` is handed back. `isSyncGenerator` is
12
+ // what makes `return()` here synchronous rather than a floating promise.
13
+ if (step.done !== true && isSyncGenerator(generator, step)) {
14
+ generator.return(step.value);
15
+ }
16
+ return step.value;
10
17
  }
11
- return step.value;
12
- }
13
- return step.then(async (asyncStep) => {
14
- if (asyncStep.done !== true) {
15
- await generator.return(asyncStep.value);
16
- }
17
- return asyncStep.value;
18
- });
18
+ return step.then(async (asyncStep) => {
19
+ if (asyncStep.done !== true) {
20
+ await generator.return(asyncStep.value);
21
+ }
22
+ return asyncStep.value;
23
+ });
19
24
  }
20
- const isSyncStep = (value) => isRecord(value) && hasKey(value, "done");
25
+ // A sync generator's `next()` returns a plain `{ value, done }` object with
26
+ // own properties, while an async generator's returns a `Promise`, whose
27
+ // `then` lives on the prototype — so an own-key check on `done` separates the
28
+ // two.
29
+ const isSyncStep = (value) => isRecord(value) && hasKey(value, 'done');
30
+ // The generator-side counterpart of `isSyncStep`: a step in the sync form can
31
+ // only have come from a sync generator, so the step is what narrows the
32
+ // generator that produced it — hence the predicate reads its second argument
33
+ // and not its first.
21
34
  const isSyncGenerator = (_generator, step) => isSyncStep(step);
22
-
23
- export { safeTry };
24
- //# sourceMappingURL=result-safe-try.mjs.map
35
+ //# sourceMappingURL=result-safe-try.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-safe-try.mjs","sources":["../../../../src/functional/result/impl/result-safe-try.mts"],"sourcesContent":["import { hasKey, isRecord } from '../../../guard/index.mjs';\nimport { type Err } from '../../../types.mjs';\nimport { type Result, type UnknownResult } from '../result.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Runs a generator body in which `yield* Result.safeUnwrap(...)` unwraps `Ok`\n * values and short-circuits on the first `Err`, emulating Rust's `?` operator\n * (early-return error propagation).\n *\n * The body must return a `Result`. If every unwrapped `Result` is `Ok`, the\n * returned value is the body's `Result`; otherwise it is the first `Err`\n * encountered, and the rest of the body never runs — though the generator is\n * closed rather than dropped, so `finally` blocks and `using` disposals\n * pending in the body still run. An exception thrown by the body is not\n * converted to an `Err`: it propagates out of `safeTry` (as a rejected\n * `Promise` for an async body). Use {@link Result.fromThrowable} for that.\n *\n * Passing an async generator (`async function*`) returns a\n * `Promise<Result<...>>` instead, so `await` can be used inside the body.\n * Note that `yield*` inside an `async function*` awaits what it receives, so\n * unwrapping an `Ok` whose value is itself a `Promise` yields the awaited\n * value there while the static type still says `Promise<...>`; keep promises\n * out of the `Ok` side of a `Result` unwrapped in an async body.\n *\n * @example\n *\n * ```ts\n * const parseTwo = (a: string, b: string): Result<number, Error> =>\n * Result.safeTry(function* () {\n * const x = yield* Result.safeUnwrap(Num.safeParseInt(a));\n *\n * const y = yield* Result.safeUnwrap(Num.safeParseInt(b));\n *\n * return Result.ok(x + y);\n * });\n *\n * assert.deepStrictEqual(parseTwo('1', '2'), Result.ok(3));\n *\n * assert.isTrue(Result.isErr(parseTwo('1', 'not a number')));\n * ```\n *\n * @template Y The union of `Err` types unwrapped via\n * {@link Result.safeUnwrap} (`never` if nothing is unwrapped).\n * @template R2 The `Result` type returned by the body.\n * @param body A generator function whose `yield*` expressions delegate to\n * {@link Result.safeUnwrap} and whose return value is a `Result`.\n * @returns The body's `Result`, or the first `Err` short-circuited out of it\n * (wrapped in a `Promise` for an async generator body).\n */\nexport function safeTry<Y extends Err<unknown>, R2 extends UnknownResult>(\n body: () => Generator<Y, R2>,\n): Result<UnwrapOk<R2>, UnwrapErr<R2> | UnwrapErr<Y>>;\n\nexport function safeTry<Y extends Err<unknown>, R2 extends UnknownResult>(\n body: () => AsyncGenerator<Y, R2>,\n): Promise<Result<UnwrapOk<R2>, UnwrapErr<R2> | UnwrapErr<Y>>>;\n\nexport function safeTry(\n body:\n | (() => AsyncGenerator<UnknownResult, UnknownResult>)\n | (() => Generator<UnknownResult, UnknownResult>),\n): Promise<UnknownResult> | UnknownResult {\n const generator = body();\n\n // A yielded `Err` and a returned `Result` are both already the final\n // answer, so the first step's `value` is the result in either case: the\n // generator is closed rather than resumed after yielding.\n const step = generator.next();\n\n if (isSyncStep(step)) {\n // Dropping a suspended generator would skip the `finally` blocks and\n // `using` disposals still pending in the body; closing it runs them\n // before the short-circuited `Err` is handed back. `isSyncGenerator` is\n // what makes `return()` here synchronous rather than a floating promise.\n if (step.done !== true && isSyncGenerator(generator, step)) {\n generator.return(step.value);\n }\n\n return step.value;\n }\n\n return step.then(async (asyncStep) => {\n if (asyncStep.done !== true) {\n await generator.return(asyncStep.value);\n }\n\n return asyncStep.value;\n });\n}\n\n// A sync generator's `next()` returns a plain `{ value, done }` object with\n// own properties, while an async generator's returns a `Promise`, whose\n// `then` lives on the prototype — so an own-key check on `done` separates the\n// two.\nconst isSyncStep = (\n value: unknown,\n): value is IteratorResult<UnknownResult, UnknownResult> =>\n isRecord(value) && hasKey(value, 'done');\n\n// The generator-side counterpart of `isSyncStep`: a step in the sync form can\n// only have come from a sync generator, so the step is what narrows the\n// generator that produced it — hence the predicate reads its second argument\n// and not its first.\nconst isSyncGenerator = (\n _generator:\n | AsyncGenerator<UnknownResult, UnknownResult>\n | Generator<UnknownResult, UnknownResult>,\n step: unknown,\n): _generator is Generator<UnknownResult, UnknownResult> => isSyncStep(step);\n"],"names":[],"mappings":";;;AA0DO,SAAS,QACd,IAAA,EAGwC;AACxC,EAAA,MAAM,YAAY,IAAA,EAAK;AAKvB,EAAA,MAAM,IAAA,GAAO,UAAU,IAAA,EAAK;AAE5B,EAAA,IAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AAKpB,IAAA,IAAI,KAAK,IAAA,KAAS,IAAA,IAAQ,eAAA,CAAgB,SAAA,EAAW,IAAI,CAAA,EAAG;AAC1D,MAAA,SAAA,CAAU,MAAA,CAAO,KAAK,KAAK,CAAA;AAAA,IAC7B;AAEA,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AAEA,EAAA,OAAO,IAAA,CAAK,IAAA,CAAK,OAAO,SAAA,KAAc;AACpC,IAAA,IAAI,SAAA,CAAU,SAAS,IAAA,EAAM;AAC3B,MAAA,MAAM,SAAA,CAAU,MAAA,CAAO,SAAA,CAAU,KAAK,CAAA;AAAA,IACxC;AAEA,IAAA,OAAO,SAAA,CAAU,KAAA;AAAA,EACnB,CAAC,CAAA;AACH;AAMA,MAAM,UAAA,GAAa,CACjB,KAAA,KAEA,QAAA,CAAS,KAAK,CAAA,IAAK,MAAA,CAAO,OAAO,MAAM,CAAA;AAMzC,MAAM,eAAA,GAAkB,CACtB,UAAA,EAGA,IAAA,KAC0D,WAAW,IAAI,CAAA;;;;"}
1
+ {"version":3,"file":"result-safe-try.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-safe-try.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AA0D5D,MAAM,UAAU,OAAO,CACrB,IAEmD;IAEnD,MAAM,SAAS,GAAG,IAAI,EAAE,CAAC;IAEzB,qEAAqE;IACrE,wEAAwE;IACxE,0DAA0D;IAC1D,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;IAE9B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,qEAAqE;QACrE,oEAAoE;QACpE,wEAAwE;QACxE,yEAAyE;QACzE,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC;YAC3D,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACnC,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAC5B,MAAM,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;QAED,OAAO,SAAS,CAAC,KAAK,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,4EAA4E;AAC5E,wEAAwE;AACxE,8EAA8E;AAC9E,OAAO;AACP,MAAM,UAAU,GAAG,CACjB,KAAc,EACyC,EAAE,CACzD,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3C,8EAA8E;AAC9E,wEAAwE;AACxE,6EAA6E;AAC7E,qBAAqB;AACrB,MAAM,eAAe,GAAG,CACtB,UAE2C,EAC3C,IAAa,EAC0C,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC"}
@@ -1,14 +1,42 @@
1
1
  import { isErr } from './result-is-err.mjs';
2
-
3
- function* safeUnwrap(result) {
4
- if (isErr(result)) {
5
- yield result;
6
- throw new Error(
7
- "`safeUnwrap()` generator was resumed after yielding an `Err`; it must only be used via `yield*` inside `safeTry()`"
8
- );
9
- }
10
- return result.value;
2
+ /**
3
+ * Unwraps a `Result` inside a {@link Result.safeTry} generator body via
4
+ * `yield*`, emulating Rust's `?` operator.
5
+ *
6
+ * If the `Result` is `Ok`, the `yield*` expression evaluates to the contained
7
+ * value and execution continues. If it is `Err`, the error is yielded to
8
+ * {@link Result.safeTry}, which returns it immediately — the rest of the
9
+ * generator body never runs.
10
+ *
11
+ * This generator must only be delegated to (`yield*`) inside a
12
+ * {@link Result.safeTry} body; resuming it after it has yielded an `Err`
13
+ * throws.
14
+ *
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * const result = Result.safeTry(function* () {
19
+ * const x = yield* Result.safeUnwrap(Result.ok(2));
20
+ *
21
+ * const y = yield* Result.safeUnwrap(Result.ok(3));
22
+ *
23
+ * return Result.ok(x + y);
24
+ * });
25
+ *
26
+ * assert.deepStrictEqual(result, Result.ok(5));
27
+ * ```
28
+ *
29
+ * @template R The input `UnknownResult` type.
30
+ * @param result The `Result` to unwrap.
31
+ * @returns A generator that yields the `Err` (if any) and returns the `Ok`
32
+ * value.
33
+ */
34
+ export function* safeUnwrap(result) {
35
+ if (isErr(result)) {
36
+ yield result;
37
+ throw new Error('`safeUnwrap()` generator was resumed after yielding an `Err`; it must only be used via `yield*` inside `safeTry()`');
38
+ }
39
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
40
+ return result.value;
11
41
  }
12
-
13
- export { safeUnwrap };
14
- //# sourceMappingURL=result-safe-unwrap.mjs.map
42
+ //# sourceMappingURL=result-safe-unwrap.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-safe-unwrap.mjs","sources":["../../../../src/functional/result/impl/result-safe-unwrap.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { isErr } from './result-is-err.mjs';\nimport { type NarrowToErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Unwraps a `Result` inside a {@link Result.safeTry} generator body via\n * `yield*`, emulating Rust's `?` operator.\n *\n * If the `Result` is `Ok`, the `yield*` expression evaluates to the contained\n * value and execution continues. If it is `Err`, the error is yielded to\n * {@link Result.safeTry}, which returns it immediately — the rest of the\n * generator body never runs.\n *\n * This generator must only be delegated to (`yield*`) inside a\n * {@link Result.safeTry} body; resuming it after it has yielded an `Err`\n * throws.\n *\n * @example\n *\n * ```ts\n * const result = Result.safeTry(function* () {\n * const x = yield* Result.safeUnwrap(Result.ok(2));\n *\n * const y = yield* Result.safeUnwrap(Result.ok(3));\n *\n * return Result.ok(x + y);\n * });\n *\n * assert.deepStrictEqual(result, Result.ok(5));\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @param result The `Result` to unwrap.\n * @returns A generator that yields the `Err` (if any) and returns the `Ok`\n * value.\n */\nexport function* safeUnwrap<R extends UnknownResult>(\n result: R,\n): Generator<NarrowToErr<R>, UnwrapOk<R>, unknown> {\n if (isErr(result)) {\n yield result;\n\n throw new Error(\n '`safeUnwrap()` generator was resumed after yielding an `Err`; it must only be used via `yield*` inside `safeTry()`',\n );\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return result.value as UnwrapOk<R>;\n}\n"],"names":[],"mappings":";;AAoCO,UAAU,WACf,MAAA,EACiD;AACjD,EAAA,IAAI,KAAA,CAAM,MAAM,CAAA,EAAG;AACjB,IAAA,MAAM,MAAA;AAEN,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAGA,EAAA,OAAO,MAAA,CAAO,KAAA;AAChB;;;;"}
1
+ {"version":3,"file":"result-safe-unwrap.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-safe-unwrap.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,SAAS,CAAC,CAAC,UAAU,CACzB,MAAS;IAET,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAClB,MAAM,MAAM,CAAC;QAEb,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,OAAO,MAAM,CAAC,KAAoB,CAAC;AACrC,CAAC"}