@nicolastoulemont/std 0.6.0 → 0.7.0

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 (198) hide show
  1. package/README.md +232 -27
  2. package/dist/adt/index.d.mts +2 -2
  3. package/dist/adt/index.mjs +1 -1
  4. package/dist/adt-DajUZvJe.mjs +2 -0
  5. package/dist/adt-DajUZvJe.mjs.map +1 -0
  6. package/dist/brand/index.d.mts +2 -2
  7. package/dist/brand/index.mjs +1 -1
  8. package/dist/brand-Bia3Vj6l.mjs +2 -0
  9. package/dist/brand-Bia3Vj6l.mjs.map +1 -0
  10. package/dist/context/index.d.mts +2 -0
  11. package/dist/context/index.mjs +1 -0
  12. package/dist/context-CCHj1nab.mjs +2 -0
  13. package/dist/context-CCHj1nab.mjs.map +1 -0
  14. package/dist/context-r8ESJiFn.d.mts +176 -0
  15. package/dist/context-r8ESJiFn.d.mts.map +1 -0
  16. package/dist/data/index.d.mts +2 -2
  17. package/dist/data/index.mjs +1 -1
  18. package/dist/data-CJxw6al9.mjs +2 -0
  19. package/dist/data-CJxw6al9.mjs.map +1 -0
  20. package/dist/data.tagged-error.types-CLlJJ3n5.d.mts +50 -0
  21. package/dist/data.tagged-error.types-CLlJJ3n5.d.mts.map +1 -0
  22. package/dist/{discriminator.types-9PxvrZki.d.mts → discriminator.types-CTURejXz.d.mts} +1 -1
  23. package/dist/discriminator.types-CTURejXz.d.mts.map +1 -0
  24. package/dist/dual-CZhzZslG.mjs +2 -0
  25. package/dist/dual-CZhzZslG.mjs.map +1 -0
  26. package/dist/either/index.d.mts +2 -2
  27. package/dist/either/index.mjs +1 -1
  28. package/dist/either-6BwadiFj.mjs +2 -0
  29. package/dist/either-6BwadiFj.mjs.map +1 -0
  30. package/dist/{equality-CD4_A1Op.mjs → equality-CoyUHWh9.mjs} +1 -1
  31. package/dist/{equality-CD4_A1Op.mjs.map → equality-CoyUHWh9.mjs.map} +1 -1
  32. package/dist/{flow-CYjiodlC.mjs → flow-D8_tllWl.mjs} +1 -1
  33. package/dist/flow-D8_tllWl.mjs.map +1 -0
  34. package/dist/functions/index.d.mts +2 -0
  35. package/dist/functions/index.mjs +1 -0
  36. package/dist/functions-BkevX2Dw.mjs +2 -0
  37. package/dist/functions-BkevX2Dw.mjs.map +1 -0
  38. package/dist/fx/index.d.mts +2 -3
  39. package/dist/fx/index.mjs +1 -1
  40. package/dist/fx-BzxLbf1Q.mjs +2 -0
  41. package/dist/fx-BzxLbf1Q.mjs.map +1 -0
  42. package/dist/fx.runtime-BcC6yMSy.mjs +2 -0
  43. package/dist/fx.runtime-BcC6yMSy.mjs.map +1 -0
  44. package/dist/{fx.types-CDVjDn_3.mjs → fx.types-Bg-Mmdm5.mjs} +1 -1
  45. package/dist/fx.types-Bg-Mmdm5.mjs.map +1 -0
  46. package/dist/{fx.types-B34asVRX.d.mts → fx.types-DeEWEltG.d.mts} +2 -2
  47. package/dist/{fx.types-B34asVRX.d.mts.map → fx.types-DeEWEltG.d.mts.map} +1 -1
  48. package/dist/index-7Lv982Om.d.mts +217 -0
  49. package/dist/index-7Lv982Om.d.mts.map +1 -0
  50. package/dist/index-B_iY5tq0.d.mts +241 -0
  51. package/dist/index-B_iY5tq0.d.mts.map +1 -0
  52. package/dist/index-B_wWGszy.d.mts +129 -0
  53. package/dist/index-B_wWGszy.d.mts.map +1 -0
  54. package/dist/index-BiiE8NS7.d.mts +108 -0
  55. package/dist/index-BiiE8NS7.d.mts.map +1 -0
  56. package/dist/index-By6dNRc4.d.mts +277 -0
  57. package/dist/index-By6dNRc4.d.mts.map +1 -0
  58. package/dist/index-CCo85AdC.d.mts +121 -0
  59. package/dist/index-CCo85AdC.d.mts.map +1 -0
  60. package/dist/index-CUZn-ohG.d.mts +490 -0
  61. package/dist/index-CUZn-ohG.d.mts.map +1 -0
  62. package/dist/index-CugDqdx6.d.mts +464 -0
  63. package/dist/index-CugDqdx6.d.mts.map +1 -0
  64. package/dist/{index-B2l8_CiD.d.mts → index-DEAWPlcI.d.mts} +155 -216
  65. package/dist/index-DEAWPlcI.d.mts.map +1 -0
  66. package/dist/{index-C4v_3f3-.d.mts → index-DKS1g1oC.d.mts} +95 -42
  67. package/dist/index-DKS1g1oC.d.mts.map +1 -0
  68. package/dist/{index-CklRfom5.d.mts → index-DSsDFLGw.d.mts} +263 -368
  69. package/dist/index-DSsDFLGw.d.mts.map +1 -0
  70. package/dist/{index-jeC5jyRh.d.mts → index-DXbYlSnB.d.mts} +64 -101
  71. package/dist/index-DXbYlSnB.d.mts.map +1 -0
  72. package/dist/{index-BzYtgdX0.d.mts → index-DaTvFhZ8.d.mts} +123 -16
  73. package/dist/index-DaTvFhZ8.d.mts.map +1 -0
  74. package/dist/{index-CjZ95Dsv.d.mts → index-Dm2dFysv.d.mts} +188 -202
  75. package/dist/index-Dm2dFysv.d.mts.map +1 -0
  76. package/dist/index.d.mts +23 -16
  77. package/dist/index.mjs +1 -1
  78. package/dist/layer/index.d.mts +2 -0
  79. package/dist/layer/index.mjs +1 -0
  80. package/dist/layer-BttmtDrs.mjs +2 -0
  81. package/dist/layer-BttmtDrs.mjs.map +1 -0
  82. package/dist/layer.types-DgpCIsk_.d.mts +100 -0
  83. package/dist/layer.types-DgpCIsk_.d.mts.map +1 -0
  84. package/dist/multithread/index.d.mts +2 -0
  85. package/dist/multithread/index.mjs +1 -0
  86. package/dist/multithread-xUUh4eLn.mjs +19 -0
  87. package/dist/multithread-xUUh4eLn.mjs.map +1 -0
  88. package/dist/option/index.d.mts +2 -3
  89. package/dist/option/index.mjs +1 -1
  90. package/dist/option-Qt1H-u7c.mjs +2 -0
  91. package/dist/option-Qt1H-u7c.mjs.map +1 -0
  92. package/dist/option.types-DRUm2QiI.mjs +2 -0
  93. package/dist/option.types-DRUm2QiI.mjs.map +1 -0
  94. package/dist/{option.types-ClJiBTdg.d.mts → option.types-DlAb6Sr0.d.mts} +4 -4
  95. package/dist/option.types-DlAb6Sr0.d.mts.map +1 -0
  96. package/dist/order/index.d.mts +2 -0
  97. package/dist/order/index.mjs +1 -0
  98. package/dist/order-D5c4QChk.mjs +2 -0
  99. package/dist/order-D5c4QChk.mjs.map +1 -0
  100. package/dist/pipeable-COGyGMUV.mjs +2 -0
  101. package/dist/pipeable-COGyGMUV.mjs.map +1 -0
  102. package/dist/{pipeable-B4YJA56p.d.mts → pipeable-rfqacPxZ.d.mts} +2 -9
  103. package/dist/{pipeable-B4YJA56p.d.mts.map → pipeable-rfqacPxZ.d.mts.map} +1 -1
  104. package/dist/predicate/index.d.mts +2 -2
  105. package/dist/predicate/index.mjs +1 -1
  106. package/dist/predicate-DUhhQqWY.mjs +2 -0
  107. package/dist/predicate-DUhhQqWY.mjs.map +1 -0
  108. package/dist/provide/index.d.mts +2 -0
  109. package/dist/provide/index.mjs +1 -0
  110. package/dist/provide-B_SqJpCd.mjs +2 -0
  111. package/dist/provide-B_SqJpCd.mjs.map +1 -0
  112. package/dist/queue/index.d.mts +2 -0
  113. package/dist/queue/index.mjs +1 -0
  114. package/dist/queue-CG5izEBS.mjs +2 -0
  115. package/dist/queue-CG5izEBS.mjs.map +1 -0
  116. package/dist/queue.types-CD2LOu37.d.mts +36 -0
  117. package/dist/queue.types-CD2LOu37.d.mts.map +1 -0
  118. package/dist/result/index.d.mts +2 -3
  119. package/dist/result/index.mjs +1 -1
  120. package/dist/result-BEzV0DYC.mjs +2 -0
  121. package/dist/result-BEzV0DYC.mjs.map +1 -0
  122. package/dist/{result.types-HHDzgSTV.d.mts → result.types-_xDAei3-.d.mts} +5 -97
  123. package/dist/result.types-_xDAei3-.d.mts.map +1 -0
  124. package/dist/schedule/index.d.mts +2 -0
  125. package/dist/schedule/index.mjs +1 -0
  126. package/dist/schedule-C6tjcJ1O.mjs +2 -0
  127. package/dist/schedule-C6tjcJ1O.mjs.map +1 -0
  128. package/dist/schedule-DlX2Dg69.d.mts +144 -0
  129. package/dist/schedule-DlX2Dg69.d.mts.map +1 -0
  130. package/dist/scope/index.d.mts +2 -0
  131. package/dist/scope/index.mjs +1 -0
  132. package/dist/scope-CZdp4wKX.d.mts +79 -0
  133. package/dist/scope-CZdp4wKX.d.mts.map +1 -0
  134. package/dist/scope-qwL1VUh2.mjs +2 -0
  135. package/dist/scope-qwL1VUh2.mjs.map +1 -0
  136. package/dist/service/index.d.mts +2 -0
  137. package/dist/service/index.mjs +1 -0
  138. package/dist/service-3PYQTUdH.mjs +2 -0
  139. package/dist/service-3PYQTUdH.mjs.map +1 -0
  140. package/dist/service-DrXU7KJG.d.mts +69 -0
  141. package/dist/service-DrXU7KJG.d.mts.map +1 -0
  142. package/dist/service-resolution-C19smeaO.mjs +2 -0
  143. package/dist/service-resolution-C19smeaO.mjs.map +1 -0
  144. package/package.json +50 -12
  145. package/dist/adt-CkRcY_GA.mjs +0 -2
  146. package/dist/adt-CkRcY_GA.mjs.map +0 -1
  147. package/dist/apply-fn.types-0g_9eXRy.d.mts +0 -8
  148. package/dist/apply-fn.types-0g_9eXRy.d.mts.map +0 -1
  149. package/dist/brand-Gy0kW6-n.mjs +0 -2
  150. package/dist/brand-Gy0kW6-n.mjs.map +0 -1
  151. package/dist/data-C0_3MGwm.mjs +0 -2
  152. package/dist/data-C0_3MGwm.mjs.map +0 -1
  153. package/dist/discriminator.types-9PxvrZki.d.mts.map +0 -1
  154. package/dist/either-CPzK-s8W.mjs +0 -2
  155. package/dist/either-CPzK-s8W.mjs.map +0 -1
  156. package/dist/err/index.d.mts +0 -2
  157. package/dist/err/index.mjs +0 -1
  158. package/dist/err-3KpQ4pj9.mjs +0 -2
  159. package/dist/err-3KpQ4pj9.mjs.map +0 -1
  160. package/dist/flow/index.d.mts +0 -2
  161. package/dist/flow/index.mjs +0 -1
  162. package/dist/flow-CYjiodlC.mjs.map +0 -1
  163. package/dist/fx-vqywVJhV.mjs +0 -2
  164. package/dist/fx-vqywVJhV.mjs.map +0 -1
  165. package/dist/fx.types-CDVjDn_3.mjs.map +0 -1
  166. package/dist/index-8Ne4GdOG.d.mts +0 -288
  167. package/dist/index-8Ne4GdOG.d.mts.map +0 -1
  168. package/dist/index-B2l8_CiD.d.mts.map +0 -1
  169. package/dist/index-BOrJQBPO.d.mts +0 -80
  170. package/dist/index-BOrJQBPO.d.mts.map +0 -1
  171. package/dist/index-BsXtpnw-.d.mts +0 -225
  172. package/dist/index-BsXtpnw-.d.mts.map +0 -1
  173. package/dist/index-BzYtgdX0.d.mts.map +0 -1
  174. package/dist/index-C4v_3f3-.d.mts.map +0 -1
  175. package/dist/index-CjZ95Dsv.d.mts.map +0 -1
  176. package/dist/index-CklRfom5.d.mts.map +0 -1
  177. package/dist/index-DZdmFtjA.d.mts +0 -79
  178. package/dist/index-DZdmFtjA.d.mts.map +0 -1
  179. package/dist/index-a4MEBZZ1.d.mts +0 -850
  180. package/dist/index-a4MEBZZ1.d.mts.map +0 -1
  181. package/dist/index-jeC5jyRh.d.mts.map +0 -1
  182. package/dist/option-DawZC1cE.mjs +0 -2
  183. package/dist/option-DawZC1cE.mjs.map +0 -1
  184. package/dist/option.types-ClJiBTdg.d.mts.map +0 -1
  185. package/dist/pipe/index.d.mts +0 -2
  186. package/dist/pipe/index.mjs +0 -1
  187. package/dist/pipe-BPpJyZf7.mjs +0 -2
  188. package/dist/pipe-BPpJyZf7.mjs.map +0 -1
  189. package/dist/pipeable-BA0mXhs4.mjs +0 -2
  190. package/dist/pipeable-BA0mXhs4.mjs.map +0 -1
  191. package/dist/predicate-Cy_oHA1Q.mjs +0 -2
  192. package/dist/predicate-Cy_oHA1Q.mjs.map +0 -1
  193. package/dist/result-CgGYLp0L.mjs +0 -2
  194. package/dist/result-CgGYLp0L.mjs.map +0 -1
  195. package/dist/result.types-HHDzgSTV.d.mts.map +0 -1
  196. /package/dist/{chunk-DAexk1S7.mjs → chunk-C934ptG5.mjs} +0 -0
  197. /package/dist/{option-Bb-taghv.mjs → option-CBCwzF0L.mjs} +0 -0
  198. /package/dist/{result-fiJhwVGz.mjs → result-B5WbPg8C.mjs} +0 -0
@@ -1,7 +1,22 @@
1
- import { a as ResultFromTry, c as ResultMatch, d as ResultUnwrapOr, f as ResultUnwrapOrElse, i as ResultFlatMap, l as ResultOrElse, n as ResultAll, o as ResultMap, r as ResultFilter, s as ResultMapErr, t as Result$1, u as ResultTap } from "./result.types-HHDzgSTV.mjs";
1
+ import { a as ResultFromTry, c as ResultMatch, d as ResultUnwrapOr, f as ResultUnwrapOrElse, i as ResultFlatMap, l as ResultOrElse, n as ResultAll, o as ResultMap, r as ResultFilter, s as ResultMapErr, t as Result$1, u as ResultTap } from "./result.types-_xDAei3-.mjs";
2
2
 
3
3
  //#region src/result/result.d.ts
4
-
4
+ declare namespace result_d_exports {
5
+ export { Result, all, err, filter, flatMap, fromTry, isErr, isOk, map, mapErr, match, ok, orElse, tap, try_ as try, unwrapOr, unwrapOrElse };
6
+ }
7
+ /**
8
+ * Re-exported `Result` type.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import type { Result } from "@nicolastoulemont/std"
13
+ *
14
+ * type Example = Result.Result<unknown, unknown>
15
+ * ```
16
+ *
17
+ * @category Re-exports
18
+ */
19
+ type Result<T, E> = Result$1<T, E>;
5
20
  /**
6
21
  * Create a successful Result.
7
22
  *
@@ -10,8 +25,13 @@ import { a as ResultFromTry, c as ResultMatch, d as ResultUnwrapOr, f as ResultU
10
25
  *
11
26
  * @example
12
27
  * ```ts
13
- * ok(42) // { _tag: "Ok", value: 42 }
28
+ * import { Result } from "@nicolastoulemont/std"
29
+ *
30
+ * const value = Result.ok(42)
31
+ * // => { _tag: "Ok", value: 42 }
14
32
  * ```
33
+ *
34
+ * @category Constructors
15
35
  */
16
36
  declare const ok: <T>(value: T) => Result$1<T, never>;
17
37
  /**
@@ -22,8 +42,13 @@ declare const ok: <T>(value: T) => Result$1<T, never>;
22
42
  *
23
43
  * @example
24
44
  * ```ts
25
- * err('something went wrong') // { _tag: "Err", error: 'something went wrong' }
45
+ * import { Result } from "@nicolastoulemont/std"
46
+ *
47
+ * const value = Result.err("boom")
48
+ * // => { _tag: "Err", error: "boom" }
26
49
  * ```
50
+ *
51
+ * @category Constructors
27
52
  */
28
53
  declare const err: <E>(error: E) => Result$1<never, E>;
29
54
  /**
@@ -34,11 +59,13 @@ declare const err: <E>(error: E) => Result$1<never, E>;
34
59
  *
35
60
  * @example
36
61
  * ```ts
37
- * const result = ok(42)
38
- * if (isOk(result)) {
39
- * console.log(result.value) // TypeScript knows value exists
40
- * }
62
+ * import { Result } from "@nicolastoulemont/std"
63
+ *
64
+ * const isOk = Result.isOk(Result.ok(1))
65
+ * // => true
41
66
  * ```
67
+ *
68
+ * @category Guards
42
69
  */
43
70
  declare const isOk: <T, E>(result: Result$1<T, E>) => result is Extract<Result$1<T, E>, {
44
71
  _tag: "Ok";
@@ -51,11 +78,13 @@ declare const isOk: <T, E>(result: Result$1<T, E>) => result is Extract<Result$1
51
78
  *
52
79
  * @example
53
80
  * ```ts
54
- * const result = err('oops')
55
- * if (isErr(result)) {
56
- * console.log(result.error) // TypeScript knows error exists
57
- * }
81
+ * import { Result } from "@nicolastoulemont/std"
82
+ *
83
+ * const isErr = Result.isErr(Result.err("boom"))
84
+ * // => true
58
85
  * ```
86
+ *
87
+ * @category Guards
59
88
  */
60
89
  declare const isErr: <T, E>(result: Result$1<T, E>) => result is Extract<Result$1<T, E>, {
61
90
  _tag: "Err";
@@ -77,21 +106,17 @@ declare const isErr: <T, E>(result: Result$1<T, E>) => result is Extract<Result$
77
106
  *
78
107
  * @example
79
108
  * ```ts
80
- * // Data-first (direct call)
81
- * map(ok(5), n => n * 2) // { _tag: "Ok", value: 10 }
82
- *
83
- * // Data-last (curried for pipe)
84
- * pipe(
85
- * ok(5),
86
- * map(n => n * 2)
87
- * ) // { _tag: "Ok", value: 10 }
88
- *
89
- * // Async usage
90
- * await pipe(
91
- * ok(userId),
92
- * map(async id => await fetchName(id))
93
- * ) // Promise<Result<string, E>>
109
+ * import { Result } from "@nicolastoulemont/std"
110
+ *
111
+ * const input = Result.ok(2)
112
+ * const dataFirst = Result.map(input, (n) => n + 1)
113
+ * // => { _tag: "Ok", value: 3 }
114
+ *
115
+ * const dataLast = Result.map((n: number) => n + 1)(input)
116
+ * // => { _tag: "Ok", value: 3 }
94
117
  * ```
118
+ *
119
+ * @category Mapping
95
120
  */
96
121
  declare const map: ResultMap;
97
122
  /**
@@ -111,22 +136,17 @@ declare const map: ResultMap;
111
136
  *
112
137
  * @example
113
138
  * ```ts
114
- * // Data-first (direct call)
115
- * mapErr(err({ code: 404 }), e => `Error: ${e.code}`)
116
- * // { _tag: "Err", error: 'Error: 404' }
117
- *
118
- * // Data-last (curried for pipe)
119
- * pipe(
120
- * err({ code: 404 }),
121
- * mapErr(e => `Error: ${e.code}`)
122
- * ) // { _tag: "Err", error: 'Error: 404' }
123
- *
124
- * // Async usage
125
- * await pipe(
126
- * err(errorCode),
127
- * mapErr(async code => await translateError(code))
128
- * ) // Promise<Result<T, string>>
139
+ * import { Result } from "@nicolastoulemont/std"
140
+ *
141
+ * const input = Result.err("missing")
142
+ * const dataFirst = Result.mapErr(input, (msg) => msg.toUpperCase())
143
+ * // => { _tag: "Err", error: "MISSING" }
144
+ *
145
+ * const dataLast = Result.mapErr((msg: string) => msg.toUpperCase())(input)
146
+ * // => { _tag: "Err", error: "MISSING" }
129
147
  * ```
148
+ *
149
+ * @category Mapping
130
150
  */
131
151
  declare const mapErr: ResultMapErr;
132
152
  /**
@@ -146,24 +166,17 @@ declare const mapErr: ResultMapErr;
146
166
  *
147
167
  * @example
148
168
  * ```ts
149
- * const divide = (a: number, b: number) =>
150
- * b === 0 ? err('division by zero') : ok(a / b)
151
- *
152
- * // Data-first (direct call)
153
- * flatMap(ok(10), n => divide(n, 2)) // { _tag: "Ok", value: 5 }
154
- *
155
- * // Data-last (curried for pipe)
156
- * pipe(
157
- * ok(10),
158
- * flatMap(n => divide(n, 2))
159
- * ) // { _tag: "Ok", value: 5 }
160
- *
161
- * // Async usage
162
- * await pipe(
163
- * ok(userId),
164
- * flatMap(async id => ok(await fetchUser(id)))
165
- * ) // Promise<Result<User, E>>
169
+ * import { Result } from "@nicolastoulemont/std"
170
+ *
171
+ * const input = Result.ok(2)
172
+ * const dataFirst = Result.flatMap(input, (n) => Result.ok(n + 1))
173
+ * // => { _tag: "Ok", value: 3 }
174
+ *
175
+ * const dataLast = Result.flatMap((n: number) => Result.ok(n + 1))(input)
176
+ * // => { _tag: "Ok", value: 3 }
166
177
  * ```
178
+ *
179
+ * @category Sequencing
167
180
  */
168
181
  declare const flatMap: ResultFlatMap;
169
182
  /**
@@ -184,23 +197,22 @@ declare const flatMap: ResultFlatMap;
184
197
  *
185
198
  * @example
186
199
  * ```ts
187
- * // Data-first (direct call)
188
- * tap(ok(42), console.log) // logs 42, returns { _tag: "Ok", value: 42 }
189
- *
190
- * // Data-last (curried for pipe)
191
- * pipe(
192
- * ok(42),
193
- * tap(console.log), // logs 42
194
- * map(n => n * 2)
195
- * ) // { _tag: "Ok", value: 84 }
196
- *
197
- * // Async usage
198
- * await pipe(
199
- * ok(42),
200
- * tap(async v => await logToServer(v)),
201
- * map(n => n * 2)
202
- * ) // Promise<Result<84, E>>
200
+ * import { Result } from "@nicolastoulemont/std"
201
+ *
202
+ * let seen = 0
203
+ * const input = Result.ok(2)
204
+ * const dataFirst = Result.tap(input, (n) => {
205
+ * seen = n
206
+ * })
207
+ * // => { _tag: "Ok", value: 2 }
208
+ *
209
+ * const dataLast = Result.tap((n: number) => {
210
+ * seen = n
211
+ * })(input)
212
+ * // => { _tag: "Ok", value: 2 }
203
213
  * ```
214
+ *
215
+ * @category Sequencing
204
216
  */
205
217
  declare const tap: ResultTap;
206
218
  /**
@@ -220,30 +232,17 @@ declare const tap: ResultTap;
220
232
  *
221
233
  * @example
222
234
  * ```ts
223
- * // Data-first (direct call)
224
- * orElse(err('cache miss'), () => ok(defaultValue))
225
- * // { _tag: "Ok", value: defaultValue }
226
- *
227
- * // Data-last (curried for pipe)
228
- * pipe(
229
- * err('cache miss'),
230
- * orElse(() => ok(defaultValue))
231
- * ) // { _tag: "Ok", value: defaultValue }
232
- *
233
- * // Async recovery
234
- * await pipe(
235
- * err('cache miss'),
236
- * orElse(async () => ok(await fetchFromAPI()))
237
- * ) // Promise<Result<T, E2>>
238
- *
239
- * // Chain multiple fallbacks
240
- * pipe(
241
- * err('not found'),
242
- * orElse(() => tryCache()),
243
- * orElse(() => tryAPI()),
244
- * orElse(() => ok(fallback))
245
- * )
235
+ * import { Result } from "@nicolastoulemont/std"
236
+ *
237
+ * const input = Result.err("missing") as Result.Result<number, string>
238
+ * const dataFirst = Result.orElse(input, () => Result.ok(0))
239
+ * // => { _tag: "Ok", value: 0 }
240
+ *
241
+ * const dataLast = Result.orElse(() => Result.ok(0))(input)
242
+ * // => { _tag: "Ok", value: 0 }
246
243
  * ```
244
+ *
245
+ * @category Error Handling
247
246
  */
248
247
  declare const orElse: ResultOrElse;
249
248
  /**
@@ -261,27 +260,17 @@ declare const orElse: ResultOrElse;
261
260
  *
262
261
  * @example
263
262
  * ```ts
264
- * // Data-first (direct call)
265
- * filter(ok(5), n => n > 10, n => `${n} is too small`)
266
- * // { _tag: "Err", error: '5 is too small' }
267
- *
268
- * // Data-last (curried for pipe)
269
- * pipe(
270
- * ok(5),
271
- * filter(n => n > 10, n => `${n} is too small`)
272
- * ) // { _tag: "Err", error: '5 is too small' }
273
- *
274
- * pipe(
275
- * ok(15),
276
- * filter(n => n > 10, n => `${n} is too small`)
277
- * ) // { _tag: "Ok", value: 15 }
278
- *
279
- * // With complex validation
280
- * pipe(
281
- * ok(user),
282
- * filter(u => u.age >= 18, u => ({ code: 'UNDERAGE', user: u }))
283
- * )
263
+ * import { Result } from "@nicolastoulemont/std"
264
+ *
265
+ * const input = Result.ok(3)
266
+ * const dataFirst = Result.filter(input, (n) => n > 0, (n) => `${n} must be positive`)
267
+ * // => { _tag: "Ok", value: 3 }
268
+ *
269
+ * const dataLast = Result.filter((n: number) => n > 0, (n) => `${n} must be positive`)(input)
270
+ * // => { _tag: "Ok", value: 3 }
284
271
  * ```
272
+ *
273
+ * @category Filtering
285
274
  */
286
275
  declare const filter: ResultFilter;
287
276
  /**
@@ -296,18 +285,13 @@ declare const filter: ResultFilter;
296
285
  *
297
286
  * @example
298
287
  * ```ts
299
- * // Array form - tuple types inferred automatically for up to 6 elements
300
- * const [num, str] = pipe(
301
- * Result.all([parseNumber(input), parseString(other)]),
302
- * Result.unwrapOr([0, ''])
303
- * )
304
- *
305
- * // Object form - returns Result<{ user: User, config: Config }, E>
306
- * pipe(
307
- * Result.all({ user: fetchUser(id), config: loadConfig() }),
308
- * Result.tap(({ user, config }) => console.log(user.name, config.theme))
309
- * )
288
+ * import { Result } from "@nicolastoulemont/std"
289
+ *
290
+ * const combined = Result.all([Result.ok(1), Result.ok(2)] as const)
291
+ * // => { _tag: "Ok", value: [1, 2] }
310
292
  * ```
293
+ *
294
+ * @category Combining
311
295
  */
312
296
  declare const all: ResultAll;
313
297
  /**
@@ -324,14 +308,17 @@ declare const all: ResultAll;
324
308
  *
325
309
  * @example
326
310
  * ```ts
327
- * // Data-first (direct call)
328
- * unwrapOr(ok(42), 0) // 42
329
- * unwrapOr(err('oops'), 0) // 0
311
+ * import { Result } from "@nicolastoulemont/std"
312
+ *
313
+ * const input = Result.err("missing") as Result.Result<number, string>
314
+ * const dataFirst = Result.unwrapOr(input, 0)
315
+ * // => 0
330
316
  *
331
- * // Data-last (curried for pipe)
332
- * pipe(ok(42), unwrapOr(0)) // 42
333
- * pipe(err('oops'), unwrapOr(0)) // 0
317
+ * const dataLast = Result.unwrapOr(0)(input)
318
+ * // => 0
334
319
  * ```
320
+ *
321
+ * @category Getters
335
322
  */
336
323
  declare const unwrapOr: ResultUnwrapOr;
337
324
  /**
@@ -346,15 +333,17 @@ declare const unwrapOr: ResultUnwrapOr;
346
333
  *
347
334
  * @example
348
335
  * ```ts
349
- * // Data-first (direct call)
350
- * unwrapOrElse(err({ code: 404 }), e => `Error ${e.code}`) // 'Error 404'
351
- *
352
- * // Data-last (curried for pipe)
353
- * pipe(
354
- * err({ code: 404 }),
355
- * unwrapOrElse(e => `Error ${e.code}`)
356
- * ) // 'Error 404'
336
+ * import { Result } from "@nicolastoulemont/std"
337
+ *
338
+ * const input = Result.err("missing") as Result.Result<number, string>
339
+ * const dataFirst = Result.unwrapOrElse(input, () => 0)
340
+ * // => 0
341
+ *
342
+ * const dataLast = Result.unwrapOrElse(() => 0)(input)
343
+ * // => 0
357
344
  * ```
345
+ *
346
+ * @category Getters
358
347
  */
359
348
  declare const unwrapOrElse: ResultUnwrapOrElse;
360
349
  /**
@@ -369,21 +358,23 @@ declare const unwrapOrElse: ResultUnwrapOrElse;
369
358
  *
370
359
  * @example
371
360
  * ```ts
372
- * // Data-first (direct call)
373
- * match(ok(42), {
374
- * Ok: n => `Got ${n}`,
375
- * Err: e => `Error: ${e}`
376
- * }) // 'Got 42'
377
- *
378
- * // Data-last (curried for pipe)
379
- * pipe(
380
- * ok(42),
381
- * match({
382
- * Ok: n => `Got ${n}`,
383
- * Err: e => `Error: ${e}`
384
- * })
385
- * ) // 'Got 42'
361
+ * import { Result } from "@nicolastoulemont/std"
362
+ *
363
+ * const input = Result.ok(2) as Result.Result<number, string>
364
+ * const dataFirst = Result.match(input, {
365
+ * Ok: (value) => `ok:${value}` ,
366
+ * Err: (error) => `err:${error}` ,
367
+ * })
368
+ * // => "ok:2"
369
+ *
370
+ * const dataLast = Result.match({
371
+ * Ok: (value: number) => `ok:${value}` ,
372
+ * Err: (error: string) => `err:${error}` ,
373
+ * })(input)
374
+ * // => "ok:2"
386
375
  * ```
376
+ *
377
+ * @category Pattern Matching
387
378
  */
388
379
  declare const match: ResultMatch;
389
380
  /**
@@ -399,68 +390,16 @@ declare const match: ResultMatch;
399
390
  *
400
391
  * @example
401
392
  * ```ts
402
- * // Simple callback
403
- * fromTry(() => JSON.parse('{"valid": true}'))
404
- *
405
- * // Object form with custom error mapping
406
- * fromTry({
407
- * try: () => JSON.parse(input),
408
- * catch: (e) => ({ type: "ParseError" as const, message: String(e) })
409
- * })
393
+ * import { Result } from "@nicolastoulemont/std"
410
394
  *
411
- * // Async with custom catch
412
- * await fromTry({
413
- * try: () => fetch('/api/user'),
414
- * catch: (e) => new NetworkError(String(e))
415
- * })
395
+ * const parsed = Result.fromTry(() => Number.parseInt("42", 10))
396
+ * // => { _tag: "Ok", value: 42 }
416
397
  * ```
417
- */
418
- declare const fromTry: ResultFromTry;
419
- /**
420
- * Result namespace containing all utility functions for working with Result types.
421
- *
422
- * Result represents either success (`Ok`) or failure (`Err`). Use this for operations
423
- * that can fail with typed errors.
424
398
  *
425
- * @see {@link Option} for presence/absence semantics (no error information)
426
- * @see {@link Either} for two valid outcomes (not just success/failure)
427
- *
428
- * @example
429
- * ```ts
430
- * import { Result, pipe } from '@nicolastoulemont/std'
431
- * import type { Result as ResultType } from '@nicolastoulemont/std'
432
- *
433
- * const divide = (a: number, b: number): ResultType<number, string> =>
434
- * b === 0 ? Result.err('division by zero') : Result.ok(a / b)
435
- *
436
- * const result = pipe(
437
- * divide(10, 2),
438
- * Result.map(n => n * 2),
439
- * Result.unwrapOr(0)
440
- * )
441
- * ```
399
+ * @category Constructors
442
400
  */
443
- declare const Result: {
444
- readonly ok: <T>(value: T) => Result$1<T, never>;
445
- readonly err: <E>(error: E) => Result$1<never, E>;
446
- readonly isOk: <T, E>(result: Result$1<T, E>) => result is Extract<Result$1<T, E>, {
447
- _tag: "Ok";
448
- }>;
449
- readonly isErr: <T, E>(result: Result$1<T, E>) => result is Extract<Result$1<T, E>, {
450
- _tag: "Err";
451
- }>;
452
- readonly map: ResultMap;
453
- readonly mapErr: ResultMapErr;
454
- readonly flatMap: ResultFlatMap;
455
- readonly tap: ResultTap;
456
- readonly orElse: ResultOrElse;
457
- readonly filter: ResultFilter;
458
- readonly all: ResultAll;
459
- readonly unwrapOr: ResultUnwrapOr;
460
- readonly unwrapOrElse: ResultUnwrapOrElse;
461
- readonly match: ResultMatch;
462
- readonly try: ResultFromTry;
463
- };
401
+ declare const fromTry: ResultFromTry;
402
+ declare const try_: ResultFromTry;
464
403
  //#endregion
465
- export { flatMap as a, isOk as c, match as d, ok as f, unwrapOrElse as g, unwrapOr as h, filter as i, map as l, tap as m, all as n, fromTry as o, orElse as p, err as r, isErr as s, Result as t, mapErr as u };
466
- //# sourceMappingURL=index-B2l8_CiD.d.mts.map
404
+ export { result_d_exports as t };
405
+ //# sourceMappingURL=index-DEAWPlcI.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-DEAWPlcI.d.mts","names":[],"sources":["../src/result/result.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;KA4DY,eAAe,SAAW,GAAG;;;;;;;;;;AAAzC;;;;;AAwBA;;AAA4C,cAA/B,EAA+B,EAAA,CAAA,CAAA,CAAA,CAAA,KAAA,EAAf,CAAe,EAAA,GAAX,QAAW,CAAA,CAAA,EAAA,KAAA,CAAA;;;AAkC5C;;;;;AAsCA;;;;;;;;;AAmBa,cAzDA,GA0DU,EAAA,CAAA,CAAA,CAAA,CAAA,KAAA,EA1DO,CA0DP,EAAA,GA1DW,QA0DX,CAAA,KAAA,EA1D6B,CA0D7B,CAAA;;;;;;;;;AAoCvB;AAwCA;AAwCA;AAwCA;AAwCA;AA+BA;AAqCA;AAkDA;AA6Ba,cA3WA,IA8WZ,EAAA,CAAA,CAAA,EAH0B,CAAA,CAAA,CAAA,MAAA,EA3WQ,QA8WlC,CA9W6C,CA8W7C,EA9WgD,CA8WhD,CAAA,EAAA,GAAA,MAAA,IA9W+D,OA8W/D,CA9WuE,QA8WvE,CA9WkF,CA8WlF,EA9WqF,CA8WrF,CAAA,EAAA;EAgCY,IAAA,EAAA,IAIZ;AA4BD,CAAA,CAAA;AA0BC;;;;;;;;;;;;;;;;cArbY,sBAAuB,SAAW,GAAG,iBAAe,QAAQ,SAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqC1E,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwCL,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwCR,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwCT,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwCL,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+BR,QAAQ;;;;;;;;;;;;;;;;;;;;;cAqCR,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkDL,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;cA6BV,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmCd,OAAO;;;;;;;;;;;;;;;;;;;;;;cAgCP,SAAS;cA6BhB,MAAI"}