ts-data-forge 14.6.1 → 14.6.3

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 (420) 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 +68 -52
  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 +70 -32
  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 +99 -149
  18. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  19. package/dist/array/impl/array-utils-search.mjs +112 -136
  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 +92 -76
  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 +53 -55
  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 -292
  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.mjs +448 -265
  44. package/dist/collections/iset-mapped.mjs.map +1 -1
  45. package/dist/collections/iset.mjs +328 -201
  46. package/dist/collections/iset.mjs.map +1 -1
  47. package/dist/collections/queue.mjs +181 -149
  48. package/dist/collections/queue.mjs.map +1 -1
  49. package/dist/collections/stack.mjs +167 -138
  50. package/dist/collections/stack.mjs.map +1 -1
  51. package/dist/entry-point.mjs +4 -77
  52. package/dist/entry-point.mjs.map +1 -1
  53. package/dist/expect-type.mjs +69 -3
  54. package/dist/expect-type.mjs.map +1 -1
  55. package/dist/functional/async-result/async-result.mjs +2 -3
  56. package/dist/functional/async-result/async-result.mjs.map +1 -1
  57. package/dist/functional/async-result/impl/async-result-flat-map.mjs +18 -20
  58. package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +1 -1
  59. package/dist/functional/async-result/impl/async-result-from-promise.mjs +9 -10
  60. package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +1 -1
  61. package/dist/functional/async-result/impl/async-result-from-throwable.mjs +12 -14
  62. package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +1 -1
  63. package/dist/functional/async-result/impl/async-result-map-err.mjs +15 -18
  64. package/dist/functional/async-result/impl/async-result-map-err.mjs.map +1 -1
  65. package/dist/functional/async-result/impl/async-result-map.mjs +15 -18
  66. package/dist/functional/async-result/impl/async-result-map.mjs.map +1 -1
  67. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +35 -8
  68. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +1 -1
  69. package/dist/functional/async-result/impl/index.mjs +8 -7
  70. package/dist/functional/async-result/impl/index.mjs.map +1 -1
  71. package/dist/functional/async-result/impl/types.mjs +2 -2
  72. package/dist/functional/async-result/impl/types.mjs.map +1 -1
  73. package/dist/functional/async-result/index.mjs +2 -3
  74. package/dist/functional/async-result/index.mjs.map +1 -1
  75. package/dist/functional/index.mjs +7 -11
  76. package/dist/functional/index.mjs.map +1 -1
  77. package/dist/functional/match.mjs +27 -13
  78. package/dist/functional/match.mjs.map +1 -1
  79. package/dist/functional/optional/impl/index.mjs +19 -18
  80. package/dist/functional/optional/impl/index.mjs.map +1 -1
  81. package/dist/functional/optional/impl/optional-expect-to-be.mjs +15 -17
  82. package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
  83. package/dist/functional/optional/impl/optional-filter.mjs +16 -18
  84. package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
  85. package/dist/functional/optional/impl/optional-flat-map.mjs +12 -14
  86. package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
  87. package/dist/functional/optional/impl/optional-from-nullable.mjs +24 -3
  88. package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
  89. package/dist/functional/optional/impl/optional-is-none.mjs +19 -3
  90. package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
  91. package/dist/functional/optional/impl/optional-is-optional.mjs +24 -6
  92. package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
  93. package/dist/functional/optional/impl/optional-is-some.mjs +20 -3
  94. package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
  95. package/dist/functional/optional/impl/optional-map.mjs +15 -17
  96. package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
  97. package/dist/functional/optional/impl/optional-match.mjs +15 -17
  98. package/dist/functional/optional/impl/optional-match.mjs.map +1 -1
  99. package/dist/functional/optional/impl/optional-none.mjs +16 -3
  100. package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
  101. package/dist/functional/optional/impl/optional-or-else.mjs +12 -14
  102. package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
  103. package/dist/functional/optional/impl/optional-some.mjs +22 -6
  104. package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
  105. package/dist/functional/optional/impl/optional-to-nullable.mjs +26 -3
  106. package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
  107. package/dist/functional/optional/impl/optional-unwrap-or.mjs +11 -13
  108. package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
  109. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +33 -8
  110. package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
  111. package/dist/functional/optional/impl/optional-unwrap.mjs +6 -9
  112. package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
  113. package/dist/functional/optional/impl/optional-zip.mjs +34 -3
  114. package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
  115. package/dist/functional/optional/impl/tag.mjs +3 -4
  116. package/dist/functional/optional/impl/tag.mjs.map +1 -1
  117. package/dist/functional/optional/impl/types.mjs +2 -2
  118. package/dist/functional/optional/impl/types.mjs.map +1 -1
  119. package/dist/functional/optional/index.mjs +2 -3
  120. package/dist/functional/optional/index.mjs.map +1 -1
  121. package/dist/functional/optional/optional.mjs +2 -3
  122. package/dist/functional/optional/optional.mjs.map +1 -1
  123. package/dist/functional/pipe.mjs +42 -14
  124. package/dist/functional/pipe.mjs.map +1 -1
  125. package/dist/functional/result/impl/index.mjs +28 -27
  126. package/dist/functional/result/impl/index.mjs.map +1 -1
  127. package/dist/functional/result/impl/result-err.mjs +28 -6
  128. package/dist/functional/result/impl/result-err.mjs.map +1 -1
  129. package/dist/functional/result/impl/result-expect-to-be.mjs +16 -17
  130. package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
  131. package/dist/functional/result/impl/result-flat-map.mjs +17 -20
  132. package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
  133. package/dist/functional/result/impl/result-fold.mjs +17 -20
  134. package/dist/functional/result/impl/result-fold.mjs.map +1 -1
  135. package/dist/functional/result/impl/result-from-optional.mjs +16 -19
  136. package/dist/functional/result/impl/result-from-optional.mjs.map +1 -1
  137. package/dist/functional/result/impl/result-from-promise.mjs +35 -6
  138. package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
  139. package/dist/functional/result/impl/result-from-throwable.mjs +40 -13
  140. package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
  141. package/dist/functional/result/impl/result-is-err.mjs +19 -3
  142. package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
  143. package/dist/functional/result/impl/result-is-ok.mjs +19 -3
  144. package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
  145. package/dist/functional/result/impl/result-is-result.mjs +23 -5
  146. package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
  147. package/dist/functional/result/impl/result-map-err.mjs +17 -20
  148. package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
  149. package/dist/functional/result/impl/result-map.mjs +17 -20
  150. package/dist/functional/result/impl/result-map.mjs.map +1 -1
  151. package/dist/functional/result/impl/result-match.mjs +16 -20
  152. package/dist/functional/result/impl/result-match.mjs.map +1 -1
  153. package/dist/functional/result/impl/result-ok.mjs +28 -6
  154. package/dist/functional/result/impl/result-ok.mjs.map +1 -1
  155. package/dist/functional/result/impl/result-or-else.mjs +13 -14
  156. package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
  157. package/dist/functional/result/impl/result-safe-try.mjs +32 -21
  158. package/dist/functional/result/impl/result-safe-try.mjs.map +1 -1
  159. package/dist/functional/result/impl/result-safe-unwrap.mjs +39 -11
  160. package/dist/functional/result/impl/result-safe-unwrap.mjs.map +1 -1
  161. package/dist/functional/result/impl/result-swap.mjs +21 -6
  162. package/dist/functional/result/impl/result-swap.mjs.map +1 -1
  163. package/dist/functional/result/impl/result-to-optional.mjs +28 -5
  164. package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
  165. package/dist/functional/result/impl/result-unwrap-err-or.mjs +12 -13
  166. package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
  167. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +42 -19
  168. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
  169. package/dist/functional/result/impl/result-unwrap-err.mjs +31 -6
  170. package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
  171. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +12 -13
  172. package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
  173. package/dist/functional/result/impl/result-unwrap-ok.mjs +6 -9
  174. package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
  175. package/dist/functional/result/impl/result-unwrap-throw.mjs +37 -10
  176. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
  177. package/dist/functional/result/impl/result-zip.mjs +33 -3
  178. package/dist/functional/result/impl/result-zip.mjs.map +1 -1
  179. package/dist/functional/result/impl/tag.mjs +3 -4
  180. package/dist/functional/result/impl/tag.mjs.map +1 -1
  181. package/dist/functional/result/impl/types.mjs +2 -2
  182. package/dist/functional/result/impl/types.mjs.map +1 -1
  183. package/dist/functional/result/index.mjs +2 -3
  184. package/dist/functional/result/index.mjs.map +1 -1
  185. package/dist/functional/result/result.mjs +2 -3
  186. package/dist/functional/result/result.mjs.map +1 -1
  187. package/dist/functional/ternary-result/impl/index.mjs +29 -28
  188. package/dist/functional/ternary-result/impl/index.mjs.map +1 -1
  189. package/dist/functional/ternary-result/impl/tag.mjs +5 -5
  190. package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
  191. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +16 -6
  192. package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
  193. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +15 -18
  194. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
  195. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +29 -33
  196. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
  197. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +24 -26
  198. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
  199. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +19 -6
  200. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
  201. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +27 -12
  202. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
  203. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +17 -3
  204. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
  205. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +19 -3
  206. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
  207. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +26 -6
  208. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
  209. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +18 -3
  210. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
  211. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +17 -18
  212. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
  213. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +20 -23
  214. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
  215. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +24 -26
  216. package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
  217. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +17 -6
  218. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
  219. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +11 -14
  220. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
  221. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +22 -8
  222. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
  223. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +11 -14
  224. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
  225. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +29 -18
  226. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
  227. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +18 -6
  228. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
  229. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +11 -14
  230. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
  231. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +6 -8
  232. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
  233. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +31 -23
  234. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
  235. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +11 -14
  236. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
  237. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +26 -16
  238. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
  239. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +18 -6
  240. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
  241. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +20 -7
  242. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
  243. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +46 -18
  244. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
  245. package/dist/functional/ternary-result/impl/types.mjs +2 -2
  246. package/dist/functional/ternary-result/impl/types.mjs.map +1 -1
  247. package/dist/functional/ternary-result/impl/variant-name.mjs +11 -13
  248. package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
  249. package/dist/functional/ternary-result/index.mjs +2 -3
  250. package/dist/functional/ternary-result/index.mjs.map +1 -1
  251. package/dist/functional/ternary-result/ternary-result.mjs +2 -3
  252. package/dist/functional/ternary-result/ternary-result.mjs.map +1 -1
  253. package/dist/guard/has-key.mjs +42 -3
  254. package/dist/guard/has-key.mjs.map +1 -1
  255. package/dist/guard/index.mjs +8 -8
  256. package/dist/guard/index.mjs.map +1 -1
  257. package/dist/guard/is-non-empty-string.mjs +38 -3
  258. package/dist/guard/is-non-empty-string.mjs.map +1 -1
  259. package/dist/guard/is-non-null-object.mjs +35 -3
  260. package/dist/guard/is-non-null-object.mjs.map +1 -1
  261. package/dist/guard/is-primitive.mjs +46 -15
  262. package/dist/guard/is-primitive.mjs.map +1 -1
  263. package/dist/guard/is-record.mjs +87 -4
  264. package/dist/guard/is-record.mjs.map +1 -1
  265. package/dist/guard/is-type.mjs +404 -19
  266. package/dist/guard/is-type.mjs.map +1 -1
  267. package/dist/guard/key-is-in.mjs +41 -3
  268. package/dist/guard/key-is-in.mjs.map +1 -1
  269. package/dist/index.mjs +12 -65
  270. package/dist/index.mjs.map +1 -1
  271. package/dist/iterator/index.mjs +2 -2
  272. package/dist/iterator/index.mjs.map +1 -1
  273. package/dist/iterator/range.mjs +18 -56
  274. package/dist/iterator/range.mjs.map +1 -1
  275. package/dist/json/index.mjs +2 -2
  276. package/dist/json/index.mjs.map +1 -1
  277. package/dist/json/json.mjs +346 -105
  278. package/dist/json/json.mjs.map +1 -1
  279. package/dist/number/branded-types/finite-number.mjs +148 -137
  280. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  281. package/dist/number/branded-types/index.mjs +33 -33
  282. package/dist/number/branded-types/index.mjs.map +1 -1
  283. package/dist/number/branded-types/int.mjs +245 -209
  284. package/dist/number/branded-types/int.mjs.map +1 -1
  285. package/dist/number/branded-types/int16.mjs +141 -131
  286. package/dist/number/branded-types/int16.mjs.map +1 -1
  287. package/dist/number/branded-types/int32.mjs +141 -131
  288. package/dist/number/branded-types/int32.mjs.map +1 -1
  289. package/dist/number/branded-types/negative-finite-number.mjs +155 -149
  290. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  291. package/dist/number/branded-types/negative-int.mjs +125 -110
  292. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  293. package/dist/number/branded-types/negative-safe-int.mjs +126 -115
  294. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  295. package/dist/number/branded-types/non-negative-finite-number.mjs +164 -154
  296. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  297. package/dist/number/branded-types/non-negative-int16.mjs +137 -125
  298. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  299. package/dist/number/branded-types/non-negative-int32.mjs +137 -125
  300. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  301. package/dist/number/branded-types/non-positive-finite-number.mjs +143 -139
  302. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  303. package/dist/number/branded-types/non-positive-int.mjs +116 -99
  304. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  305. package/dist/number/branded-types/non-positive-safe-int.mjs +118 -107
  306. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  307. package/dist/number/branded-types/non-zero-finite-number.mjs +144 -129
  308. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  309. package/dist/number/branded-types/non-zero-int.mjs +102 -82
  310. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  311. package/dist/number/branded-types/non-zero-int16.mjs +118 -105
  312. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  313. package/dist/number/branded-types/non-zero-int32.mjs +118 -105
  314. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  315. package/dist/number/branded-types/non-zero-safe-int.mjs +121 -107
  316. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  317. package/dist/number/branded-types/non-zero-uint16.mjs +118 -104
  318. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  319. package/dist/number/branded-types/non-zero-uint32.mjs +118 -104
  320. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  321. package/dist/number/branded-types/positive-finite-number.mjs +167 -160
  322. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  323. package/dist/number/branded-types/positive-int.mjs +260 -224
  324. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  325. package/dist/number/branded-types/positive-int16.mjs +134 -122
  326. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  327. package/dist/number/branded-types/positive-int32.mjs +134 -122
  328. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  329. package/dist/number/branded-types/positive-safe-int.mjs +291 -257
  330. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  331. package/dist/number/branded-types/positive-uint16.mjs +134 -122
  332. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  333. package/dist/number/branded-types/positive-uint32.mjs +134 -122
  334. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  335. package/dist/number/branded-types/safe-int.mjs +283 -254
  336. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  337. package/dist/number/branded-types/safe-uint.mjs +134 -123
  338. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  339. package/dist/number/branded-types/uint.mjs +248 -211
  340. package/dist/number/branded-types/uint.mjs.map +1 -1
  341. package/dist/number/branded-types/uint16.mjs +132 -121
  342. package/dist/number/branded-types/uint16.mjs.map +1 -1
  343. package/dist/number/branded-types/uint32.mjs +132 -121
  344. package/dist/number/branded-types/uint32.mjs.map +1 -1
  345. package/dist/number/enum/index.mjs +3 -3
  346. package/dist/number/enum/index.mjs.map +1 -1
  347. package/dist/number/enum/int8.mjs +146 -131
  348. package/dist/number/enum/int8.mjs.map +1 -1
  349. package/dist/number/enum/uint8.mjs +133 -119
  350. package/dist/number/enum/uint8.mjs.map +1 -1
  351. package/dist/number/index.mjs +6 -37
  352. package/dist/number/index.mjs.map +1 -1
  353. package/dist/number/num-arithmetic-types.mjs +42 -1
  354. package/dist/number/num-arithmetic-types.mjs.map +1 -1
  355. package/dist/number/num.mjs +549 -91
  356. package/dist/number/num.mjs.map +1 -1
  357. package/dist/number/refined-number-utils.mjs +294 -133
  358. package/dist/number/refined-number-utils.mjs.map +1 -1
  359. package/dist/object/index.mjs +2 -2
  360. package/dist/object/index.mjs.map +1 -1
  361. package/dist/object/object.mjs +356 -203
  362. package/dist/object/object.mjs.map +1 -1
  363. package/dist/others/cast-mutable.mjs +38 -11
  364. package/dist/others/cast-mutable.mjs.map +1 -1
  365. package/dist/others/cast-readonly.mjs +37 -11
  366. package/dist/others/cast-readonly.mjs.map +1 -1
  367. package/dist/others/debounce-function.mjs +22 -11
  368. package/dist/others/debounce-function.mjs.map +1 -1
  369. package/dist/others/fast-deep-equal.mjs +70 -51
  370. package/dist/others/fast-deep-equal.mjs.map +1 -1
  371. package/dist/others/if-then.mjs +31 -4
  372. package/dist/others/if-then.mjs.map +1 -1
  373. package/dist/others/index.mjs +10 -10
  374. package/dist/others/index.mjs.map +1 -1
  375. package/dist/others/map-nullable.mjs +11 -13
  376. package/dist/others/map-nullable.mjs.map +1 -1
  377. package/dist/others/memoize-function.mjs +14 -16
  378. package/dist/others/memoize-function.mjs.map +1 -1
  379. package/dist/others/tuple.mjs +51 -3
  380. package/dist/others/tuple.mjs.map +1 -1
  381. package/dist/others/unknown-to-string.mjs +91 -47
  382. package/dist/others/unknown-to-string.mjs.map +1 -1
  383. package/dist/promise/index.mjs +2 -2
  384. package/dist/promise/index.mjs.map +1 -1
  385. package/dist/promise/promise.mjs +49 -8
  386. package/dist/promise/promise.mjs.map +1 -1
  387. package/dist/string/index.mjs +2 -2
  388. package/dist/string/index.mjs.map +1 -1
  389. package/dist/string/str.mjs +250 -83
  390. package/dist/string/str.mjs.map +1 -1
  391. package/dist/types.mjs +2 -1
  392. package/dist/types.mjs.map +1 -1
  393. package/package.json +6 -7
  394. package/src/guard/is-type.test.mts +2 -2
  395. package/src/number/branded-types/finite-number.test.mts +1 -1
  396. package/src/number/branded-types/int.test.mts +1 -1
  397. package/src/number/branded-types/int16.test.mts +1 -1
  398. package/src/number/branded-types/int32.test.mts +1 -1
  399. package/src/number/branded-types/non-negative-finite-number.test.mts +1 -1
  400. package/src/number/branded-types/non-negative-int16.test.mts +1 -1
  401. package/src/number/branded-types/non-negative-int32.test.mts +1 -1
  402. package/src/number/branded-types/non-zero-finite-number.test.mts +1 -1
  403. package/src/number/branded-types/non-zero-int.test.mts +1 -1
  404. package/src/number/branded-types/non-zero-int16.test.mts +1 -1
  405. package/src/number/branded-types/non-zero-int32.test.mts +1 -1
  406. package/src/number/branded-types/non-zero-safe-int.test.mts +1 -1
  407. package/src/number/branded-types/non-zero-uint16.test.mts +1 -1
  408. package/src/number/branded-types/non-zero-uint32.test.mts +1 -1
  409. package/src/number/branded-types/positive-finite-number.test.mts +1 -1
  410. package/src/number/branded-types/positive-int.test.mts +1 -1
  411. package/src/number/branded-types/positive-int16.test.mts +1 -1
  412. package/src/number/branded-types/positive-int32.test.mts +1 -1
  413. package/src/number/branded-types/positive-safe-int.test.mts +1 -1
  414. package/src/number/branded-types/positive-uint16.test.mts +1 -1
  415. package/src/number/branded-types/positive-uint32.test.mts +1 -1
  416. package/src/number/branded-types/safe-int.test.mts +1 -1
  417. package/src/number/branded-types/safe-uint.test.mts +1 -1
  418. package/src/number/branded-types/uint.test.mts +1 -1
  419. package/src/number/branded-types/uint16.test.mts +1 -1
  420. package/src/number/branded-types/uint32.test.mts +1 -1
@@ -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
3
 
5
- const isResult = (maybeResult) => isRecord(maybeResult) && hasKey(maybeResult, "$$tag") && hasKey(maybeResult, "value") && (maybeResult.$$tag === ErrTypeTagName || maybeResult.$$tag === OkTypeTagName);
6
4
 
7
- export { isResult };
8
- //# sourceMappingURL=result-is-result.mjs.map
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
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
+ export function mapErr(...args) {
4
+ switch (args.length) {
5
+ case 2: {
3
6
 
4
- function mapErr(...args) {
5
- switch (args.length) {
6
- case 2: {
7
- const [result, mapFn] = args;
8
- return mapErrImpl(result, mapFn);
9
- }
10
- case 1: {
11
- const [mapFn] = args;
12
- return (result) => mapErrImpl(result, mapFn);
7
+ const [result, mapFn] = args;
8
+ return mapErrImpl(result, mapFn);
9
+ }
10
+ case 1: {
11
+
12
+ const [mapFn] = args;
13
+ return (result) => mapErrImpl(result, mapFn);
14
+ }
13
15
  }
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
+ ?
19
+ result
20
+ :
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
+ export function map(...args) {
4
+ switch (args.length) {
5
+ case 2: {
3
6
 
4
- function map(...args) {
5
- switch (args.length) {
6
- case 2: {
7
- const [result, mapFn] = args;
8
- return mapImpl(result, mapFn);
9
- }
10
- case 1: {
11
- const [mapFn] = args;
12
- return (result) => mapImpl(result, mapFn);
7
+ const [result, mapFn] = args;
8
+ return mapImpl(result, mapFn);
9
+ }
10
+ case 1: {
11
+
12
+ const [mapFn] = args;
13
+ return (result) => mapImpl(result, mapFn);
14
+ }
13
15
  }
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
+ ?
19
+ result
20
+ :
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
+ 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: {
2
9
 
3
- function match(...args) {
4
- switch (args.length) {
5
- case 2: {
6
- const [result, cases] = args;
7
- return matchImpl(result, cases);
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
+ ?
17
+ cases.ok(result.value)
18
+ :
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
2
 
3
- const ok = (value) => ({
4
- $$tag: OkTypeTagName,
5
- value
6
- });
7
3
 
8
- export { ok };
9
- //# sourceMappingURL=result-ok.mjs.map
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ export const ok = (value) => ({
28
+ $$tag: OkTypeTagName,
29
+ value,
30
+ });
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
+ export function orElse(...args) {
3
+ switch (args.length) {
4
+ case 2: {
2
5
 
3
- function orElse(...args) {
4
- switch (args.length) {
5
- case 2: {
6
- const [result, alternative] = args;
7
- return orElseImpl(result, alternative);
8
- }
9
- case 1: {
10
- const [alternative] = args;
11
- return (result) => orElseImpl(result, alternative);
6
+ const [result, alternative] = args;
7
+ return orElseImpl(result, alternative);
8
+ }
9
+ case 1: {
10
+
11
+ const [alternative] = args;
12
+ return (result) => orElseImpl(result, alternative);
13
+ }
12
14
  }
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);
10
- }
11
- return step.value;
12
- }
13
- return step.then(async (asyncStep) => {
14
- if (asyncStep.done !== true) {
15
- await generator.return(asyncStep.value);
1
+ import { hasKey, isRecord } from '../../../guard/index.mjs';
2
+ export function safeTry(body) {
3
+ const generator = body();
4
+
5
+
6
+
7
+ const step = generator.next();
8
+ if (isSyncStep(step)) {
9
+
10
+
11
+
12
+
13
+ if (step.done !== true && isSyncGenerator(generator, step)) {
14
+ generator.return(step.value);
15
+ }
16
+ return step.value;
16
17
  }
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");
21
- const isSyncGenerator = (_generator, step) => isSyncStep(step);
22
25
 
23
- export { safeTry };
24
- //# sourceMappingURL=result-safe-try.mjs.map
26
+
27
+
28
+
29
+ const isSyncStep = (value) => isRecord(value) && hasKey(value, 'done');
30
+
31
+
32
+
33
+
34
+ const isSyncGenerator = (_generator, step) => isSyncStep(step);
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
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;
11
- }
12
3
 
13
- export { safeUnwrap };
14
- //# sourceMappingURL=result-safe-unwrap.mjs.map
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
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
+
40
+ return result.value;
41
+ }
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"}
@@ -3,10 +3,25 @@ import { isOk } from './result-is-ok.mjs';
3
3
  import { ok } from './result-ok.mjs';
4
4
  import { unwrapOk } from './result-unwrap-ok.mjs';
5
5
 
6
- const swap = (result) => (
7
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
8
- isOk(result) ? err(unwrapOk(result)) : ok(result.value)
9
- );
10
6
 
11
- export { swap };
12
- //# sourceMappingURL=result-swap.mjs.map
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ export const swap = (result) =>
25
+
26
+ isOk(result) ? err(unwrapOk(result)) : ok(result.value);
27
+ //# sourceMappingURL=result-swap.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-swap.mjs","sources":["../../../../src/functional/result/impl/result-swap.mts"],"sourcesContent":["import { type Result, type UnknownResult } from '../result.mjs';\nimport { err } from './result-err.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { ok } from './result-ok.mjs';\nimport { unwrapOk } from './result-unwrap-ok.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Swaps the success and error values of a `Result`.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok('value');\n *\n * const errValue = Result.err('error');\n *\n * assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));\n *\n * assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @param result The `Result` to swap.\n * @returns A new `Result` with success and error swapped.\n */\nexport const swap = <R extends UnknownResult>(\n result: R,\n): Result<UnwrapErr<R>, UnwrapOk<R>> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n isOk(result) ? err(unwrapOk(result)) : ok(result.value as UnwrapErr<R>);\n"],"names":[],"mappings":";;;;;AA0BO,MAAM,OAAO,CAClB,MAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAA,GAAI,GAAA,CAAI,QAAA,CAAS,MAAM,CAAC,CAAA,GAAI,EAAA,CAAG,MAAA,CAAO,KAAqB;AAAA;;;;"}
1
+ {"version":3,"file":"result-swap.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-swap.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,MAAS,EAC0B,EAAE;AACrC,oEAAoE;AACpE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,KAAqB,CAAC,CAAC"}
@@ -1,9 +1,32 @@
1
- import { none } from '../../optional/impl/optional-none.mjs';
2
- import { some } from '../../optional/impl/optional-some.mjs';
1
+ import { Optional } from '../../optional/index.mjs';
3
2
  import { isOk } from './result-is-ok.mjs';
4
3
  import { unwrapOk } from './result-unwrap-ok.mjs';
5
4
 
6
- const toOptional = (result) => isOk(result) ? some(unwrapOk(result)) : none;
7
5
 
8
- export { toOptional };
9
- //# sourceMappingURL=result-to-optional.mjs.map
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ export const toOptional = (result) => isOk(result) ? Optional.some(unwrapOk(result)) : Optional.none;
32
+ //# sourceMappingURL=result-to-optional.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-to-optional.mjs","sources":["../../../../src/functional/result/impl/result-to-optional.mts"],"sourcesContent":["import { Optional } from '../../optional/index.mjs';\nimport { type UnknownResult } from '../result.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { unwrapOk } from './result-unwrap-ok.mjs';\nimport { type UnwrapOk } from './types.mjs';\n\n/**\n * Converts a `Result` to an `Optional`.\n *\n * This conversion is useful when you want to discard error information and\n * only care about whether an operation succeeded. The error information is\n * lost in this conversion, so use it when error details are not needed.\n *\n * If the `Result` is `Ok`, returns `Some` with the value. If the `Result` is\n * `Err`, returns `None`.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok(7);\n *\n * const errValue = Result.err('fail');\n *\n * assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));\n *\n * assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @param result The `Result` to convert.\n * @returns An `Optional<UnwrapOk<R>>` containing the success value or\n * representing `None`.\n */\nexport const toOptional = <R extends UnknownResult>(\n result: R,\n): Optional<UnwrapOk<R>> =>\n isOk(result) ? Optional.some(unwrapOk(result)) : Optional.none;\n"],"names":["Optional.some","Optional.none"],"mappings":";;;;;AAiCO,MAAM,UAAA,GAAa,CACxB,MAAA,KAEA,IAAA,CAAK,MAAM,CAAA,GAAIA,IAAS,CAAK,QAAA,CAAS,MAAM,CAAC,CAAA,GAAIC;;;;"}
1
+ {"version":3,"file":"result-to-optional.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-to-optional.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,MAAS,EACc,EAAE,CACzB,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC"}
@@ -1,18 +1,17 @@
1
1
  import { unwrapErr } from './result-unwrap-err.mjs';
2
+ export function unwrapErrOr(...args) {
3
+ switch (args.length) {
4
+ case 2: {
2
5
 
3
- function unwrapErrOr(...args) {
4
- switch (args.length) {
5
- case 2: {
6
- const [result, defaultValue] = args;
7
- return unwrapErrOrImpl(result, defaultValue);
8
- }
9
- case 1: {
10
- const [defaultValue] = args;
11
- return (result) => unwrapErrOrImpl(result, defaultValue);
6
+ const [result, defaultValue] = args;
7
+ return unwrapErrOrImpl(result, defaultValue);
8
+ }
9
+ case 1: {
10
+
11
+ const [defaultValue] = args;
12
+ return (result) => unwrapErrOrImpl(result, defaultValue);
13
+ }
12
14
  }
13
- }
14
15
  }
15
16
  const unwrapErrOrImpl = (result, defaultValue) => unwrapErr(result) ?? defaultValue;
16
-
17
- export { unwrapErrOr };
18
- //# sourceMappingURL=result-unwrap-err-or.mjs.map
17
+ //# sourceMappingURL=result-unwrap-err-or.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"result-unwrap-err-or.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-err-or.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { unwrapErr } from './result-unwrap-err.mjs';\nimport { type UnwrapErr } from './types.mjs';\n\n/**\n * Unwraps a `Result`, returning the error value or a default value if it is\n * `Result.Ok`.\n *\n * @example\n *\n * ```ts\n * const okResult = Result.ok('success');\n *\n * const errResult = Result.err('failure');\n *\n * assert.isTrue(Result.unwrapErrOr(okResult, 'default') === 'default');\n *\n * assert.isTrue(Result.unwrapErrOr(errResult, 'default') === 'failure');\n *\n * const unwrapError = Result.unwrapErrOr('fallback error');\n *\n * assert.isTrue(unwrapError(Result.err('boom')) === 'boom');\n *\n * assert.isTrue(unwrapError(Result.ok('no error')) === 'fallback error');\n * ```\n *\n * @template R The `UnknownResult` type to unwrap.\n * @template D The type of the default value.\n * @param result The `Result` to unwrap.\n * @param defaultValue The value to return if `result` is `Result.Ok`.\n * @returns The error value if `Result.Err`, otherwise `defaultValue`.\n */\nexport function unwrapErrOr<R extends UnknownResult, D>(\n result: R,\n defaultValue: D,\n): D | UnwrapErr<R>;\n\n// Curried version\nexport function unwrapErrOr<D>(\n defaultValue: D,\n): <R extends UnknownResult>(result: R) => D | UnwrapErr<R>;\n\nexport function unwrapErrOr<R extends UnknownResult, D>(\n ...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]\n): D | UnwrapErr<R> | ((result: R) => D | UnwrapErr<R>) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, defaultValue] = args;\n\n return unwrapErrOrImpl(result, defaultValue);\n }\n\n case 1: {\n // Curried version\n const [defaultValue] = args;\n\n return (result: R) => unwrapErrOrImpl(result, defaultValue);\n }\n }\n}\n\nconst unwrapErrOrImpl = <R extends UnknownResult, D>(\n result: R,\n defaultValue: D,\n): D | UnwrapErr<R> => unwrapErr(result) ?? defaultValue;\n"],"names":[],"mappings":";;AA0CO,SAAS,eACX,IAAA,EACmD;AACtD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,YAAY,CAAA,GAAI,IAAA;AAE/B,MAAA,OAAO,eAAA,CAAgB,QAAQ,YAAY,CAAA;AAAA,IAC7C;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,YAAY,CAAA,GAAI,IAAA;AAEvB,MAAA,OAAO,CAAC,MAAA,KAAc,eAAA,CAAgB,MAAA,EAAQ,YAAY,CAAA;AAAA,IAC5D;AAAA;AAEJ;AAEA,MAAM,kBAAkB,CACtB,MAAA,EACA,YAAA,KACqB,SAAA,CAAU,MAAM,CAAA,IAAK,YAAA;;;;"}
1
+ {"version":3,"file":"result-unwrap-err-or.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-unwrap-err-or.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAyCpD,MAAM,UAAU,WAAW,CACzB,GAAG,IAAwE;IAE3E,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,2CAA2C;YAC3C,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,IAAI,CAAC;YAEpC,OAAO,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC/C,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,kBAAkB;YAClB,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;YAE5B,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,eAAe,GAAG,CACtB,MAAS,EACT,YAAe,EACG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC"}