ts-data-forge 14.6.4 → 14.7.1

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 (573) hide show
  1. package/README.md +2 -1
  2. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +36 -6
  3. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
  4. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +4 -0
  5. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
  6. package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +26 -6
  7. package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -1
  8. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +4 -0
  9. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
  10. package/dist/expect-type.d.mts +2 -70
  11. package/dist/expect-type.d.mts.map +1 -1
  12. package/dist/expect-type.mjs +1 -68
  13. package/dist/expect-type.mjs.map +1 -1
  14. package/dist/functional/index.d.mts +11 -6
  15. package/dist/functional/index.d.mts.map +1 -1
  16. package/dist/functional/index.mjs +10 -6
  17. package/dist/functional/index.mjs.map +1 -1
  18. package/dist/guard/has-key.d.mts +2 -51
  19. package/dist/guard/has-key.d.mts.map +1 -1
  20. package/dist/guard/has-key.mjs +1 -41
  21. package/dist/guard/has-key.mjs.map +1 -1
  22. package/dist/guard/is-non-null-object.d.mts +2 -34
  23. package/dist/guard/is-non-null-object.d.mts.map +1 -1
  24. package/dist/guard/is-non-null-object.mjs +1 -34
  25. package/dist/guard/is-non-null-object.mjs.map +1 -1
  26. package/dist/guard/is-record.d.mts +2 -89
  27. package/dist/guard/is-record.d.mts.map +1 -1
  28. package/dist/guard/is-record.mjs +1 -88
  29. package/dist/guard/is-record.mjs.map +1 -1
  30. package/dist/guard/key-is-in.d.mts +2 -42
  31. package/dist/guard/key-is-in.d.mts.map +1 -1
  32. package/dist/guard/key-is-in.mjs +1 -40
  33. package/dist/guard/key-is-in.mjs.map +1 -1
  34. package/dist/index.d.mts +2 -0
  35. package/dist/index.d.mts.map +1 -1
  36. package/dist/index.mjs +2 -0
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/number/num.d.mts +9 -1
  39. package/dist/number/num.d.mts.map +1 -1
  40. package/dist/number/num.mjs +24 -16
  41. package/dist/number/num.mjs.map +1 -1
  42. package/dist/others/index.d.mts +1 -0
  43. package/dist/others/index.d.mts.map +1 -1
  44. package/dist/others/index.mjs +1 -0
  45. package/dist/others/index.mjs.map +1 -1
  46. package/dist/others/panic-error.d.mts +9 -0
  47. package/dist/others/panic-error.d.mts.map +1 -0
  48. package/dist/others/panic-error.mjs +9 -0
  49. package/dist/others/panic-error.mjs.map +1 -0
  50. package/dist/others/unknown-to-string.d.mts +2 -37
  51. package/dist/others/unknown-to-string.d.mts.map +1 -1
  52. package/dist/others/unknown-to-string.mjs +1 -92
  53. package/dist/others/unknown-to-string.mjs.map +1 -1
  54. package/dist/types.d.mts +1 -41
  55. package/dist/types.d.mts.map +1 -1
  56. package/dist/types.mjs +0 -1
  57. package/dist/types.mjs.map +1 -1
  58. package/package.json +9 -9
  59. package/src/array/impl/array-utils-length-bounded-array-cast.mts +36 -6
  60. package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +26 -6
  61. package/src/expect-type.mts +2 -78
  62. package/src/functional/index.mts +31 -6
  63. package/src/guard/has-key.mts +2 -72
  64. package/src/guard/is-non-null-object.mts +2 -36
  65. package/src/guard/is-record.mts +2 -95
  66. package/src/guard/key-is-in.mts +2 -49
  67. package/src/index.mts +2 -0
  68. package/src/number/num.mts +36 -28
  69. package/src/others/index.mts +1 -0
  70. package/src/others/panic-error.mts +8 -0
  71. package/src/others/unknown-to-string.mts +2 -111
  72. package/src/types.mts +4 -54
  73. package/dist/functional/async-result/async-result.d.mts +0 -16
  74. package/dist/functional/async-result/async-result.d.mts.map +0 -1
  75. package/dist/functional/async-result/async-result.mjs +0 -2
  76. package/dist/functional/async-result/async-result.mjs.map +0 -1
  77. package/dist/functional/async-result/impl/async-result-flat-map.d.mts +0 -39
  78. package/dist/functional/async-result/impl/async-result-flat-map.d.mts.map +0 -1
  79. package/dist/functional/async-result/impl/async-result-flat-map.mjs +0 -23
  80. package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +0 -1
  81. package/dist/functional/async-result/impl/async-result-from-promise.d.mts +0 -47
  82. package/dist/functional/async-result/impl/async-result-from-promise.d.mts.map +0 -1
  83. package/dist/functional/async-result/impl/async-result-from-promise.mjs +0 -10
  84. package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +0 -1
  85. package/dist/functional/async-result/impl/async-result-from-throwable.d.mts +0 -53
  86. package/dist/functional/async-result/impl/async-result-from-throwable.d.mts.map +0 -1
  87. package/dist/functional/async-result/impl/async-result-from-throwable.mjs +0 -15
  88. package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +0 -1
  89. package/dist/functional/async-result/impl/async-result-map-err.d.mts +0 -35
  90. package/dist/functional/async-result/impl/async-result-map-err.d.mts.map +0 -1
  91. package/dist/functional/async-result/impl/async-result-map-err.mjs +0 -20
  92. package/dist/functional/async-result/impl/async-result-map-err.mjs.map +0 -1
  93. package/dist/functional/async-result/impl/async-result-map.d.mts +0 -45
  94. package/dist/functional/async-result/impl/async-result-map.d.mts.map +0 -1
  95. package/dist/functional/async-result/impl/async-result-map.mjs +0 -20
  96. package/dist/functional/async-result/impl/async-result-map.mjs.map +0 -1
  97. package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts +0 -34
  98. package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts.map +0 -1
  99. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +0 -37
  100. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +0 -1
  101. package/dist/functional/async-result/impl/index.d.mts +0 -8
  102. package/dist/functional/async-result/impl/index.d.mts.map +0 -1
  103. package/dist/functional/async-result/impl/index.mjs +0 -8
  104. package/dist/functional/async-result/impl/index.mjs.map +0 -1
  105. package/dist/functional/async-result/impl/types.d.mts +0 -45
  106. package/dist/functional/async-result/impl/types.d.mts.map +0 -1
  107. package/dist/functional/async-result/impl/types.mjs +0 -2
  108. package/dist/functional/async-result/impl/types.mjs.map +0 -1
  109. package/dist/functional/async-result/index.d.mts +0 -2
  110. package/dist/functional/async-result/index.d.mts.map +0 -1
  111. package/dist/functional/async-result/index.mjs +0 -2
  112. package/dist/functional/async-result/index.mjs.map +0 -1
  113. package/dist/functional/match.d.mts +0 -80
  114. package/dist/functional/match.d.mts.map +0 -1
  115. package/dist/functional/match.mjs +0 -31
  116. package/dist/functional/match.mjs.map +0 -1
  117. package/dist/functional/optional/impl/index.d.mts +0 -19
  118. package/dist/functional/optional/impl/index.d.mts.map +0 -1
  119. package/dist/functional/optional/impl/index.mjs +0 -19
  120. package/dist/functional/optional/impl/index.mjs.map +0 -1
  121. package/dist/functional/optional/impl/optional-expect-to-be.d.mts +0 -37
  122. package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +0 -1
  123. package/dist/functional/optional/impl/optional-expect-to-be.mjs +0 -22
  124. package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +0 -1
  125. package/dist/functional/optional/impl/optional-filter.d.mts +0 -33
  126. package/dist/functional/optional/impl/optional-filter.d.mts.map +0 -1
  127. package/dist/functional/optional/impl/optional-filter.mjs +0 -25
  128. package/dist/functional/optional/impl/optional-filter.mjs.map +0 -1
  129. package/dist/functional/optional/impl/optional-flat-map.d.mts +0 -39
  130. package/dist/functional/optional/impl/optional-flat-map.d.mts.map +0 -1
  131. package/dist/functional/optional/impl/optional-flat-map.mjs +0 -18
  132. package/dist/functional/optional/impl/optional-flat-map.mjs.map +0 -1
  133. package/dist/functional/optional/impl/optional-from-nullable.d.mts +0 -27
  134. package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +0 -1
  135. package/dist/functional/optional/impl/optional-from-nullable.mjs +0 -28
  136. package/dist/functional/optional/impl/optional-from-nullable.mjs.map +0 -1
  137. package/dist/functional/optional/impl/optional-is-none.d.mts +0 -23
  138. package/dist/functional/optional/impl/optional-is-none.d.mts.map +0 -1
  139. package/dist/functional/optional/impl/optional-is-none.mjs +0 -22
  140. package/dist/functional/optional/impl/optional-is-none.mjs.map +0 -1
  141. package/dist/functional/optional/impl/optional-is-optional.d.mts +0 -21
  142. package/dist/functional/optional/impl/optional-is-optional.d.mts.map +0 -1
  143. package/dist/functional/optional/impl/optional-is-optional.mjs +0 -26
  144. package/dist/functional/optional/impl/optional-is-optional.mjs.map +0 -1
  145. package/dist/functional/optional/impl/optional-is-some.d.mts +0 -24
  146. package/dist/functional/optional/impl/optional-is-some.d.mts.map +0 -1
  147. package/dist/functional/optional/impl/optional-is-some.mjs +0 -23
  148. package/dist/functional/optional/impl/optional-is-some.mjs.map +0 -1
  149. package/dist/functional/optional/impl/optional-map.d.mts +0 -34
  150. package/dist/functional/optional/impl/optional-map.d.mts.map +0 -1
  151. package/dist/functional/optional/impl/optional-map.mjs +0 -22
  152. package/dist/functional/optional/impl/optional-map.mjs.map +0 -1
  153. package/dist/functional/optional/impl/optional-match.d.mts +0 -48
  154. package/dist/functional/optional/impl/optional-match.d.mts.map +0 -1
  155. package/dist/functional/optional/impl/optional-match.mjs +0 -20
  156. package/dist/functional/optional/impl/optional-match.mjs.map +0 -1
  157. package/dist/functional/optional/impl/optional-none.d.mts +0 -19
  158. package/dist/functional/optional/impl/optional-none.d.mts.map +0 -1
  159. package/dist/functional/optional/impl/optional-none.mjs +0 -19
  160. package/dist/functional/optional/impl/optional-none.mjs.map +0 -1
  161. package/dist/functional/optional/impl/optional-or-else.d.mts +0 -43
  162. package/dist/functional/optional/impl/optional-or-else.d.mts.map +0 -1
  163. package/dist/functional/optional/impl/optional-or-else.mjs +0 -16
  164. package/dist/functional/optional/impl/optional-or-else.mjs.map +0 -1
  165. package/dist/functional/optional/impl/optional-some.d.mts +0 -22
  166. package/dist/functional/optional/impl/optional-some.d.mts.map +0 -1
  167. package/dist/functional/optional/impl/optional-some.mjs +0 -25
  168. package/dist/functional/optional/impl/optional-some.mjs.map +0 -1
  169. package/dist/functional/optional/impl/optional-to-nullable.d.mts +0 -30
  170. package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +0 -1
  171. package/dist/functional/optional/impl/optional-to-nullable.mjs +0 -30
  172. package/dist/functional/optional/impl/optional-to-nullable.mjs.map +0 -1
  173. package/dist/functional/optional/impl/optional-unwrap-or.d.mts +0 -37
  174. package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +0 -1
  175. package/dist/functional/optional/impl/optional-unwrap-or.mjs +0 -16
  176. package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +0 -1
  177. package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +0 -31
  178. package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +0 -1
  179. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +0 -36
  180. package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +0 -1
  181. package/dist/functional/optional/impl/optional-unwrap.d.mts +0 -32
  182. package/dist/functional/optional/impl/optional-unwrap.d.mts.map +0 -1
  183. package/dist/functional/optional/impl/optional-unwrap.mjs +0 -8
  184. package/dist/functional/optional/impl/optional-unwrap.mjs.map +0 -1
  185. package/dist/functional/optional/impl/optional-zip.d.mts +0 -35
  186. package/dist/functional/optional/impl/optional-zip.d.mts.map +0 -1
  187. package/dist/functional/optional/impl/optional-zip.mjs +0 -39
  188. package/dist/functional/optional/impl/optional-zip.mjs.map +0 -1
  189. package/dist/functional/optional/impl/tag.d.mts +0 -6
  190. package/dist/functional/optional/impl/tag.d.mts.map +0 -1
  191. package/dist/functional/optional/impl/tag.mjs +0 -4
  192. package/dist/functional/optional/impl/tag.mjs.map +0 -1
  193. package/dist/functional/optional/impl/types.d.mts +0 -24
  194. package/dist/functional/optional/impl/types.d.mts.map +0 -1
  195. package/dist/functional/optional/impl/types.mjs +0 -2
  196. package/dist/functional/optional/impl/types.mjs.map +0 -1
  197. package/dist/functional/optional/index.d.mts +0 -2
  198. package/dist/functional/optional/index.d.mts.map +0 -1
  199. package/dist/functional/optional/index.mjs +0 -2
  200. package/dist/functional/optional/index.mjs.map +0 -1
  201. package/dist/functional/optional/optional.d.mts +0 -16
  202. package/dist/functional/optional/optional.d.mts.map +0 -1
  203. package/dist/functional/optional/optional.mjs +0 -2
  204. package/dist/functional/optional/optional.mjs.map +0 -1
  205. package/dist/functional/pipe.d.mts +0 -102
  206. package/dist/functional/pipe.d.mts.map +0 -1
  207. package/dist/functional/pipe.mjs +0 -45
  208. package/dist/functional/pipe.mjs.map +0 -1
  209. package/dist/functional/result/impl/index.d.mts +0 -28
  210. package/dist/functional/result/impl/index.d.mts.map +0 -1
  211. package/dist/functional/result/impl/index.mjs +0 -28
  212. package/dist/functional/result/impl/index.mjs.map +0 -1
  213. package/dist/functional/result/impl/result-err.d.mts +0 -28
  214. package/dist/functional/result/impl/result-err.d.mts.map +0 -1
  215. package/dist/functional/result/impl/result-err.mjs +0 -31
  216. package/dist/functional/result/impl/result-err.mjs.map +0 -1
  217. package/dist/functional/result/impl/result-expect-to-be.d.mts +0 -33
  218. package/dist/functional/result/impl/result-expect-to-be.d.mts.map +0 -1
  219. package/dist/functional/result/impl/result-expect-to-be.mjs +0 -23
  220. package/dist/functional/result/impl/result-expect-to-be.mjs.map +0 -1
  221. package/dist/functional/result/impl/result-flat-map.d.mts +0 -45
  222. package/dist/functional/result/impl/result-flat-map.d.mts.map +0 -1
  223. package/dist/functional/result/impl/result-flat-map.mjs +0 -21
  224. package/dist/functional/result/impl/result-flat-map.mjs.map +0 -1
  225. package/dist/functional/result/impl/result-fold.d.mts +0 -50
  226. package/dist/functional/result/impl/result-fold.d.mts.map +0 -1
  227. package/dist/functional/result/impl/result-fold.mjs +0 -23
  228. package/dist/functional/result/impl/result-fold.mjs.map +0 -1
  229. package/dist/functional/result/impl/result-from-optional.d.mts +0 -41
  230. package/dist/functional/result/impl/result-from-optional.d.mts.map +0 -1
  231. package/dist/functional/result/impl/result-from-optional.mjs +0 -21
  232. package/dist/functional/result/impl/result-from-optional.mjs.map +0 -1
  233. package/dist/functional/result/impl/result-from-promise.d.mts +0 -43
  234. package/dist/functional/result/impl/result-from-promise.d.mts.map +0 -1
  235. package/dist/functional/result/impl/result-from-promise.mjs +0 -39
  236. package/dist/functional/result/impl/result-from-promise.mjs.map +0 -1
  237. package/dist/functional/result/impl/result-from-throwable.d.mts +0 -32
  238. package/dist/functional/result/impl/result-from-throwable.d.mts.map +0 -1
  239. package/dist/functional/result/impl/result-from-throwable.mjs +0 -46
  240. package/dist/functional/result/impl/result-from-throwable.mjs.map +0 -1
  241. package/dist/functional/result/impl/result-is-err.d.mts +0 -23
  242. package/dist/functional/result/impl/result-is-err.d.mts.map +0 -1
  243. package/dist/functional/result/impl/result-is-err.mjs +0 -22
  244. package/dist/functional/result/impl/result-is-err.mjs.map +0 -1
  245. package/dist/functional/result/impl/result-is-ok.d.mts +0 -23
  246. package/dist/functional/result/impl/result-is-ok.d.mts.map +0 -1
  247. package/dist/functional/result/impl/result-is-ok.mjs +0 -22
  248. package/dist/functional/result/impl/result-is-ok.mjs.map +0 -1
  249. package/dist/functional/result/impl/result-is-result.d.mts +0 -22
  250. package/dist/functional/result/impl/result-is-result.d.mts.map +0 -1
  251. package/dist/functional/result/impl/result-is-result.mjs +0 -26
  252. package/dist/functional/result/impl/result-is-result.mjs.map +0 -1
  253. package/dist/functional/result/impl/result-map-err.d.mts +0 -39
  254. package/dist/functional/result/impl/result-map-err.d.mts.map +0 -1
  255. package/dist/functional/result/impl/result-map-err.mjs +0 -22
  256. package/dist/functional/result/impl/result-map-err.mjs.map +0 -1
  257. package/dist/functional/result/impl/result-map.d.mts +0 -39
  258. package/dist/functional/result/impl/result-map.d.mts.map +0 -1
  259. package/dist/functional/result/impl/result-map.mjs +0 -22
  260. package/dist/functional/result/impl/result-map.mjs.map +0 -1
  261. package/dist/functional/result/impl/result-match.d.mts +0 -47
  262. package/dist/functional/result/impl/result-match.d.mts.map +0 -1
  263. package/dist/functional/result/impl/result-match.mjs +0 -20
  264. package/dist/functional/result/impl/result-match.mjs.map +0 -1
  265. package/dist/functional/result/impl/result-ok.d.mts +0 -28
  266. package/dist/functional/result/impl/result-ok.d.mts.map +0 -1
  267. package/dist/functional/result/impl/result-ok.mjs +0 -31
  268. package/dist/functional/result/impl/result-ok.mjs.map +0 -1
  269. package/dist/functional/result/impl/result-or-else.d.mts +0 -40
  270. package/dist/functional/result/impl/result-or-else.d.mts.map +0 -1
  271. package/dist/functional/result/impl/result-or-else.mjs +0 -17
  272. package/dist/functional/result/impl/result-or-else.mjs.map +0 -1
  273. package/dist/functional/result/impl/result-safe-try.d.mts +0 -51
  274. package/dist/functional/result/impl/result-safe-try.d.mts.map +0 -1
  275. package/dist/functional/result/impl/result-safe-try.mjs +0 -35
  276. package/dist/functional/result/impl/result-safe-try.mjs.map +0 -1
  277. package/dist/functional/result/impl/result-safe-unwrap.d.mts +0 -36
  278. package/dist/functional/result/impl/result-safe-unwrap.d.mts.map +0 -1
  279. package/dist/functional/result/impl/result-safe-unwrap.mjs +0 -42
  280. package/dist/functional/result/impl/result-safe-unwrap.mjs.map +0 -1
  281. package/dist/functional/result/impl/result-swap.d.mts +0 -23
  282. package/dist/functional/result/impl/result-swap.d.mts.map +0 -1
  283. package/dist/functional/result/impl/result-swap.mjs +0 -27
  284. package/dist/functional/result/impl/result-swap.mjs.map +0 -1
  285. package/dist/functional/result/impl/result-to-optional.d.mts +0 -32
  286. package/dist/functional/result/impl/result-to-optional.d.mts.map +0 -1
  287. package/dist/functional/result/impl/result-to-optional.mjs +0 -32
  288. package/dist/functional/result/impl/result-to-optional.mjs.map +0 -1
  289. package/dist/functional/result/impl/result-unwrap-err-or.d.mts +0 -33
  290. package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +0 -1
  291. package/dist/functional/result/impl/result-unwrap-err-or.mjs +0 -17
  292. package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +0 -1
  293. package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +0 -33
  294. package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +0 -1
  295. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +0 -46
  296. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +0 -1
  297. package/dist/functional/result/impl/result-unwrap-err.d.mts +0 -33
  298. package/dist/functional/result/impl/result-unwrap-err.d.mts.map +0 -1
  299. package/dist/functional/result/impl/result-unwrap-err.mjs +0 -34
  300. package/dist/functional/result/impl/result-unwrap-err.mjs.map +0 -1
  301. package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +0 -33
  302. package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +0 -1
  303. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +0 -17
  304. package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +0 -1
  305. package/dist/functional/result/impl/result-unwrap-ok.d.mts +0 -26
  306. package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +0 -1
  307. package/dist/functional/result/impl/result-unwrap-ok.mjs +0 -8
  308. package/dist/functional/result/impl/result-unwrap-ok.mjs.map +0 -1
  309. package/dist/functional/result/impl/result-unwrap-throw.d.mts +0 -33
  310. package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +0 -1
  311. package/dist/functional/result/impl/result-unwrap-throw.mjs +0 -40
  312. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +0 -1
  313. package/dist/functional/result/impl/result-zip.d.mts +0 -32
  314. package/dist/functional/result/impl/result-zip.d.mts.map +0 -1
  315. package/dist/functional/result/impl/result-zip.mjs +0 -37
  316. package/dist/functional/result/impl/result-zip.mjs.map +0 -1
  317. package/dist/functional/result/impl/tag.d.mts +0 -6
  318. package/dist/functional/result/impl/tag.d.mts.map +0 -1
  319. package/dist/functional/result/impl/tag.mjs +0 -4
  320. package/dist/functional/result/impl/tag.mjs.map +0 -1
  321. package/dist/functional/result/impl/types.d.mts +0 -31
  322. package/dist/functional/result/impl/types.d.mts.map +0 -1
  323. package/dist/functional/result/impl/types.mjs +0 -2
  324. package/dist/functional/result/impl/types.mjs.map +0 -1
  325. package/dist/functional/result/index.d.mts +0 -2
  326. package/dist/functional/result/index.d.mts.map +0 -1
  327. package/dist/functional/result/index.mjs +0 -2
  328. package/dist/functional/result/index.mjs.map +0 -1
  329. package/dist/functional/result/result.d.mts +0 -16
  330. package/dist/functional/result/result.d.mts.map +0 -1
  331. package/dist/functional/result/result.mjs +0 -2
  332. package/dist/functional/result/result.mjs.map +0 -1
  333. package/dist/functional/ternary-result/impl/index.d.mts +0 -29
  334. package/dist/functional/ternary-result/impl/index.d.mts.map +0 -1
  335. package/dist/functional/ternary-result/impl/index.mjs +0 -29
  336. package/dist/functional/ternary-result/impl/index.mjs.map +0 -1
  337. package/dist/functional/ternary-result/impl/tag.d.mts +0 -8
  338. package/dist/functional/ternary-result/impl/tag.d.mts.map +0 -1
  339. package/dist/functional/ternary-result/impl/tag.mjs +0 -6
  340. package/dist/functional/ternary-result/impl/tag.mjs.map +0 -1
  341. package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +0 -16
  342. package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +0 -1
  343. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +0 -19
  344. package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +0 -1
  345. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +0 -24
  346. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +0 -1
  347. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +0 -21
  348. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +0 -1
  349. package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +0 -39
  350. package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +0 -1
  351. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +0 -38
  352. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +0 -1
  353. package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +0 -30
  354. package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +0 -1
  355. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +0 -33
  356. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +0 -1
  357. package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +0 -23
  358. package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +0 -1
  359. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +0 -23
  360. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +0 -1
  361. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +0 -20
  362. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +0 -1
  363. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +0 -33
  364. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +0 -1
  365. package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts +0 -21
  366. package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +0 -1
  367. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -20
  368. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +0 -1
  369. package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +0 -23
  370. package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +0 -1
  371. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -22
  372. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +0 -1
  373. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +0 -22
  374. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +0 -1
  375. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +0 -28
  376. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +0 -1
  377. package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +0 -22
  378. package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +0 -1
  379. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -21
  380. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +0 -1
  381. package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +0 -27
  382. package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +0 -1
  383. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +0 -23
  384. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +0 -1
  385. package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +0 -28
  386. package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +0 -1
  387. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +0 -26
  388. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +0 -1
  389. package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +0 -36
  390. package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +0 -1
  391. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +0 -32
  392. package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +0 -1
  393. package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +0 -17
  394. package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +0 -1
  395. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +0 -20
  396. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +0 -1
  397. package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +0 -29
  398. package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +0 -1
  399. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +0 -16
  400. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +0 -1
  401. package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +0 -23
  402. package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +0 -1
  403. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +0 -26
  404. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +0 -1
  405. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +0 -28
  406. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +0 -1
  407. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +0 -14
  408. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +0 -1
  409. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +0 -20
  410. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +0 -1
  411. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +0 -34
  412. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +0 -1
  413. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +0 -20
  414. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +0 -1
  415. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +0 -21
  416. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +0 -1
  417. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +0 -25
  418. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +0 -1
  419. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +0 -14
  420. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +0 -1
  421. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +0 -20
  422. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +0 -1
  423. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +0 -10
  424. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +0 -1
  425. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +0 -21
  426. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +0 -1
  427. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +0 -35
  428. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +0 -1
  429. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +0 -22
  430. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +0 -1
  431. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +0 -14
  432. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +0 -1
  433. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +0 -20
  434. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +0 -1
  435. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +0 -30
  436. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +0 -1
  437. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +0 -20
  438. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +0 -1
  439. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +0 -21
  440. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +0 -1
  441. package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +0 -19
  442. package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +0 -1
  443. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +0 -23
  444. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +0 -1
  445. package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +0 -34
  446. package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +0 -1
  447. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +0 -52
  448. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +0 -1
  449. package/dist/functional/ternary-result/impl/types.d.mts +0 -26
  450. package/dist/functional/ternary-result/impl/types.d.mts.map +0 -1
  451. package/dist/functional/ternary-result/impl/types.mjs +0 -2
  452. package/dist/functional/ternary-result/impl/types.mjs.map +0 -1
  453. package/dist/functional/ternary-result/impl/variant-name.d.mts +0 -4
  454. package/dist/functional/ternary-result/impl/variant-name.d.mts.map +0 -1
  455. package/dist/functional/ternary-result/impl/variant-name.mjs +0 -13
  456. package/dist/functional/ternary-result/impl/variant-name.mjs.map +0 -1
  457. package/dist/functional/ternary-result/index.d.mts +0 -2
  458. package/dist/functional/ternary-result/index.d.mts.map +0 -1
  459. package/dist/functional/ternary-result/index.mjs +0 -2
  460. package/dist/functional/ternary-result/index.mjs.map +0 -1
  461. package/dist/functional/ternary-result/ternary-result.d.mts +0 -40
  462. package/dist/functional/ternary-result/ternary-result.d.mts.map +0 -1
  463. package/dist/functional/ternary-result/ternary-result.mjs +0 -2
  464. package/dist/functional/ternary-result/ternary-result.mjs.map +0 -1
  465. package/src/functional/async-result/async-result.mts +0 -17
  466. package/src/functional/async-result/impl/async-result-flat-map.mts +0 -99
  467. package/src/functional/async-result/impl/async-result-from-promise.mts +0 -69
  468. package/src/functional/async-result/impl/async-result-from-throwable.mts +0 -78
  469. package/src/functional/async-result/impl/async-result-map-err.mts +0 -84
  470. package/src/functional/async-result/impl/async-result-map.mts +0 -94
  471. package/src/functional/async-result/impl/async-result-unwrap-or.mts +0 -42
  472. package/src/functional/async-result/impl/index.mts +0 -7
  473. package/src/functional/async-result/impl/types.mts +0 -51
  474. package/src/functional/async-result/index.mts +0 -1
  475. package/src/functional/async-result.test.mts +0 -291
  476. package/src/functional/match.mts +0 -193
  477. package/src/functional/match.test.mts +0 -180
  478. package/src/functional/optional/impl/index.mts +0 -18
  479. package/src/functional/optional/impl/optional-expect-to-be.mts +0 -75
  480. package/src/functional/optional/impl/optional-filter.mts +0 -78
  481. package/src/functional/optional/impl/optional-flat-map.mts +0 -75
  482. package/src/functional/optional/impl/optional-from-nullable.mts +0 -31
  483. package/src/functional/optional/impl/optional-is-none.mts +0 -26
  484. package/src/functional/optional/impl/optional-is-optional.mts +0 -30
  485. package/src/functional/optional/impl/optional-is-some.mts +0 -27
  486. package/src/functional/optional/impl/optional-map.mts +0 -90
  487. package/src/functional/optional/impl/optional-match.mts +0 -108
  488. package/src/functional/optional/impl/optional-none.mts +0 -20
  489. package/src/functional/optional/impl/optional-or-else.mts +0 -83
  490. package/src/functional/optional/impl/optional-some.mts +0 -27
  491. package/src/functional/optional/impl/optional-to-nullable.mts +0 -34
  492. package/src/functional/optional/impl/optional-unwrap-or.mts +0 -70
  493. package/src/functional/optional/impl/optional-unwrap-throw.mts +0 -41
  494. package/src/functional/optional/impl/optional-unwrap.mts +0 -45
  495. package/src/functional/optional/impl/optional-zip.mts +0 -44
  496. package/src/functional/optional/impl/tag.mts +0 -8
  497. package/src/functional/optional/impl/types.mts +0 -31
  498. package/src/functional/optional/index.mts +0 -1
  499. package/src/functional/optional/optional.mts +0 -19
  500. package/src/functional/optional.test.mts +0 -883
  501. package/src/functional/pipe.mts +0 -180
  502. package/src/functional/pipe.test.mts +0 -155
  503. package/src/functional/result/impl/index.mts +0 -27
  504. package/src/functional/result/impl/result-err.mts +0 -33
  505. package/src/functional/result/impl/result-expect-to-be.mts +0 -73
  506. package/src/functional/result/impl/result-flat-map.mts +0 -88
  507. package/src/functional/result/impl/result-fold.mts +0 -102
  508. package/src/functional/result/impl/result-from-optional.mts +0 -80
  509. package/src/functional/result/impl/result-from-promise.mts +0 -51
  510. package/src/functional/result/impl/result-from-throwable.mts +0 -48
  511. package/src/functional/result/impl/result-is-err.mts +0 -26
  512. package/src/functional/result/impl/result-is-ok.mts +0 -26
  513. package/src/functional/result/impl/result-is-result.mts +0 -28
  514. package/src/functional/result/impl/result-map-err.mts +0 -96
  515. package/src/functional/result/impl/result-map.mts +0 -96
  516. package/src/functional/result/impl/result-match.mts +0 -108
  517. package/src/functional/result/impl/result-ok.mts +0 -33
  518. package/src/functional/result/impl/result-or-else.mts +0 -73
  519. package/src/functional/result/impl/result-safe-try.mts +0 -110
  520. package/src/functional/result/impl/result-safe-unwrap.mts +0 -50
  521. package/src/functional/result/impl/result-swap.mts +0 -31
  522. package/src/functional/result/impl/result-to-optional.mts +0 -37
  523. package/src/functional/result/impl/result-unwrap-err-or.mts +0 -66
  524. package/src/functional/result/impl/result-unwrap-err-throw.mts +0 -56
  525. package/src/functional/result/impl/result-unwrap-err.mts +0 -38
  526. package/src/functional/result/impl/result-unwrap-ok-or.mts +0 -66
  527. package/src/functional/result/impl/result-unwrap-ok.mts +0 -39
  528. package/src/functional/result/impl/result-unwrap-throw.mts +0 -46
  529. package/src/functional/result/impl/result-zip.mts +0 -42
  530. package/src/functional/result/impl/tag.mts +0 -8
  531. package/src/functional/result/impl/types.mts +0 -38
  532. package/src/functional/result/index.mts +0 -1
  533. package/src/functional/result/result.mts +0 -19
  534. package/src/functional/result.test.mts +0 -1349
  535. package/src/functional/ternary-result/impl/index.mts +0 -28
  536. package/src/functional/ternary-result/impl/tag.mts +0 -17
  537. package/src/functional/ternary-result/impl/ternary-result-err.mts +0 -21
  538. package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +0 -65
  539. package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +0 -112
  540. package/src/functional/ternary-result/impl/ternary-result-fold.mts +0 -102
  541. package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +0 -30
  542. package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +0 -36
  543. package/src/functional/ternary-result/impl/ternary-result-is-err.mts +0 -24
  544. package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +0 -26
  545. package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +0 -32
  546. package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +0 -25
  547. package/src/functional/ternary-result/impl/ternary-result-map-err.mts +0 -74
  548. package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +0 -79
  549. package/src/functional/ternary-result/impl/ternary-result-map.mts +0 -95
  550. package/src/functional/ternary-result/impl/ternary-result-ok.mts +0 -22
  551. package/src/functional/ternary-result/impl/ternary-result-or-else.mts +0 -72
  552. package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +0 -31
  553. package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +0 -54
  554. package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +0 -42
  555. package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +0 -25
  556. package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +0 -51
  557. package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +0 -39
  558. package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +0 -48
  559. package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +0 -48
  560. package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +0 -40
  561. package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +0 -25
  562. package/src/functional/ternary-result/impl/ternary-result-warn.mts +0 -28
  563. package/src/functional/ternary-result/impl/ternary-result-zip.mts +0 -61
  564. package/src/functional/ternary-result/impl/types.mts +0 -46
  565. package/src/functional/ternary-result/impl/variant-name.mts +0 -18
  566. package/src/functional/ternary-result/index.mts +0 -1
  567. package/src/functional/ternary-result/ternary-result.mts +0 -50
  568. package/src/functional/ternary-result.test.mts +0 -310
  569. package/src/guard/has-key.test.mts +0 -111
  570. package/src/guard/is-non-null-object.test.mts +0 -109
  571. package/src/guard/is-record.test.mts +0 -195
  572. package/src/guard/key-is-in.test.mts +0 -21
  573. package/src/others/unknown-to-string.test.mts +0 -295
@@ -1,110 +0,0 @@
1
- import { hasKey, isRecord } from '../../../guard/index.mjs';
2
- import { type Err } from '../../../types.mjs';
3
- import { type Result, type UnknownResult } from '../result.mjs';
4
- import { type UnwrapErr, type UnwrapOk } from './types.mjs';
5
-
6
- /**
7
- * Runs a generator body in which `yield* Result.safeUnwrap(...)` unwraps `Ok`
8
- * values and short-circuits on the first `Err`, emulating Rust's `?` operator
9
- * (early-return error propagation).
10
- *
11
- * The body must return a `Result`. If every unwrapped `Result` is `Ok`, the
12
- * returned value is the body's `Result`; otherwise it is the first `Err`
13
- * encountered, and the rest of the body never runs — though the generator is
14
- * closed rather than dropped, so `finally` blocks and `using` disposals
15
- * pending in the body still run. An exception thrown by the body is not
16
- * converted to an `Err`: it propagates out of `safeTry` (as a rejected
17
- * `Promise` for an async body). Use {@link Result.fromThrowable} for that.
18
- *
19
- * Passing an async generator (`async function*`) returns a
20
- * `Promise<Result<...>>` instead, so `await` can be used inside the body.
21
- * Note that `yield*` inside an `async function*` awaits what it receives, so
22
- * unwrapping an `Ok` whose value is itself a `Promise` yields the awaited
23
- * value there while the static type still says `Promise<...>`; keep promises
24
- * out of the `Ok` side of a `Result` unwrapped in an async body.
25
- *
26
- * @example
27
- *
28
- * ```ts
29
- * const parseTwo = (a: string, b: string): Result<number, Error> =>
30
- * Result.safeTry(function* () {
31
- * const x = yield* Result.safeUnwrap(Num.safeParseInt(a));
32
- *
33
- * const y = yield* Result.safeUnwrap(Num.safeParseInt(b));
34
- *
35
- * return Result.ok(x + y);
36
- * });
37
- *
38
- * assert.deepStrictEqual(parseTwo('1', '2'), Result.ok(3));
39
- *
40
- * assert.isTrue(Result.isErr(parseTwo('1', 'not a number')));
41
- * ```
42
- *
43
- * @template Y The union of `Err` types unwrapped via
44
- * {@link Result.safeUnwrap} (`never` if nothing is unwrapped).
45
- * @template R2 The `Result` type returned by the body.
46
- * @param body A generator function whose `yield*` expressions delegate to
47
- * {@link Result.safeUnwrap} and whose return value is a `Result`.
48
- * @returns The body's `Result`, or the first `Err` short-circuited out of it
49
- * (wrapped in a `Promise` for an async generator body).
50
- */
51
- export function safeTry<Y extends Err<unknown>, R2 extends UnknownResult>(
52
- body: () => Generator<Y, R2>,
53
- ): Result<UnwrapOk<R2>, UnwrapErr<R2> | UnwrapErr<Y>>;
54
-
55
- export function safeTry<Y extends Err<unknown>, R2 extends UnknownResult>(
56
- body: () => AsyncGenerator<Y, R2>,
57
- ): Promise<Result<UnwrapOk<R2>, UnwrapErr<R2> | UnwrapErr<Y>>>;
58
-
59
- export function safeTry(
60
- body:
61
- | (() => AsyncGenerator<UnknownResult, UnknownResult>)
62
- | (() => Generator<UnknownResult, UnknownResult>),
63
- ): Promise<UnknownResult> | UnknownResult {
64
- const generator = body();
65
-
66
- // A yielded `Err` and a returned `Result` are both already the final
67
- // answer, so the first step's `value` is the result in either case: the
68
- // generator is closed rather than resumed after yielding.
69
- const step = generator.next();
70
-
71
- if (isSyncStep(step)) {
72
- // Dropping a suspended generator would skip the `finally` blocks and
73
- // `using` disposals still pending in the body; closing it runs them
74
- // before the short-circuited `Err` is handed back. `isSyncGenerator` is
75
- // what makes `return()` here synchronous rather than a floating promise.
76
- if (step.done !== true && isSyncGenerator(generator, step)) {
77
- generator.return(step.value);
78
- }
79
-
80
- return step.value;
81
- }
82
-
83
- return step.then(async (asyncStep) => {
84
- if (asyncStep.done !== true) {
85
- await generator.return(asyncStep.value);
86
- }
87
-
88
- return asyncStep.value;
89
- });
90
- }
91
-
92
- // A sync generator's `next()` returns a plain `{ value, done }` object with
93
- // own properties, while an async generator's returns a `Promise`, whose
94
- // `then` lives on the prototype — so an own-key check on `done` separates the
95
- // two.
96
- const isSyncStep = (
97
- value: unknown,
98
- ): value is IteratorResult<UnknownResult, UnknownResult> =>
99
- isRecord(value) && hasKey(value, 'done');
100
-
101
- // The generator-side counterpart of `isSyncStep`: a step in the sync form can
102
- // only have come from a sync generator, so the step is what narrows the
103
- // generator that produced it — hence the predicate reads its second argument
104
- // and not its first.
105
- const isSyncGenerator = (
106
- _generator:
107
- | AsyncGenerator<UnknownResult, UnknownResult>
108
- | Generator<UnknownResult, UnknownResult>,
109
- step: unknown,
110
- ): _generator is Generator<UnknownResult, UnknownResult> => isSyncStep(step);
@@ -1,50 +0,0 @@
1
- import { type UnknownResult } from '../result.mjs';
2
- import { isErr } from './result-is-err.mjs';
3
- import { type NarrowToErr, type UnwrapOk } from './types.mjs';
4
-
5
- /**
6
- * Unwraps a `Result` inside a {@link Result.safeTry} generator body via
7
- * `yield*`, emulating Rust's `?` operator.
8
- *
9
- * If the `Result` is `Ok`, the `yield*` expression evaluates to the contained
10
- * value and execution continues. If it is `Err`, the error is yielded to
11
- * {@link Result.safeTry}, which returns it immediately — the rest of the
12
- * generator body never runs.
13
- *
14
- * This generator must only be delegated to (`yield*`) inside a
15
- * {@link Result.safeTry} body; resuming it after it has yielded an `Err`
16
- * throws.
17
- *
18
- * @example
19
- *
20
- * ```ts
21
- * const result = Result.safeTry(function* () {
22
- * const x = yield* Result.safeUnwrap(Result.ok(2));
23
- *
24
- * const y = yield* Result.safeUnwrap(Result.ok(3));
25
- *
26
- * return Result.ok(x + y);
27
- * });
28
- *
29
- * assert.deepStrictEqual(result, Result.ok(5));
30
- * ```
31
- *
32
- * @template R The input `UnknownResult` type.
33
- * @param result The `Result` to unwrap.
34
- * @returns A generator that yields the `Err` (if any) and returns the `Ok`
35
- * value.
36
- */
37
- export function* safeUnwrap<R extends UnknownResult>(
38
- result: R,
39
- ): Generator<NarrowToErr<R>, UnwrapOk<R>, unknown> {
40
- if (isErr(result)) {
41
- yield result;
42
-
43
- throw new Error(
44
- '`safeUnwrap()` generator was resumed after yielding an `Err`; it must only be used via `yield*` inside `safeTry()`',
45
- );
46
- }
47
-
48
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
49
- return result.value as UnwrapOk<R>;
50
- }
@@ -1,31 +0,0 @@
1
- import { type Result, type UnknownResult } from '../result.mjs';
2
- import { err } from './result-err.mjs';
3
- import { isOk } from './result-is-ok.mjs';
4
- import { ok } from './result-ok.mjs';
5
- import { unwrapOk } from './result-unwrap-ok.mjs';
6
- import { type UnwrapErr, type UnwrapOk } from './types.mjs';
7
-
8
- /**
9
- * Swaps the success and error values of a `Result`.
10
- *
11
- * @example
12
- *
13
- * ```ts
14
- * const okValue = Result.ok('value');
15
- *
16
- * const errValue = Result.err('error');
17
- *
18
- * assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));
19
- *
20
- * assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));
21
- * ```
22
- *
23
- * @template R The input `UnknownResult` type.
24
- * @param result The `Result` to swap.
25
- * @returns A new `Result` with success and error swapped.
26
- */
27
- export const swap = <R extends UnknownResult>(
28
- result: R,
29
- ): Result<UnwrapErr<R>, UnwrapOk<R>> =>
30
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
31
- isOk(result) ? err(unwrapOk(result)) : ok(result.value as UnwrapErr<R>);
@@ -1,37 +0,0 @@
1
- import { Optional } from '../../optional/index.mjs';
2
- import { type UnknownResult } from '../result.mjs';
3
- import { isOk } from './result-is-ok.mjs';
4
- import { unwrapOk } from './result-unwrap-ok.mjs';
5
- import { type UnwrapOk } from './types.mjs';
6
-
7
- /**
8
- * Converts a `Result` to an `Optional`.
9
- *
10
- * This conversion is useful when you want to discard error information and
11
- * only care about whether an operation succeeded. The error information is
12
- * lost in this conversion, so use it when error details are not needed.
13
- *
14
- * If the `Result` is `Ok`, returns `Some` with the value. If the `Result` is
15
- * `Err`, returns `None`.
16
- *
17
- * @example
18
- *
19
- * ```ts
20
- * const okValue = Result.ok(7);
21
- *
22
- * const errValue = Result.err('fail');
23
- *
24
- * assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));
25
- *
26
- * assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);
27
- * ```
28
- *
29
- * @template R The input `UnknownResult` type.
30
- * @param result The `Result` to convert.
31
- * @returns An `Optional<UnwrapOk<R>>` containing the success value or
32
- * representing `None`.
33
- */
34
- export const toOptional = <R extends UnknownResult>(
35
- result: R,
36
- ): Optional<UnwrapOk<R>> =>
37
- isOk(result) ? Optional.some(unwrapOk(result)) : Optional.none;
@@ -1,66 +0,0 @@
1
- import { type UnknownResult } from '../result.mjs';
2
- import { unwrapErr } from './result-unwrap-err.mjs';
3
- import { type UnwrapErr } from './types.mjs';
4
-
5
- /**
6
- * Unwraps a `Result`, returning the error value or a default value if it is
7
- * `Result.Ok`.
8
- *
9
- * @example
10
- *
11
- * ```ts
12
- * const okResult = Result.ok('success');
13
- *
14
- * const errResult = Result.err('failure');
15
- *
16
- * assert.isTrue(Result.unwrapErrOr(okResult, 'default') === 'default');
17
- *
18
- * assert.isTrue(Result.unwrapErrOr(errResult, 'default') === 'failure');
19
- *
20
- * const unwrapError = Result.unwrapErrOr('fallback error');
21
- *
22
- * assert.isTrue(unwrapError(Result.err('boom')) === 'boom');
23
- *
24
- * assert.isTrue(unwrapError(Result.ok('no error')) === 'fallback error');
25
- * ```
26
- *
27
- * @template R The `UnknownResult` type to unwrap.
28
- * @template D The type of the default value.
29
- * @param result The `Result` to unwrap.
30
- * @param defaultValue The value to return if `result` is `Result.Ok`.
31
- * @returns The error value if `Result.Err`, otherwise `defaultValue`.
32
- */
33
- export function unwrapErrOr<R extends UnknownResult, D>(
34
- result: R,
35
- defaultValue: D,
36
- ): D | UnwrapErr<R>;
37
-
38
- // Curried version
39
- export function unwrapErrOr<D>(
40
- defaultValue: D,
41
- ): <R extends UnknownResult>(result: R) => D | UnwrapErr<R>;
42
-
43
- export function unwrapErrOr<R extends UnknownResult, D>(
44
- ...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]
45
- ): D | UnwrapErr<R> | ((result: R) => D | UnwrapErr<R>) {
46
- switch (args.length) {
47
- case 2: {
48
- // Direct version: first argument is result
49
- const [result, defaultValue] = args;
50
-
51
- return unwrapErrOrImpl(result, defaultValue);
52
- }
53
-
54
- case 1: {
55
- // Curried version
56
- const [defaultValue] = args;
57
-
58
- return (result: R) => unwrapErrOrImpl(result, defaultValue);
59
- }
60
- }
61
- }
62
-
63
- const unwrapErrOrImpl = <R extends UnknownResult, D>(
64
- result: R,
65
- defaultValue: D,
66
- ): D | UnwrapErr<R> => unwrapErr(result) ?? defaultValue;
@@ -1,56 +0,0 @@
1
- import { unknownToString } from '../../../others/index.mjs';
2
- import { match } from '../../match.mjs';
3
- import { type UnknownResult } from '../result.mjs';
4
- import { isErr } from './result-is-err.mjs';
5
- import { type UnwrapErr, type UnwrapOk } from './types.mjs';
6
-
7
- /**
8
- * Unwraps a `Result`, returning the error value. Throws an error if the
9
- * `Result` is `Result.Ok`.
10
- *
11
- * This function is used when you expect a Result to be an error and want to
12
- * extract the error value. If the Result is unexpectedly Ok, it will throw an
13
- * error with information about the unexpected success value.
14
- *
15
- * @example
16
- *
17
- * ```ts
18
- * const errResult = Result.err(new Error('broken'));
19
- *
20
- * const okResult = Result.ok('value');
21
- *
22
- * assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');
23
- *
24
- * assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
25
- * ```
26
- *
27
- * @template R The `UnknownResult` type to unwrap.
28
- * @param result The `Result` to unwrap.
29
- * @param toStr An optional function to convert the success value to a string
30
- * for the error message when the Result is unexpectedly Ok. Defaults to
31
- * `String`.
32
- * @returns The error value if `Result.Err`.
33
- * @throws {Error} Error with message "Expected Err but got Ok: {value}" if
34
- * the `Result` is `Result.Ok`.
35
- */
36
- export const unwrapErrThrow = <R extends UnknownResult>(
37
- result: R,
38
- toStr: (v: UnwrapOk<R>) => string = unknownToString,
39
- ): UnwrapErr<R> => {
40
- if (isErr(result)) {
41
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
42
- return result.value as UnwrapErr<R>;
43
- }
44
-
45
- const variant = match(result.$$tag, {
46
- 'ts-data-forge::Result.ok': 'Ok',
47
- 'ts-data-forge::Result.err': 'Err',
48
- });
49
-
50
- throw new Error(
51
- `Expected Err but got ${variant}: ${toStr(
52
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
53
- result.value as UnwrapOk<R>,
54
- )}`,
55
- );
56
- };
@@ -1,38 +0,0 @@
1
- import { type UnknownResult } from '../result.mjs';
2
- import { isErr } from './result-is-err.mjs';
3
- import { type UnwrapErr } from './types.mjs';
4
-
5
- /**
6
- * Unwraps a `Result`, returning the error value or `undefined` if it is
7
- * `Result.Ok`.
8
- *
9
- * This provides a safe way to extract error values from Results without
10
- * throwing exceptions. Useful for error handling patterns where you want to
11
- * check for specific error conditions.
12
- *
13
- * @example
14
- *
15
- * ```ts
16
- * const okResult = Result.ok('data');
17
- *
18
- * const errResult = Result.err('problem');
19
- *
20
- * // Result.unwrapErr returns undefined for Ok results
21
- *
22
- * // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
23
- * assert.isTrue(Result.unwrapErr(okResult) === undefined);
24
- *
25
- * // Result.unwrapErr returns the error value for Err results
26
- *
27
- * assert.isTrue(Result.unwrapErr(errResult) === 'problem');
28
- * ```
29
- *
30
- * @template R The `UnknownResult` type to unwrap.
31
- * @param result The `Result` to unwrap.
32
- * @returns The error value if `Result.Err`, otherwise `undefined`.
33
- */
34
- export const unwrapErr = <R extends UnknownResult>(
35
- result: R,
36
- ): UnwrapErr<R> | undefined =>
37
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
38
- isErr(result) ? (result.value as UnwrapErr<R>) : undefined;
@@ -1,66 +0,0 @@
1
- import { type UnknownResult } from '../result.mjs';
2
- import { unwrapOk } from './result-unwrap-ok.mjs';
3
- import { type UnwrapOk } from './types.mjs';
4
-
5
- /**
6
- * Unwraps a `Result`, returning the success value or a default value if it is
7
- * `Result.Err`.
8
- *
9
- * @example
10
- *
11
- * ```ts
12
- * const okValue = Result.ok(10);
13
- *
14
- * const errValue = Result.err('fail');
15
- *
16
- * assert.isTrue(Result.unwrapOkOr(okValue, 0) === 10);
17
- *
18
- * assert.isTrue(Result.unwrapOkOr(errValue, 0) === 0);
19
- *
20
- * const unwrapWithDefault = Result.unwrapOkOr(5);
21
- *
22
- * assert.isTrue(unwrapWithDefault(Result.ok(3)) === 3);
23
- *
24
- * assert.isTrue(unwrapWithDefault(Result.err('no data')) === 5);
25
- * ```
26
- *
27
- * @template R The `UnknownResult` type to unwrap.
28
- * @template D The type of the default value.
29
- * @param result The `Result` to unwrap.
30
- * @param defaultValue The value to return if `result` is `Result.Err`.
31
- * @returns The success value if `Result.Ok`, otherwise `defaultValue`.
32
- */
33
- export function unwrapOkOr<R extends UnknownResult, D>(
34
- result: R,
35
- defaultValue: D,
36
- ): D | UnwrapOk<R>;
37
-
38
- // Curried version
39
- export function unwrapOkOr<D>(
40
- defaultValue: D,
41
- ): <R extends UnknownResult>(result: R) => D | UnwrapOk<R>;
42
-
43
- export function unwrapOkOr<R extends UnknownResult, D>(
44
- ...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]
45
- ): D | UnwrapOk<R> | ((result: R) => D | UnwrapOk<R>) {
46
- switch (args.length) {
47
- case 2: {
48
- // Direct version: first argument is result
49
- const [result, defaultValue] = args;
50
-
51
- return unwrapOkOrImpl(result, defaultValue);
52
- }
53
-
54
- case 1: {
55
- // Curried version
56
- const [defaultValue] = args;
57
-
58
- return (result: R) => unwrapOkOrImpl(result, defaultValue);
59
- }
60
- }
61
- }
62
-
63
- const unwrapOkOrImpl = <R extends UnknownResult, D>(
64
- result: R,
65
- defaultValue: D,
66
- ): D | UnwrapOk<R> => unwrapOk(result) ?? defaultValue;
@@ -1,39 +0,0 @@
1
- import { type Ok } from '../../../types.mjs';
2
- import { type UnknownResult } from '../result.mjs';
3
- import { isOk } from './result-is-ok.mjs';
4
- import { type UnwrapOk } from './types.mjs';
5
-
6
- /**
7
- * Safely unwraps the success value, returning `undefined` for failures.
8
- *
9
- * @example
10
- *
11
- * ```ts
12
- * const okResult = Result.ok(42);
13
- *
14
- * const errResult = Result.err('oops');
15
- *
16
- * // Result.unwrapOk returns the value for Ok results
17
- *
18
- * assert.isTrue(Result.unwrapOk(okResult) === 42);
19
- *
20
- * // Result.unwrapOk returns undefined for Err results
21
- *
22
- * // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
23
- * assert.isTrue(Result.unwrapOk(errResult) === undefined);
24
- * ```
25
- */
26
- export function unwrapOk<R extends Ok<unknown>>(result: R): UnwrapOk<R>;
27
-
28
- export function unwrapOk<R extends UnknownResult>(
29
- result: R,
30
- ): UnwrapOk<R> | undefined;
31
-
32
- export function unwrapOk<R extends UnknownResult>(
33
- result: R,
34
- ): UnwrapOk<R> | undefined {
35
- return isOk(result)
36
- ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
37
- (result.value as UnwrapOk<R>)
38
- : undefined;
39
- }
@@ -1,46 +0,0 @@
1
- import { unknownToString } from '../../../others/index.mjs';
2
- import { type UnknownResult } from '../result.mjs';
3
- import { isErr } from './result-is-err.mjs';
4
- import { type UnwrapErr, type UnwrapOk } from './types.mjs';
5
-
6
- /**
7
- * Unwraps a `Result`, returning the success value. Throws an error if the
8
- * `Result` is `Result.Err`.
9
- *
10
- * This is useful when you're confident that a Result should contain a success
11
- * value and want to treat errors as exceptional conditions. The error message
12
- * will be constructed from the error value using the provided string
13
- * conversion function.
14
- *
15
- * @example
16
- *
17
- * ```ts
18
- * const okResult = Result.ok('data');
19
- *
20
- * const errResult = Result.err(new Error('fail'));
21
- *
22
- * assert.isTrue(Result.unwrapThrow(okResult) === 'data');
23
- *
24
- * assert.throws(() => Result.unwrapThrow(errResult), Error, 'fail');
25
- * ```
26
- *
27
- * @template R The `UnknownResult` type to unwrap.
28
- * @param result The `Result` to unwrap.
29
- * @param toStr An optional function to convert the error value to a string
30
- * for the error message. Defaults to `String`.
31
- * @returns The success value if `Result.Ok`.
32
- * @throws {Error} Error with the stringified error value if the `Result` is
33
- * `Result.Err`.
34
- */
35
- export const unwrapThrow = <R extends UnknownResult>(
36
- result: R,
37
- toStr: (e: UnwrapErr<R>) => string = unknownToString,
38
- ): UnwrapOk<R> => {
39
- if (isErr(result)) {
40
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
41
- throw new Error(toStr(result.value as UnwrapErr<R>));
42
- }
43
-
44
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
45
- return result.value as UnwrapOk<R>;
46
- };
@@ -1,42 +0,0 @@
1
- import { type Result } from '../result.mjs';
2
- import { isOk } from './result-is-ok.mjs';
3
- import { ok } from './result-ok.mjs';
4
-
5
- /**
6
- * Combines two `Result` values into a single `Result` containing a tuple. If
7
- * either `Result` is `Err`, returns the first `Err` encountered.
8
- *
9
- * @example
10
- *
11
- * ```ts
12
- * const first = Result.ok('left');
13
- *
14
- * const second = Result.ok(1);
15
- *
16
- * const expected = ['left', 1] as const;
17
- *
18
- * assert.deepStrictEqual(Result.zip(first, second), Result.ok(expected));
19
- *
20
- * assert.deepStrictEqual(
21
- * Result.zip(first, Result.err('error')),
22
- * Result.err('error'),
23
- * );
24
- * ```
25
- *
26
- * @template S1 The success type of the first `Result`.
27
- * @template E1 The error type of the first `Result`.
28
- * @template S2 The success type of the second `Result`.
29
- * @template E2 The error type of the second `Result`.
30
- * @param resultA The first `Result`.
31
- * @param resultB The second `Result`.
32
- * @returns A `Result` containing a tuple of both values, or the first `Err`.
33
- */
34
- export const zip = <S1, E1, S2, E2>(
35
- resultA: Result<S1, E1>,
36
- resultB: Result<S2, E2>,
37
- ): Result<readonly [S1, S2], E1 | E2> =>
38
- isOk(resultA)
39
- ? isOk(resultB)
40
- ? ok([resultA.value, resultB.value] as const)
41
- : resultB
42
- : resultA;
@@ -1,8 +0,0 @@
1
- /** @internal Tag identifying the Ok variant. */
2
- import { type Err, type Ok } from '../../../types.mjs';
3
-
4
- export const OkTypeTagName: Ok<unknown>['$$tag'] = 'ts-data-forge::Result.ok';
5
-
6
- /** @internal Tag identifying the Err variant. */
7
- export const ErrTypeTagName: Err<unknown>['$$tag'] =
8
- 'ts-data-forge::Result.err';
@@ -1,38 +0,0 @@
1
- import { type Err, type Ok } from '../../../types.mjs';
2
- import { type UnknownResult } from '../result.mjs';
3
-
4
- /**
5
- * Extracts the success value type `S` from a `Result.Ok<S>`. If the `Result`
6
- * is `Result.Err<E>`, resolves to `never`.
7
- *
8
- * @template R The `UnknownResult` type to unwrap.
9
- */
10
- export type UnwrapOk<R extends UnknownResult> =
11
- R extends Ok<infer S> ? S : never;
12
-
13
- /**
14
- * Extracts the error value type `E` from a `Result.Err<E>`. If the `Result`
15
- * is `Result.Ok<S>`, resolves to `never`.
16
- *
17
- * @template R The `UnknownResult` type to unwrap.
18
- */
19
- export type UnwrapErr<R extends UnknownResult> =
20
- R extends Err<infer E> ? E : never;
21
-
22
- /**
23
- * Narrows a `UnknownResult` type to `Result.Ok<S>` if it is an `Ok`. If the
24
- * `Result` is `Result.Err<E>`, resolves to `never`.
25
- *
26
- * @template R The `UnknownResult` type to narrow.
27
- */
28
- export type NarrowToOk<R extends UnknownResult> =
29
- R extends Ok<unknown> ? R : never;
30
-
31
- /**
32
- * Narrows a `UnknownResult` type to `Result.Err<E>` if it is an `Err`. If the
33
- * `Result` is `Result.Ok<S>`, resolves to `never`.
34
- *
35
- * @template R The `UnknownResult` type to narrow.
36
- */
37
- export type NarrowToErr<R extends UnknownResult> =
38
- R extends Err<unknown> ? R : never;
@@ -1 +0,0 @@
1
- export * from './result.mjs';
@@ -1,19 +0,0 @@
1
- import { type Err, type Ok } from '../../types.mjs';
2
-
3
- /**
4
- * Represents a value that can either be a success (`Ok`) or an error (`Err`).
5
- *
6
- * @template S The type of the success value.
7
- * @template E The type of the error value.
8
- */
9
- export type Result<S, E> = Ok<S> | Err<E>;
10
-
11
- /**
12
- * Base type for any `Result`, used for generic constraints. Represents a
13
- * `Result` with unknown success and error types.
14
- */
15
- export type UnknownResult = Ok<unknown> | Err<unknown>;
16
-
17
- export type { Err, Ok } from '../../types.mjs';
18
-
19
- export * as Result from './impl/index.mjs';