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,883 +0,0 @@
1
- import { expectType } from '../expect-type.mjs';
2
- import { Num } from '../number/index.mjs';
3
- import { unknownToString } from '../others/index.mjs';
4
- import { type None, type Some } from '../types.mjs';
5
- import { Optional, type UnknownOptional } from './optional/index.mjs';
6
- import { pipe } from './pipe.mjs';
7
- import { Result } from './result/index.mjs';
8
-
9
- describe('Optional test', () => {
10
- describe('isOptional', () => {
11
- test('should return true for Some values', () => {
12
- assert.isTrue(Optional.isOptional(Optional.some(42)));
13
-
14
- assert.isTrue(Optional.isOptional(Optional.some('hello')));
15
-
16
- assert.isTrue(Optional.isOptional(Optional.some(null)));
17
-
18
- assert.isTrue(Optional.isOptional(Optional.some(undefined)));
19
- });
20
-
21
- test('should return true for None value', () => {
22
- assert.isTrue(Optional.isOptional(Optional.none));
23
- });
24
-
25
- test('should return false for non-Optional values', () => {
26
- assert.isFalse(Optional.isOptional(42));
27
-
28
- assert.isFalse(Optional.isOptional('hello'));
29
-
30
- assert.isFalse(Optional.isOptional(null));
31
-
32
- assert.isFalse(Optional.isOptional(undefined));
33
-
34
- assert.isFalse(Optional.isOptional({}));
35
-
36
- assert.isFalse(Optional.isOptional({ type: 'fake', value: 42 }));
37
- });
38
- });
39
-
40
- describe('some', () => {
41
- test('should create a Some variant with the provided value', () => {
42
- const someNumber = Optional.some(42);
43
-
44
- assert.isTrue(Optional.isSome(someNumber));
45
-
46
- expect(Optional.unwrap(someNumber)).toBe(42);
47
-
48
- const someString = Optional.some('hello');
49
-
50
- assert.isTrue(Optional.isSome(someString));
51
-
52
- expect(Optional.unwrap(someString)).toBe('hello');
53
-
54
- const someObject = Optional.some({ name: 'Alice', age: 30 });
55
-
56
- assert.isTrue(Optional.isSome(someObject));
57
-
58
- assert.deepStrictEqual(Optional.unwrap(someObject), {
59
- name: 'Alice',
60
- age: 30,
61
- });
62
- });
63
-
64
- test('should preserve const types', () => {
65
- expectTypeOf(Optional.some('test' as const)).toEqualTypeOf<
66
- Some<'test'>
67
- >();
68
- });
69
- });
70
-
71
- describe('none', () => {
72
- test('should be a singleton None value', () => {
73
- assert.isTrue(Optional.isNone(Optional.none));
74
-
75
- assert.isFalse(Optional.isSome(Optional.none));
76
-
77
- // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
78
- expect(Optional.unwrapOr(Optional.none, undefined)).toBeUndefined();
79
- });
80
-
81
- test('should always reference the same instance', () => {
82
- expect(Optional.none).toBe(Optional.none);
83
- });
84
- });
85
-
86
- describe('isSome and isNone', () => {
87
- test('should correctly identify Some values', () => {
88
- const some = Optional.some(42);
89
-
90
- assert.isTrue(Optional.isSome(some));
91
-
92
- assert.isFalse(Optional.isNone(some));
93
- });
94
-
95
- test('should correctly identify None values', () => {
96
- const none = Optional.none;
97
-
98
- assert.isFalse(Optional.isSome(none));
99
-
100
- assert.isTrue(Optional.isNone(none));
101
- });
102
-
103
- test('should act as type guards', () => {
104
- const optional = Optional.some(42) as Optional<number>;
105
-
106
- if (Optional.isSome(optional)) {
107
- expectType<typeof optional, Some<number>>('=');
108
- }
109
-
110
- if (Optional.isNone(optional)) {
111
- expectType<typeof optional, None>('<=');
112
- }
113
- });
114
- });
115
-
116
- describe('map', () => {
117
- test('should map over Some values', () => {
118
- const some = Optional.some(5);
119
-
120
- const mapped = Optional.map(some, (x) => x * 2);
121
-
122
- assert.isTrue(Optional.isSome(mapped));
123
-
124
- if (Optional.isSome(mapped)) {
125
- expect(Optional.unwrap(mapped)).toBe(10);
126
- }
127
- });
128
-
129
- test('should return None for None values', () => {
130
- const none = Optional.none;
131
-
132
- const mapped = Optional.map(none, (x: never) => x * 2);
133
-
134
- assert.isTrue(Optional.isNone(mapped));
135
- });
136
-
137
- test('should support chaining', () => {
138
- const result = Optional.map(
139
- Optional.map(Optional.some('hello'), (s) => s.toUpperCase()),
140
- (s) => s.length,
141
- );
142
-
143
- if (Optional.isSome(result)) {
144
- expect(Optional.unwrap(result)).toBe(5);
145
- }
146
- });
147
-
148
- test('curried form is usable from a caller generic over the optional', () => {
149
- // The motivating case: with the curried parameter fixed to
150
- // `Optional<S>`, `S` binds to `Optional.Unwrap<O>` here and a bare
151
- // `O extends UnknownOptional` is not assignable to
152
- // `Optional<Optional.Unwrap<O>>`, so this only compiles because the
153
- // returned function is generic over the whole optional.
154
- const liftMap =
155
- <O extends UnknownOptional, B>(mapFn: (x: Optional.Unwrap<O>) => B) =>
156
- (optional: O): Optional<B> =>
157
- Optional.map(mapFn)(optional);
158
-
159
- const lengthOf = liftMap<Optional<string>, number>((s) => s.length);
160
-
161
- const mapped = lengthOf(Optional.some('abc'));
162
-
163
- expectType<typeof mapped, Optional<number>>('=');
164
-
165
- assert.deepStrictEqual(mapped, Optional.some(3));
166
-
167
- assert.deepStrictEqual(lengthOf(Optional.none), Optional.none);
168
- });
169
-
170
- test('curried form still infers the result precisely', () => {
171
- const mapToLength = Optional.map((text: string) => text.length);
172
-
173
- const mapped = mapToLength(Optional.some('abc'));
174
-
175
- expectType<typeof mapped, Optional<number>>('=');
176
-
177
- assert.deepStrictEqual(mapped, Optional.some(3));
178
-
179
- const empty = mapToLength(Optional.none);
180
-
181
- expectType<typeof empty, Optional<number>>('=');
182
-
183
- assert.deepStrictEqual(empty, Optional.none);
184
- });
185
-
186
- test('curried form still rejects a mismatched value type', () => {
187
- const mapToLength = Optional.map((text: string) => text.length);
188
-
189
- // @ts-expect-error an Optional<number> is not an Optional<string>
190
- const rejected = (): unknown => mapToLength(Optional.some(42));
191
-
192
- expect(rejected).toBeTypeOf('function');
193
- });
194
-
195
- test('should preserve types correctly', () => {
196
- const some = Optional.some(42);
197
-
198
- expectTypeOf(Optional.map(some, (x) => x.toString())).toEqualTypeOf<
199
- Optional<string>
200
- >();
201
- });
202
-
203
- test('should support curried form', () => {
204
- const doubler = Optional.map((x: number) => x * 2);
205
-
206
- const some = Optional.some(5);
207
-
208
- const mapped = doubler(some);
209
-
210
- assert.isTrue(Optional.isSome(mapped));
211
-
212
- if (Optional.isSome(mapped)) {
213
- expect(Optional.unwrap(mapped)).toBe(10);
214
- }
215
-
216
- const none = Optional.none;
217
-
218
- const mappedNone = doubler(none);
219
-
220
- assert.isTrue(Optional.isNone(mappedNone));
221
- });
222
-
223
- test('should work with pipe when curried', () => {
224
- const doubler = Optional.map((x: number) => x * 2);
225
-
226
- const toStringFn = Optional.map((x: number) => x.toString());
227
-
228
- const result = pipe(Optional.some(5)).map(doubler).map(toStringFn).value;
229
-
230
- assert.isTrue(Optional.isSome(result));
231
-
232
- if (Optional.isSome(result)) {
233
- expect(Optional.unwrap(result)).toBe('10');
234
- }
235
- });
236
- });
237
-
238
- describe('unwrap', () => {
239
- test('should return the value for Some', () => {
240
- expect(Optional.unwrap(Optional.some(42))).toBe(42);
241
-
242
- expect(Optional.unwrap(Optional.some('hello'))).toBe('hello');
243
-
244
- expect(Optional.unwrap(Optional.some(null))).toBeNull();
245
- });
246
-
247
- test('should return undefined for None', () => {
248
- // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
249
- expect(Optional.unwrapOr(Optional.none, undefined)).toBeUndefined();
250
- });
251
-
252
- test('should have correct return types', () => {
253
- const someNumber = Optional.some(42);
254
-
255
- expectTypeOf(Optional.unwrap(someNumber)).toExtend<number | undefined>();
256
-
257
- const none = Optional.none;
258
-
259
- // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
260
- expectTypeOf(Optional.unwrapOr(none, undefined)).toExtend<undefined>();
261
- });
262
- });
263
-
264
- describe('unwrapThrow', () => {
265
- test('should return the value for Some', () => {
266
- expect(Optional.unwrapThrow(Optional.some(42))).toBe(42);
267
-
268
- expect(Optional.unwrapThrow(Optional.some('hello'))).toBe('hello');
269
- });
270
-
271
- test('should throw for None', () => {
272
- expect(() => Optional.unwrapThrow(Optional.none)).toThrow(
273
- '`unwrapThrow()` has failed because it is `None`',
274
- );
275
- });
276
-
277
- test('should have correct return types', () => {
278
- const someNumber = Optional.some(42);
279
-
280
- expectTypeOf(Optional.unwrapThrow(someNumber)).toExtend<number>();
281
- });
282
- });
283
-
284
- describe('unwrapOr', () => {
285
- test('should return the value for Some', () => {
286
- expect(Optional.unwrapOr(Optional.some(42), 0)).toBe(42);
287
-
288
- expect(Optional.unwrapOr(Optional.some('hello'), 'default')).toBe(
289
- 'hello',
290
- );
291
- });
292
-
293
- test('should return the default value for None', () => {
294
- expect(Optional.unwrapOr(Optional.none, 0)).toBe(0);
295
-
296
- expect(Optional.unwrapOr(Optional.none, 'default')).toBe('default');
297
- });
298
-
299
- test('should have correct return types', () => {
300
- const someNumber = Optional.some(42);
301
-
302
- expectTypeOf(Optional.unwrapOr(someNumber, 0)).toExtend<number>();
303
-
304
- expectTypeOf(Optional.unwrapOr(someNumber, 'default')).toExtend<
305
- number | string
306
- >();
307
-
308
- const none = Optional.none;
309
-
310
- expectTypeOf(Optional.unwrapOr(none, 'default')).toExtend<string>();
311
- });
312
-
313
- test('should support curried form', () => {
314
- const unwrapWithDefault = Optional.unwrapOr(42);
315
-
316
- const someValue = Optional.some(100);
317
-
318
- const result = unwrapWithDefault(someValue);
319
-
320
- expect(result).toBe(100);
321
-
322
- const noneValue = Optional.none;
323
-
324
- const defaultResult = unwrapWithDefault(noneValue);
325
-
326
- expect(defaultResult).toBe(42);
327
- });
328
-
329
- test('should work with pipe when curried', () => {
330
- const unwrapWithDefault = Optional.unwrapOr('default');
331
-
332
- const someResult = pipe(Optional.some('hello')).map(
333
- unwrapWithDefault,
334
- ).value;
335
-
336
- expect(someResult).toBe('hello');
337
-
338
- const noneResult = pipe(Optional.none).map(unwrapWithDefault).value;
339
-
340
- expect(noneResult).toBe('default');
341
- });
342
- });
343
-
344
- describe('expectToBe', () => {
345
- test('should return the value for Some', () => {
346
- const expectNumber = Optional.expectToBe('Expected a number');
347
-
348
- expect(expectNumber(Optional.some(42))).toBe(42);
349
- });
350
-
351
- test('should throw with custom message for None', () => {
352
- const expectNumber = Optional.expectToBe('Expected a number');
353
-
354
- expect(() => expectNumber(Optional.none)).toThrow('Expected a number');
355
- });
356
-
357
- test('should be curried', () => {
358
- const expectValidId = Optional.expectToBe('ID is required');
359
-
360
- const id1 = Optional.some('user-123');
361
-
362
- const id2 = Optional.none;
363
-
364
- expect(expectValidId(id1)).toBe('user-123');
365
-
366
- expect(() => expectValidId(id2)).toThrow('ID is required');
367
- });
368
-
369
- test('should support curried form', () => {
370
- const getValue = Optional.expectToBe('Value must exist');
371
-
372
- const someValue = Optional.some('important data');
373
-
374
- const result = getValue(someValue);
375
-
376
- expect(result).toBe('important data');
377
-
378
- const noneValue = Optional.none;
379
-
380
- expect(() => getValue(noneValue)).toThrow('Value must exist');
381
- });
382
-
383
- test('should work with pipe when curried', () => {
384
- const expectUser = Optional.expectToBe('User not found');
385
-
386
- const someResult = pipe(Optional.some({ name: 'Alice', age: 30 })).map(
387
- expectUser,
388
- ).value;
389
-
390
- assert.deepStrictEqual(someResult, { name: 'Alice', age: 30 });
391
-
392
- expect(() => pipe(Optional.none).map(expectUser).value).toThrow(
393
- 'User not found',
394
- );
395
- });
396
- });
397
-
398
- describe('type utilities', () => {
399
- test('should correctly unwrap types', () => {
400
- type SomeNumber = Some<number>;
401
-
402
- type UnwrappedNumber = Optional.Unwrap<SomeNumber>;
403
-
404
- expectType<UnwrappedNumber, number>('=');
405
-
406
- type UnwrappedNone = Optional.Unwrap<None>;
407
-
408
- expectType<UnwrappedNone, never>('=');
409
- });
410
-
411
- test('should correctly narrow types', () => {
412
- type MaybeNumber = Optional<number>;
413
-
414
- type OnlySome = Optional.NarrowToSome<MaybeNumber>;
415
-
416
- expectType<OnlySome, Some<number>>('=');
417
-
418
- type OnlyNone = Optional.NarrowToNone<MaybeNumber>;
419
-
420
- expectType<OnlyNone, None>('=');
421
- });
422
- });
423
-
424
- describe('flatMap', () => {
425
- test('should chain operations that return Optional', () => {
426
- const parseNumber = (s: string): Optional<number> => {
427
- const n = Result.unwrapOkOr(Num.safeParseFloat(s), Number.NaN);
428
-
429
- return Number.isNaN(n) ? Optional.none : Optional.some(n);
430
- };
431
-
432
- const result = Optional.flatMap(Optional.some('42'), parseNumber);
433
-
434
- if (Optional.isSome(result)) {
435
- expect(Optional.unwrap(result)).toBe(42);
436
- }
437
-
438
- const invalid = Optional.flatMap(Optional.some('abc'), parseNumber);
439
-
440
- assert.isTrue(Optional.isNone(invalid));
441
- });
442
-
443
- test('should return None if input is None', () => {
444
- const result = Optional.flatMap(Optional.none, (_: never) =>
445
- Optional.some(42),
446
- );
447
-
448
- assert.isTrue(Optional.isNone(result));
449
- });
450
-
451
- test('should support chaining multiple flatMaps', () => {
452
- const parseNumber = (s: string): Optional<number> => {
453
- const n = Result.unwrapOkOr(Num.safeParseFloat(s), Number.NaN);
454
-
455
- return Number.isNaN(n) ? Optional.none : Optional.some(n);
456
- };
457
-
458
- const divideBy =
459
- (divisor: number) =>
460
- (n: number): Optional<number> =>
461
- divisor === 0
462
- ? Optional.none
463
- : // eslint-disable-next-line total-functions/no-partial-division
464
- Optional.some(n / divisor);
465
-
466
- const intermediate = Optional.flatMap(Optional.some('100'), parseNumber);
467
-
468
- const result = Optional.flatMap(intermediate, divideBy(2));
469
-
470
- if (Optional.isSome(result)) {
471
- expect(Optional.unwrap(result)).toBe(50);
472
- }
473
- });
474
-
475
- test('should support curried form', () => {
476
- const parseNumber = (s: string): Optional<number> => {
477
- const n = Result.unwrapOkOr(Num.safeParseFloat(s), Number.NaN);
478
-
479
- return Number.isNaN(n) ? Optional.none : Optional.some(n);
480
- };
481
-
482
- const parser = Optional.flatMap(parseNumber);
483
-
484
- const result = parser(Optional.some('42'));
485
-
486
- assert.isTrue(Optional.isSome(result));
487
-
488
- if (Optional.isSome(result)) {
489
- expect(Optional.unwrap(result)).toBe(42);
490
- }
491
-
492
- const invalid = parser(Optional.some('abc'));
493
-
494
- assert.isTrue(Optional.isNone(invalid));
495
-
496
- const noneResult = parser(Optional.none);
497
-
498
- assert.isTrue(Optional.isNone(noneResult));
499
- });
500
-
501
- test('should work with pipe when curried', () => {
502
- const parseNumber = (s: string): Optional<number> => {
503
- const n = Result.unwrapOkOr(Num.safeParseFloat(s), Number.NaN);
504
-
505
- return Number.isNaN(n) ? Optional.none : Optional.some(n);
506
- };
507
-
508
- const doubleIfPositive = (n: number): Optional<number> =>
509
- n > 0 ? Optional.some(n * 2) : Optional.none;
510
-
511
- const parser = Optional.flatMap(parseNumber);
512
-
513
- const doubler = Optional.flatMap(doubleIfPositive);
514
-
515
- const result = pipe(Optional.some('42')).map(parser).map(doubler).value;
516
-
517
- assert.isTrue(Optional.isSome(result));
518
-
519
- if (Optional.isSome(result)) {
520
- expect(Optional.unwrap(result)).toBe(84);
521
- }
522
- });
523
- });
524
-
525
- describe('filter', () => {
526
- test('should keep Some values that match predicate', () => {
527
- const someEven = Optional.some(4);
528
-
529
- const filtered = Optional.filter(someEven, (x) => x % 2 === 0);
530
-
531
- if (Optional.isSome(filtered)) {
532
- expect(Optional.unwrap(filtered)).toBe(4);
533
- }
534
- });
535
-
536
- test('should return None for Some values that do not match predicate', () => {
537
- const someOdd = Optional.some(5);
538
-
539
- const filtered = Optional.filter(someOdd, (x) => x % 2 === 0);
540
-
541
- assert.isTrue(Optional.isNone(filtered));
542
- });
543
-
544
- test('should return None if input is None', () => {
545
- const filtered = Optional.filter(Optional.none, (_: never) => true);
546
-
547
- assert.isTrue(Optional.isNone(filtered));
548
- });
549
-
550
- test('should support curried form', () => {
551
- const evenFilter = Optional.filter((x: number) => x % 2 === 0);
552
-
553
- const someEven = Optional.some(4);
554
-
555
- const filtered = evenFilter(someEven);
556
-
557
- assert.isTrue(Optional.isSome(filtered));
558
-
559
- if (Optional.isSome(filtered)) {
560
- expect(Optional.unwrap(filtered)).toBe(4);
561
- }
562
-
563
- const someOdd = Optional.some(5);
564
-
565
- const filteredOdd = evenFilter(someOdd);
566
-
567
- assert.isTrue(Optional.isNone(filteredOdd));
568
-
569
- const noneResult = evenFilter(Optional.none);
570
-
571
- assert.isTrue(Optional.isNone(noneResult));
572
- });
573
-
574
- test('should work with pipe when curried', () => {
575
- const evenFilter = Optional.filter((x: number) => x % 2 === 0);
576
-
577
- const positiveFilter = Optional.filter((x: number) => x > 0);
578
-
579
- const result = pipe(Optional.some(4))
580
- .map(evenFilter)
581
- .map(positiveFilter).value;
582
-
583
- assert.isTrue(Optional.isSome(result));
584
-
585
- if (Optional.isSome(result)) {
586
- expect(Optional.unwrap(result)).toBe(4);
587
- }
588
-
589
- const filtered = pipe(Optional.some(3)).map(evenFilter).value;
590
-
591
- assert.isTrue(Optional.isNone(filtered));
592
- });
593
- });
594
-
595
- describe('orElse', () => {
596
- test('should return the first Optional if it is Some', () => {
597
- const primary = Optional.some(42);
598
-
599
- const fallback = Optional.some(100);
600
-
601
- const result = Optional.orElse(primary, fallback);
602
-
603
- if (Optional.isSome(result)) {
604
- expect(Optional.unwrap(result)).toBe(42);
605
- }
606
- });
607
-
608
- test('should return the alternative if the first is None', () => {
609
- const primary = Optional.none;
610
-
611
- const fallback = Optional.some('default');
612
-
613
- const result = Optional.orElse(primary, fallback);
614
-
615
- if (Optional.isSome(result)) {
616
- expect(Optional.unwrap(result)).toBe('default');
617
- }
618
- });
619
-
620
- test('should return None if both are None', () => {
621
- const result = Optional.orElse(Optional.none, Optional.none);
622
-
623
- assert.isTrue(Optional.isNone(result));
624
- });
625
-
626
- test('should support curried form', () => {
627
- const fallbackTo = Optional.orElse(Optional.some('fallback'));
628
-
629
- const someValue = Optional.some('primary');
630
-
631
- const result = fallbackTo(someValue);
632
-
633
- assert.isTrue(Optional.isSome(result));
634
-
635
- if (Optional.isSome(result)) {
636
- expect(Optional.unwrap(result)).toBe('primary');
637
- }
638
-
639
- const noneValue = Optional.none;
640
-
641
- const fallbackResult = fallbackTo(noneValue);
642
-
643
- assert.isTrue(Optional.isSome(fallbackResult));
644
-
645
- if (Optional.isSome(fallbackResult)) {
646
- expect(Optional.unwrap(fallbackResult)).toBe('fallback');
647
- }
648
- });
649
-
650
- test('should work with pipe when curried', () => {
651
- const fallbackTo = Optional.orElse(Optional.some('backup'));
652
-
653
- const someResult = pipe(Optional.some('original')).map(fallbackTo).value;
654
-
655
- assert.isTrue(Optional.isSome(someResult));
656
-
657
- if (Optional.isSome(someResult)) {
658
- expect(Optional.unwrap(someResult)).toBe('original');
659
- }
660
-
661
- const noneResult = pipe(Optional.none).map(fallbackTo).value;
662
-
663
- assert.isTrue(Optional.isSome(noneResult));
664
-
665
- if (Optional.isSome(noneResult)) {
666
- expect(Optional.unwrap(noneResult)).toBe('backup');
667
- }
668
- });
669
- });
670
-
671
- describe('zip', () => {
672
- test('should combine two Some values into a tuple', () => {
673
- const a = Optional.some(1);
674
-
675
- const b = Optional.some('hello');
676
-
677
- const zipped = Optional.zip(a, b);
678
-
679
- if (Optional.isSome(zipped)) {
680
- assert.deepStrictEqual(Optional.unwrap(zipped), [1, 'hello']);
681
- }
682
- });
683
-
684
- test('should return None if first is None', () => {
685
- const a = Optional.none;
686
-
687
- const b = Optional.some('hello');
688
-
689
- const zipped = Optional.zip(a, b);
690
-
691
- assert.isTrue(Optional.isNone(zipped));
692
- });
693
-
694
- test('should return None if second is None', () => {
695
- const a = Optional.some(1);
696
-
697
- const b = Optional.none;
698
-
699
- const zipped = Optional.zip(a, b);
700
-
701
- assert.isTrue(Optional.isNone(zipped));
702
- });
703
-
704
- test('should return None if both are None', () => {
705
- const zipped = Optional.zip(Optional.none, Optional.none);
706
-
707
- assert.isTrue(Optional.isNone(zipped));
708
- });
709
- });
710
-
711
- describe('fromNullable', () => {
712
- test('should convert non-null values to Some', () => {
713
- const helloOpt = Optional.fromNullable('hello');
714
-
715
- if (Optional.isSome(helloOpt))
716
- expect(Optional.unwrap(helloOpt)).toBe('hello');
717
-
718
- const numOpt = Optional.fromNullable(42);
719
-
720
- if (Optional.isSome(numOpt)) expect(Optional.unwrap(numOpt)).toBe(42);
721
-
722
- const zeroOpt = Optional.fromNullable(0);
723
-
724
- if (Optional.isSome(zeroOpt)) expect(Optional.unwrap(zeroOpt)).toBe(0);
725
-
726
- const emptyOpt = Optional.fromNullable('');
727
-
728
- if (Optional.isSome(emptyOpt)) expect(Optional.unwrap(emptyOpt)).toBe('');
729
-
730
- const falseOpt = Optional.fromNullable(false);
731
-
732
- if (Optional.isSome(falseOpt)) assert.isFalse(Optional.unwrap(falseOpt));
733
- });
734
-
735
- test('should convert null to None', () => {
736
- assert.isTrue(Optional.isNone(Optional.fromNullable(null)));
737
- });
738
-
739
- test('should convert undefined to None', () => {
740
- assert.isTrue(Optional.isNone(Optional.fromNullable(undefined)));
741
- });
742
-
743
- test('should work with union types', () => {
744
- const value: string | null = 'test';
745
-
746
- expectTypeOf(Optional.fromNullable(value)).toExtend<Optional<string>>();
747
- });
748
- });
749
-
750
- describe('toNullable', () => {
751
- test('should convert Some to its value', () => {
752
- expect(Optional.toNullable(Optional.some(42))).toBe(42);
753
-
754
- expect(Optional.toNullable(Optional.some('hello'))).toBe('hello');
755
-
756
- expect(Optional.toNullable(Optional.some(null))).toBeNull();
757
- });
758
-
759
- test('should convert None to null', () => {
760
- // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
761
- expect(Optional.toNullable(Optional.none)).toBeUndefined();
762
- });
763
-
764
- test('should have correct return type', () => {
765
- const some = Optional.some(42);
766
-
767
- expectTypeOf(Optional.toNullable(some)).toExtend<number | undefined>();
768
- });
769
- });
770
-
771
- describe('edge cases', () => {
772
- test('should handle undefined as a Some value', () => {
773
- const someUndefined = Optional.some(undefined);
774
-
775
- assert.isTrue(Optional.isSome(someUndefined));
776
-
777
- // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
778
- expect(Optional.unwrap(someUndefined)).toBeUndefined();
779
-
780
- // This is different from None
781
- expect(someUndefined).not.toBe(Optional.none);
782
- });
783
-
784
- test('should handle null as a Some value', () => {
785
- const someNull = Optional.some(null);
786
-
787
- assert.isTrue(Optional.isSome(someNull));
788
-
789
- expect(Optional.unwrap(someNull)).toBeNull();
790
- });
791
-
792
- test('should handle nested Optionals', () => {
793
- const nested = Optional.some(Optional.some(42));
794
-
795
- assert.isTrue(Optional.isSome(nested));
796
-
797
- const inner = Optional.unwrap(nested);
798
-
799
- assert.isTrue(Optional.isOptional(inner));
800
-
801
- expect(Optional.unwrap(inner)).toBe(42);
802
- });
803
- });
804
-
805
- describe('match', () => {
806
- test('should apply the some case for Some', () => {
807
- const result = Optional.match(Optional.some(21), {
808
- some: (value) => value * 2,
809
- none: () => 0,
810
- });
811
-
812
- expectType<typeof result, number>('=');
813
-
814
- assert.deepStrictEqual(result, 42);
815
- });
816
-
817
- test('should apply the none case for None', () => {
818
- const result = Optional.match(Optional.none, {
819
- some: () => 'some',
820
- none: () => 'none',
821
- });
822
-
823
- assert.deepStrictEqual(result, 'none');
824
- });
825
-
826
- test('should support Optional union inputs', () => {
827
- const optional: Optional<number> = Optional.some(3);
828
-
829
- const result = Optional.match(optional, {
830
- some: (value) => `value: ${value}`,
831
- none: () => 'none',
832
- });
833
-
834
- expectType<typeof result, string>('=');
835
-
836
- assert.deepStrictEqual(result, 'value: 3');
837
- });
838
-
839
- test('curried version should work', () => {
840
- const matcher = Optional.match({
841
- some: (value: number) => `value: ${value}`,
842
- none: () => 'none',
843
- });
844
-
845
- const result = matcher(Optional.some(3));
846
-
847
- expectType<typeof result, string>('=');
848
-
849
- assert.deepStrictEqual(result, 'value: 3');
850
-
851
- assert.deepStrictEqual(matcher(Optional.none), 'none');
852
- });
853
-
854
- test('curried version should compose with Array.map and pipe', () => {
855
- const matcher = Optional.match({
856
- some: (value: number) => `some:${value}`,
857
- none: () => 'none',
858
- });
859
-
860
- const optionals: readonly Optional<number>[] = [
861
- Optional.some(1),
862
- Optional.none,
863
- ] as const;
864
-
865
- assert.deepStrictEqual(optionals.map(matcher), ['some:1', 'none']);
866
-
867
- const single: Optional<number> = Optional.some(3);
868
-
869
- assert.deepStrictEqual(pipe(single).map(matcher).value, 'some:3');
870
- });
871
-
872
- test('should apply the some case for Some(undefined)', () => {
873
- const makeOptional = (): Optional<undefined> => Optional.some(undefined);
874
-
875
- const result = Optional.match(makeOptional(), {
876
- some: (value) => `some: ${unknownToString(value)}`,
877
- none: () => 'none',
878
- });
879
-
880
- assert.deepStrictEqual(result, 'some: undefined');
881
- });
882
- });
883
- });