@nicolastoulemont/std 0.6.0 → 0.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 (198) hide show
  1. package/README.md +232 -33
  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-BLXO4XwS.mjs +2 -0
  19. package/dist/data-BLXO4XwS.mjs.map +1 -0
  20. package/dist/data.tagged-error.types-CGiKD-ES.d.mts +29 -0
  21. package/dist/data.tagged-error.types-CGiKD-ES.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-BMLPfvMl.mjs +2 -0
  29. package/dist/either-BMLPfvMl.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-K-a9Smhn.mjs +2 -0
  41. package/dist/fx-K-a9Smhn.mjs.map +1 -0
  42. package/dist/fx.runtime-DclEDyjY.mjs +2 -0
  43. package/dist/fx.runtime-DclEDyjY.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-CklRfom5.d.mts → index-B1-tBzc0.d.mts} +263 -368
  51. package/dist/index-B1-tBzc0.d.mts.map +1 -0
  52. package/dist/index-BNQ9xSAz.d.mts +464 -0
  53. package/dist/index-BNQ9xSAz.d.mts.map +1 -0
  54. package/dist/index-B_iY5tq0.d.mts +241 -0
  55. package/dist/index-B_iY5tq0.d.mts.map +1 -0
  56. package/dist/index-B_wWGszy.d.mts +129 -0
  57. package/dist/index-B_wWGszy.d.mts.map +1 -0
  58. package/dist/index-BiiE8NS7.d.mts +108 -0
  59. package/dist/index-BiiE8NS7.d.mts.map +1 -0
  60. package/dist/index-By6dNRc4.d.mts +277 -0
  61. package/dist/index-By6dNRc4.d.mts.map +1 -0
  62. package/dist/{index-BzYtgdX0.d.mts → index-CGiLfREk.d.mts} +123 -16
  63. package/dist/index-CGiLfREk.d.mts.map +1 -0
  64. package/dist/index-CUZn-ohG.d.mts +490 -0
  65. package/dist/index-CUZn-ohG.d.mts.map +1 -0
  66. package/dist/index-Cq2IFito.d.mts +121 -0
  67. package/dist/index-Cq2IFito.d.mts.map +1 -0
  68. package/dist/{index-B2l8_CiD.d.mts → index-DEAWPlcI.d.mts} +155 -216
  69. package/dist/index-DEAWPlcI.d.mts.map +1 -0
  70. package/dist/{index-C4v_3f3-.d.mts → index-DKS1g1oC.d.mts} +95 -42
  71. package/dist/index-DKS1g1oC.d.mts.map +1 -0
  72. package/dist/{index-jeC5jyRh.d.mts → index-DXbYlSnB.d.mts} +64 -101
  73. package/dist/index-DXbYlSnB.d.mts.map +1 -0
  74. package/dist/{index-CjZ95Dsv.d.mts → index-UzMbg1dh.d.mts} +188 -202
  75. package/dist/index-UzMbg1dh.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-Tfbo4wty.mjs +2 -0
  91. package/dist/option-Tfbo4wty.mjs.map +1 -0
  92. package/dist/option.types-D1mm0zUb.mjs +2 -0
  93. package/dist/option.types-D1mm0zUb.mjs.map +1 -0
  94. package/dist/{option.types-ClJiBTdg.d.mts → option.types-qPevEZQd.d.mts} +7 -12
  95. package/dist/option.types-qPevEZQd.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-C2cWOx2B.mjs +2 -0
  111. package/dist/provide-C2cWOx2B.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-Sg6KJerl.mjs +2 -0
  115. package/dist/queue-Sg6KJerl.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-D_kzd1nT.mjs +2 -0
  135. package/dist/scope-D_kzd1nT.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,7 @@
1
- import { i as Fx } from "./fx.types-B34asVRX.mjs";
2
- import { t as Pipeable } from "./pipeable-B4YJA56p.mjs";
3
- import { t as Result } from "./result.types-HHDzgSTV.mjs";
4
- import { r as Option } from "./option.types-ClJiBTdg.mjs";
1
+ import { i as Fx } from "./fx.types-DeEWEltG.mjs";
2
+ import { t as Pipeable } from "./pipeable-rfqacPxZ.mjs";
3
+ import { t as Result } from "./result.types-_xDAei3-.mjs";
4
+ import { r as Option } from "./option.types-qPevEZQd.mjs";
5
5
 
6
6
  //#region src/either/either.types.d.ts
7
7
  /**
@@ -70,53 +70,17 @@ type RightValue<E> = E extends {
70
70
  readonly _tag: "Right";
71
71
  readonly value: infer R;
72
72
  } ? R : never;
73
- /**
74
- * Return type for map() - detects Promise and adjusts return type
75
- */
76
- type MapReturn<FnReturn, L> = FnReturn extends Promise<infer U> ? Promise<Either$1<L, U>> : Either$1<L, FnReturn>;
77
- /**
78
- * Return type for mapLeft() - detects Promise and adjusts return type
79
- */
80
- type MapLeftReturn<R, FnReturn> = FnReturn extends Promise<infer L2> ? Promise<Either$1<L2, R>> : Either$1<FnReturn, R>;
81
- /**
82
- * Return type for bimap() - detects Promise and adjusts return type
83
- */
84
- type BimapReturn<FnLeftReturn, FnRightReturn> = FnLeftReturn | FnRightReturn extends Promise<any> ? Promise<FnLeftReturn extends Promise<Either$1<infer L2, any>> ? Either$1<L2, any> : FnLeftReturn extends Either$1<infer L2, any> ? Either$1<L2, any> : FnRightReturn extends Promise<Either$1<any, infer R2>> ? Either$1<any, R2> : FnRightReturn extends Either$1<any, infer R2> ? Either$1<any, R2> : never> : FnLeftReturn extends Either$1<infer L2, any> ? FnRightReturn extends Either$1<any, infer R2> ? Either$1<L2, R2> : never : never;
85
- /**
86
- * Return type for flatMap() - combines left error unions
87
- */
88
- type FlatMapReturn<FnReturn, L> = FnReturn extends Promise<Either$1<infer L2, infer R2>> ? Promise<Either$1<L | L2, R2>> : FnReturn extends Either$1<infer L2, infer R2> ? Either$1<L | L2, R2> : never;
89
- /**
90
- * Return type for tap() - preserves Either type with async detection
91
- */
92
- type TapReturn<FnReturn, L, R> = FnReturn extends Promise<any> ? Promise<Either$1<L, R>> : Either$1<L, R>;
93
- /**
94
- * Return type for orElse() - combines right value unions
95
- */
96
- type OrElseReturn<FnReturn, R> = FnReturn extends Promise<Either$1<infer L2, infer R2>> ? Promise<Either$1<L2, R | R2>> : FnReturn extends Either$1<infer L2, infer R2> ? Either$1<L2, R | R2> : never;
97
- /**
98
- * Return type for filter() - adds L2 to left union
99
- */
100
- type FilterReturn<L, L2$1, R> = Either$1<L | L2$1, R>;
101
- /**
102
- * Return type for all() with array input - preserves tuple structure
103
- */
104
- type AllArrayReturn<T extends readonly Either$1<unknown, unknown>[]> = Either$1<LeftValue<T[number]>, { -readonly [K in keyof T]: RightValue<T[K]> }>;
105
- /**
106
- * Return type for all() with object input - preserves object structure
107
- */
108
- type AllObjectReturn<T extends Record<string, Either$1<unknown, unknown>>> = Either$1<LeftValue<T[keyof T]>, { -readonly [K in keyof T]: RightValue<T[K]> }>;
109
73
  /**
110
74
  * Overloaded all() type with explicit tuple arities for better inference.
111
75
  * Provides tuple overloads for 1-6 elements so `as const` is not required.
112
76
  */
113
77
  type EitherAll = {
114
78
  <L1, A>(eithers: readonly [Either$1<L1, A>]): Either$1<L1, [A]>;
115
- <L1, L2$1, A, B>(eithers: readonly [Either$1<L1, A>, Either$1<L2$1, B>]): Either$1<L1 | L2$1, [A, B]>;
116
- <L1, L2$1, L3, A, B, C>(eithers: readonly [Either$1<L1, A>, Either$1<L2$1, B>, Either$1<L3, C>]): Either$1<L1 | L2$1 | L3, [A, B, C]>;
117
- <L1, L2$1, L3, L4, A, B, C, D>(eithers: readonly [Either$1<L1, A>, Either$1<L2$1, B>, Either$1<L3, C>, Either$1<L4, D>]): Either$1<L1 | L2$1 | L3 | L4, [A, B, C, D]>;
118
- <L1, L2$1, L3, L4, L5, A, B, C, D, E>(eithers: readonly [Either$1<L1, A>, Either$1<L2$1, B>, Either$1<L3, C>, Either$1<L4, D>, Either$1<L5, E>]): Either$1<L1 | L2$1 | L3 | L4 | L5, [A, B, C, D, E]>;
119
- <L1, L2$1, L3, L4, L5, L6, A, B, C, D, E, F>(eithers: readonly [Either$1<L1, A>, Either$1<L2$1, B>, Either$1<L3, C>, Either$1<L4, D>, Either$1<L5, E>, Either$1<L6, F>]): Either$1<L1 | L2$1 | L3 | L4 | L5 | L6, [A, B, C, D, E, F]>;
79
+ <L1, L2, A, B>(eithers: readonly [Either$1<L1, A>, Either$1<L2, B>]): Either$1<L1 | L2, [A, B]>;
80
+ <L1, L2, L3, A, B, C>(eithers: readonly [Either$1<L1, A>, Either$1<L2, B>, Either$1<L3, C>]): Either$1<L1 | L2 | L3, [A, B, C]>;
81
+ <L1, L2, L3, L4, A, B, C, D>(eithers: readonly [Either$1<L1, A>, Either$1<L2, B>, Either$1<L3, C>, Either$1<L4, D>]): Either$1<L1 | L2 | L3 | L4, [A, B, C, D]>;
82
+ <L1, L2, L3, L4, L5, A, B, C, D, E>(eithers: readonly [Either$1<L1, A>, Either$1<L2, B>, Either$1<L3, C>, Either$1<L4, D>, Either$1<L5, E>]): Either$1<L1 | L2 | L3 | L4 | L5, [A, B, C, D, E]>;
83
+ <L1, L2, L3, L4, L5, L6, A, B, C, D, E, F>(eithers: readonly [Either$1<L1, A>, Either$1<L2, B>, Either$1<L3, C>, Either$1<L4, D>, Either$1<L5, E>, Either$1<L6, F>]): Either$1<L1 | L2 | L3 | L4 | L5 | L6, [A, B, C, D, E, F]>;
120
84
  <T extends readonly Either$1<unknown, unknown>[]>(eithers: T): Either$1<LeftValue<T[number]>, { -readonly [K in keyof T]: RightValue<T[K]> }>;
121
85
  <T extends Record<string, Either$1<unknown, unknown>>>(eithers: T): Either$1<LeftValue<T[keyof T]>, { -readonly [K in keyof T]: RightValue<T[K]> }>;
122
86
  };
@@ -136,34 +100,34 @@ type EitherMap = {
136
100
  * Supports both data-first and data-last (curried) calling styles via dual().
137
101
  */
138
102
  type EitherMapLeft = {
139
- <L1, R, L2$1>(either: Either$1<L1, R>, fn: (value: L1) => Promise<L2$1>): Promise<Either$1<L2$1, R>>;
140
- <L1, R, L2$1>(either: Either$1<L1, R>, fn: (value: L1) => L2$1): Either$1<L2$1, R>;
141
- <L1, L2$1>(fn: (value: L1) => Promise<L2$1>): <R>(either: Either$1<L1, R>) => Promise<Either$1<L2$1, R>>;
142
- <L1, L2$1>(fn: (value: L1) => L2$1): <R>(either: Either$1<L1, R>) => Either$1<L2$1, R>;
103
+ <L1, R, L2>(either: Either$1<L1, R>, fn: (value: L1) => Promise<L2>): Promise<Either$1<L2, R>>;
104
+ <L1, R, L2>(either: Either$1<L1, R>, fn: (value: L1) => L2): Either$1<L2, R>;
105
+ <L1, L2>(fn: (value: L1) => Promise<L2>): <R>(either: Either$1<L1, R>) => Promise<Either$1<L2, R>>;
106
+ <L1, L2>(fn: (value: L1) => L2): <R>(either: Either$1<L1, R>) => Either$1<L2, R>;
143
107
  };
144
108
  /**
145
109
  * Type-safe interface for bimap() with async detection
146
110
  * Supports both data-first and data-last (curried) calling styles via dual().
147
111
  */
148
112
  type EitherBimap = {
149
- <L1, R1, L2$1, R2$1>(either: Either$1<L1, R1>, fnLeft: (left: L1) => Promise<L2$1>, fnRight: (right: R1) => Promise<R2$1>): Promise<Either$1<L2$1, R2$1>>;
150
- <L1, R1, L2$1, R2$1>(either: Either$1<L1, R1>, fnLeft: (left: L1) => Promise<L2$1>, fnRight: (right: R1) => R2$1): Promise<Either$1<L2$1, R2$1>>;
151
- <L1, R1, L2$1, R2$1>(either: Either$1<L1, R1>, fnLeft: (left: L1) => L2$1, fnRight: (right: R1) => Promise<R2$1>): Promise<Either$1<L2$1, R2$1>>;
152
- <L1, R1, L2$1, R2$1>(either: Either$1<L1, R1>, fnLeft: (left: L1) => L2$1, fnRight: (right: R1) => R2$1): Either$1<L2$1, R2$1>;
153
- <L1, L2$1, R1, R2$1>(fnLeft: (left: L1) => Promise<L2$1>, fnRight: (right: R1) => Promise<R2$1>): (either: Either$1<L1, R1>) => Promise<Either$1<L2$1, R2$1>>;
154
- <L1, L2$1, R1, R2$1>(fnLeft: (left: L1) => Promise<L2$1>, fnRight: (right: R1) => R2$1): (either: Either$1<L1, R1>) => Promise<Either$1<L2$1, R2$1>>;
155
- <L1, L2$1, R1, R2$1>(fnLeft: (left: L1) => L2$1, fnRight: (right: R1) => Promise<R2$1>): (either: Either$1<L1, R1>) => Promise<Either$1<L2$1, R2$1>>;
156
- <L1, L2$1, R1, R2$1>(fnLeft: (left: L1) => L2$1, fnRight: (right: R1) => R2$1): (either: Either$1<L1, R1>) => Either$1<L2$1, R2$1>;
113
+ <L1, R1, L2, R2>(either: Either$1<L1, R1>, fnLeft: (left: L1) => Promise<L2>, fnRight: (right: R1) => Promise<R2>): Promise<Either$1<L2, R2>>;
114
+ <L1, R1, L2, R2>(either: Either$1<L1, R1>, fnLeft: (left: L1) => Promise<L2>, fnRight: (right: R1) => R2): Promise<Either$1<L2, R2>>;
115
+ <L1, R1, L2, R2>(either: Either$1<L1, R1>, fnLeft: (left: L1) => L2, fnRight: (right: R1) => Promise<R2>): Promise<Either$1<L2, R2>>;
116
+ <L1, R1, L2, R2>(either: Either$1<L1, R1>, fnLeft: (left: L1) => L2, fnRight: (right: R1) => R2): Either$1<L2, R2>;
117
+ <L1, L2, R1, R2>(fnLeft: (left: L1) => Promise<L2>, fnRight: (right: R1) => Promise<R2>): (either: Either$1<L1, R1>) => Promise<Either$1<L2, R2>>;
118
+ <L1, L2, R1, R2>(fnLeft: (left: L1) => Promise<L2>, fnRight: (right: R1) => R2): (either: Either$1<L1, R1>) => Promise<Either$1<L2, R2>>;
119
+ <L1, L2, R1, R2>(fnLeft: (left: L1) => L2, fnRight: (right: R1) => Promise<R2>): (either: Either$1<L1, R1>) => Promise<Either$1<L2, R2>>;
120
+ <L1, L2, R1, R2>(fnLeft: (left: L1) => L2, fnRight: (right: R1) => R2): (either: Either$1<L1, R1>) => Either$1<L2, R2>;
157
121
  };
158
122
  /**
159
123
  * Type-safe interface for flatMap() with async detection and left union
160
124
  * Supports both data-first and data-last (curried) calling styles via dual().
161
125
  */
162
126
  type EitherFlatMap = {
163
- <L, A, B, L2$1>(either: Either$1<L, A>, fn: (value: A) => Promise<Either$1<L2$1, B>>): Promise<Either$1<L | L2$1, B>>;
164
- <L, A, B, L2$1>(either: Either$1<L, A>, fn: (value: A) => Either$1<L2$1, B>): Either$1<L | L2$1, B>;
165
- <A, B, L2$1>(fn: (value: A) => Promise<Either$1<L2$1, B>>): <L>(either: Either$1<L, A>) => Promise<Either$1<L | L2$1, B>>;
166
- <A, B, L2$1>(fn: (value: A) => Either$1<L2$1, B>): <L>(either: Either$1<L, A>) => Either$1<L | L2$1, B>;
127
+ <L, A, B, L2>(either: Either$1<L, A>, fn: (value: A) => Promise<Either$1<L2, B>>): Promise<Either$1<L | L2, B>>;
128
+ <L, A, B, L2>(either: Either$1<L, A>, fn: (value: A) => Either$1<L2, B>): Either$1<L | L2, B>;
129
+ <A, B, L2>(fn: (value: A) => Promise<Either$1<L2, B>>): <L>(either: Either$1<L, A>) => Promise<Either$1<L | L2, B>>;
130
+ <A, B, L2>(fn: (value: A) => Either$1<L2, B>): <L>(either: Either$1<L, A>) => Either$1<L | L2, B>;
167
131
  };
168
132
  /**
169
133
  * Type-safe interface for tap() with async detection
@@ -190,18 +154,18 @@ type EitherTapLeft = {
190
154
  * Supports both data-first and data-last (curried) calling styles via dual().
191
155
  */
192
156
  type EitherOrElse = {
193
- <L1, R, L2$1, R2$1>(either: Either$1<L1, R>, fn: (left: L1) => Promise<Either$1<L2$1, R2$1>>): Promise<Either$1<L2$1, R | R2$1>>;
194
- <L1, R, L2$1, R2$1>(either: Either$1<L1, R>, fn: (left: L1) => Either$1<L2$1, R2$1>): Either$1<L2$1, R | R2$1>;
195
- <L1, L2$1, R2$1>(fn: (left: L1) => Promise<Either$1<L2$1, R2$1>>): <R>(either: Either$1<L1, R>) => Promise<Either$1<L2$1, R | R2$1>>;
196
- <L1, L2$1, R2$1>(fn: (left: L1) => Either$1<L2$1, R2$1>): <R>(either: Either$1<L1, R>) => Either$1<L2$1, R | R2$1>;
157
+ <L1, R, L2, R2>(either: Either$1<L1, R>, fn: (left: L1) => Promise<Either$1<L2, R2>>): Promise<Either$1<L2, R | R2>>;
158
+ <L1, R, L2, R2>(either: Either$1<L1, R>, fn: (left: L1) => Either$1<L2, R2>): Either$1<L2, R | R2>;
159
+ <L1, L2, R2>(fn: (left: L1) => Promise<Either$1<L2, R2>>): <R>(either: Either$1<L1, R>) => Promise<Either$1<L2, R | R2>>;
160
+ <L1, L2, R2>(fn: (left: L1) => Either$1<L2, R2>): <R>(either: Either$1<L1, R>) => Either$1<L2, R | R2>;
197
161
  };
198
162
  /**
199
163
  * Type-safe interface for filter()
200
164
  * Supports both data-first and data-last (curried) calling styles via dual().
201
165
  */
202
166
  type EitherFilter = {
203
- <L, R, L2$1>(either: Either$1<L, R>, predicate: (value: R) => boolean, onFail: (value: R) => L2$1): Either$1<L | L2$1, R>;
204
- <R, L2$1>(predicate: (value: R) => boolean, onFail: (value: R) => L2$1): <L>(either: Either$1<L, R>) => Either$1<L | L2$1, R>;
167
+ <L, R, L2>(either: Either$1<L, R>, predicate: (value: R) => boolean, onFail: (value: R) => L2): Either$1<L | L2, R>;
168
+ <R, L2>(predicate: (value: R) => boolean, onFail: (value: R) => L2): <L>(either: Either$1<L, R>) => Either$1<L | L2, R>;
205
169
  };
206
170
  /**
207
171
  * Interface for unwrapOr function.
@@ -225,17 +189,31 @@ type EitherUnwrapOrElse = {
225
189
  * Supports both data-first and data-last (curried) calling styles via dual().
226
190
  */
227
191
  type EitherMatch = {
228
- <L, R, U$1>(either: Either$1<L, R>, handlers: {
229
- Left: (value: L) => U$1;
230
- Right: (value: R) => U$1;
231
- }): U$1;
232
- <L, R, U$1>(handlers: {
233
- Left: (value: L) => U$1;
234
- Right: (value: R) => U$1;
235
- }): (either: Either$1<L, R>) => U$1;
192
+ <L, R, U>(either: Either$1<L, R>, handlers: {
193
+ Left: (value: L) => U;
194
+ Right: (value: R) => U;
195
+ }): U;
196
+ <L, R, U>(handlers: {
197
+ Left: (value: L) => U;
198
+ Right: (value: R) => U;
199
+ }): (either: Either$1<L, R>) => U;
236
200
  };
237
- //#endregion
238
- //#region src/either/either.d.ts
201
+ declare namespace either_d_exports {
202
+ export { Either, all, bimap, filter, flatMap, fromNullable, fromOption, fromPredicate, fromResult, isLeft, isRight, left, map, mapLeft, match, orElse, right, swap, tap, tapLeft, toOption, toResult, unwrapOr, unwrapOrElse };
203
+ }
204
+ /**
205
+ * Re-exported `Either` type.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * import type { Either } from "@nicolastoulemont/std"
210
+ *
211
+ * type Example = Either.Either<unknown, unknown>
212
+ * ```
213
+ *
214
+ * @category Re-exports
215
+ */
216
+ type Either<L, R> = Either$1<L, R>;
239
217
  /**
240
218
  * Create a right Either value (success/preferred path).
241
219
  *
@@ -247,15 +225,13 @@ type EitherMatch = {
247
225
  *
248
226
  * @example
249
227
  * ```ts
250
- * const result = right(42)
251
- * // => { _tag: "Right", value: 42 }
228
+ * import { Either } from "@nicolastoulemont/std"
252
229
  *
253
- * // In Fx.gen() - never short-circuits
254
- * const fx = Fx.gen(function* () {
255
- * const a = yield* Either.right(10) // Returns 10
256
- * return a * 2 // Executes, returns 20
257
- * })
230
+ * const value = Either.right(42)
231
+ * // => { _tag: "Right", value: 42 }
258
232
  * ```
233
+ *
234
+ * @category Constructors
259
235
  */
260
236
  declare const right: <R, L = never>(value: R) => Either$1<L, R>;
261
237
  /**
@@ -272,15 +248,13 @@ declare const right: <R, L = never>(value: R) => Either$1<L, R>;
272
248
  *
273
249
  * @example
274
250
  * ```ts
275
- * const cached = left({ source: "cache", data: cachedValue })
276
- * // => { _tag: "Left", value: { source: "cache", data: cachedValue } }
251
+ * import { Either } from "@nicolastoulemont/std"
277
252
  *
278
- * // In Fx.gen() - never short-circuits (unlike Result.err)
279
- * const fx = Fx.gen(function* () {
280
- * const a = yield* Either.left("cached") // Returns "cached"
281
- * return a.toUpperCase() // Executes, returns "CACHED"
282
- * })
253
+ * const value = Either.left("missing")
254
+ * // => { _tag: "Left", value: "missing" }
283
255
  * ```
256
+ *
257
+ * @category Constructors
284
258
  */
285
259
  declare const left: <L, R = never>(value: L) => Either$1<L, R>;
286
260
  /**
@@ -291,15 +265,30 @@ declare const left: <L, R = never>(value: L) => Either$1<L, R>;
291
265
  *
292
266
  * @example
293
267
  * ```ts
294
- * const either = right(42)
295
- * if (isRight(either)) {
296
- * console.log(either.value) // Type: number
297
- * }
268
+ * import { Either } from "@nicolastoulemont/std"
269
+ *
270
+ * const isRight = Either.isRight(Either.right(1))
271
+ * // => true
298
272
  * ```
273
+ *
274
+ * @category Guards
299
275
  */
300
276
  declare const isRight: <L, R>(either: Either$1<L, R>) => either is Extract<Either$1<L, R>, {
301
277
  _tag: "Right";
302
278
  }>;
279
+ /**
280
+ * isLeft utility.
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * import { Either } from "@nicolastoulemont/std"
285
+ *
286
+ * const isLeft = Either.isLeft(Either.left("missing"))
287
+ * // => true
288
+ * ```
289
+ *
290
+ * @category Guards
291
+ */
303
292
  declare const isLeft: <L, R>(either: Either$1<L, R>) => either is Extract<Either$1<L, R>, {
304
293
  _tag: "Left";
305
294
  }>;
@@ -318,26 +307,17 @@ declare const isLeft: <L, R>(either: Either$1<L, R>) => either is Extract<Either
318
307
  *
319
308
  * @example
320
309
  * ```ts
321
- * // Data-first (direct call)
322
- * map(right(5), x => x * 2) // => right(10)
323
- *
324
- * // Data-last (curried for pipe)
325
- * pipe(
326
- * right(5),
327
- * map(x => x * 2)
328
- * ) // => right(10)
329
- *
330
- * pipe(
331
- * left("error"),
332
- * map(x => x * 2)
333
- * ) // => left("error")
334
- *
335
- * // Async usage
336
- * await pipe(
337
- * right(userId),
338
- * map(async id => await fetchUser(id))
339
- * ) // => Promise<Either<L, User>>
310
+ * import { Either } from "@nicolastoulemont/std"
311
+ *
312
+ * const input = Either.right(2)
313
+ * const dataFirst = Either.map(input, (n) => n + 1)
314
+ * // => { _tag: "Right", value: 3 }
315
+ *
316
+ * const dataLast = Either.map((n: number) => n + 1)(input)
317
+ * // => { _tag: "Right", value: 3 }
340
318
  * ```
319
+ *
320
+ * @category Mapping
341
321
  */
342
322
  declare const map: EitherMap;
343
323
  /**
@@ -355,20 +335,17 @@ declare const map: EitherMap;
355
335
  *
356
336
  * @example
357
337
  * ```ts
358
- * // Data-first (direct call)
359
- * mapLeft(left("error"), e => e.toUpperCase()) // => left("ERROR")
360
- *
361
- * // Data-last (curried for pipe)
362
- * pipe(
363
- * left("error"),
364
- * mapLeft(e => e.toUpperCase())
365
- * ) // => left("ERROR")
366
- *
367
- * pipe(
368
- * right(42),
369
- * mapLeft(e => e.toUpperCase())
370
- * ) // => right(42)
338
+ * import { Either } from "@nicolastoulemont/std"
339
+ *
340
+ * const input = Either.left("missing")
341
+ * const dataFirst = Either.mapLeft(input, (msg) => msg.toUpperCase())
342
+ * // => { _tag: "Left", value: "MISSING" }
343
+ *
344
+ * const dataLast = Either.mapLeft((msg: string) => msg.toUpperCase())(input)
345
+ * // => { _tag: "Left", value: "MISSING" }
371
346
  * ```
347
+ *
348
+ * @category Mapping
372
349
  */
373
350
  declare const mapLeft: EitherMapLeft;
374
351
  /**
@@ -387,26 +364,17 @@ declare const mapLeft: EitherMapLeft;
387
364
  *
388
365
  * @example
389
366
  * ```ts
390
- * // Data-first (direct call)
391
- * bimap(right(5), e => e.toUpperCase(), x => x * 2) // => right(10)
392
- *
393
- * // Data-last (curried for pipe)
394
- * pipe(
395
- * right(5),
396
- * bimap(
397
- * e => e.toUpperCase(),
398
- * x => x * 2
399
- * )
400
- * ) // => right(10)
401
- *
402
- * pipe(
403
- * left("error"),
404
- * bimap(
405
- * e => e.toUpperCase(),
406
- * x => x * 2
407
- * )
408
- * ) // => left("ERROR")
367
+ * import { Either } from "@nicolastoulemont/std"
368
+ *
369
+ * const input = Either.left("missing")
370
+ * const dataFirst = Either.bimap(input, (left) => left.toUpperCase(), (right: number) => right + 1)
371
+ * // => { _tag: "Left", value: "MISSING" }
372
+ *
373
+ * const dataLast = Either.bimap((left: string) => left.toUpperCase(), (right: number) => right + 1)(input)
374
+ * // => { _tag: "Left", value: "MISSING" }
409
375
  * ```
376
+ *
377
+ * @category Mapping
410
378
  */
411
379
  declare const bimap: EitherBimap;
412
380
  /**
@@ -424,29 +392,17 @@ declare const bimap: EitherBimap;
424
392
  *
425
393
  * @example
426
394
  * ```ts
427
- * // Data-first (direct call)
428
- * flatMap(right(5), x => right(x * 2)) // => right(10)
429
- *
430
- * // Data-last (curried for pipe)
431
- * pipe(
432
- * right(5),
433
- * flatMap(x => right(x * 2)),
434
- * flatMap(x => right(x + 1))
435
- * ) // => right(11)
436
- *
437
- * pipe(
438
- * right(5),
439
- * flatMap(x => left("error")),
440
- * flatMap(x => right(x + 1)) // Not executed
441
- * ) // => left("error")
442
- *
443
- * // Async usage
444
- * await pipe(
445
- * right(userId),
446
- * flatMap(async id => right(await fetchUser(id))),
447
- * flatMap(async user => right(await enrichProfile(user)))
448
- * ) // => Promise<Either<L, EnrichedUser>>
395
+ * import { Either } from "@nicolastoulemont/std"
396
+ *
397
+ * const input = Either.right(2)
398
+ * const dataFirst = Either.flatMap(input, (n) => Either.right(n + 1))
399
+ * // => { _tag: "Right", value: 3 }
400
+ *
401
+ * const dataLast = Either.flatMap((n: number) => Either.right(n + 1))(input)
402
+ * // => { _tag: "Right", value: 3 }
449
403
  * ```
404
+ *
405
+ * @category Sequencing
450
406
  */
451
407
  declare const flatMap: EitherFlatMap;
452
408
  /**
@@ -464,16 +420,22 @@ declare const flatMap: EitherFlatMap;
464
420
  *
465
421
  * @example
466
422
  * ```ts
467
- * // Data-first (direct call)
468
- * tap(right(42), x => console.log(x)) // Logs: 42, returns right(42)
469
- *
470
- * // Data-last (curried for pipe)
471
- * pipe(
472
- * right(42),
473
- * tap(x => console.log(x)), // Logs: 42
474
- * map(x => x * 2)
475
- * ) // => right(84)
423
+ * import { Either } from "@nicolastoulemont/std"
424
+ *
425
+ * let seen = 0
426
+ * const input = Either.right(2)
427
+ * const dataFirst = Either.tap(input, (n) => {
428
+ * seen = n
429
+ * })
430
+ * // => { _tag: "Right", value: 2 }
431
+ *
432
+ * const dataLast = Either.tap((n: number) => {
433
+ * seen = n
434
+ * })(input)
435
+ * // => { _tag: "Right", value: 2 }
476
436
  * ```
437
+ *
438
+ * @category Sequencing
477
439
  */
478
440
  declare const tap: EitherTap;
479
441
  /**
@@ -491,16 +453,22 @@ declare const tap: EitherTap;
491
453
  *
492
454
  * @example
493
455
  * ```ts
494
- * // Data-first (direct call)
495
- * tapLeft(left("error"), e => console.error(e)) // Logs: error, returns left("error")
496
- *
497
- * // Data-last (curried for pipe)
498
- * pipe(
499
- * left("error"),
500
- * tapLeft(e => console.error(e)), // Logs: error
501
- * mapLeft(e => e.toUpperCase())
502
- * ) // => left("ERROR")
456
+ * import { Either } from "@nicolastoulemont/std"
457
+ *
458
+ * let seen = ""
459
+ * const input = Either.left("missing")
460
+ * const dataFirst = Either.tapLeft(input, (msg) => {
461
+ * seen = msg
462
+ * })
463
+ * // => { _tag: "Left", value: "missing" }
464
+ *
465
+ * const dataLast = Either.tapLeft((msg: string) => {
466
+ * seen = msg
467
+ * })(input)
468
+ * // => { _tag: "Left", value: "missing" }
503
469
  * ```
470
+ *
471
+ * @category Sequencing
504
472
  */
505
473
  declare const tapLeft: EitherTapLeft;
506
474
  /**
@@ -518,20 +486,17 @@ declare const tapLeft: EitherTapLeft;
518
486
  *
519
487
  * @example
520
488
  * ```ts
521
- * // Data-first (direct call)
522
- * orElse(left("error"), () => right(42)) // => right(42)
523
- *
524
- * // Data-last (curried for pipe)
525
- * pipe(
526
- * left("error"),
527
- * orElse(() => right(42))
528
- * ) // => right(42)
529
- *
530
- * pipe(
531
- * right(10),
532
- * orElse(() => right(42))
533
- * ) // => right(10)
489
+ * import { Either } from "@nicolastoulemont/std"
490
+ *
491
+ * const input = Either.left("missing")
492
+ * const dataFirst = Either.orElse(input, () => Either.right(0))
493
+ * // => { _tag: "Right", value: 0 }
494
+ *
495
+ * const dataLast = Either.orElse(() => Either.right(0))(input)
496
+ * // => { _tag: "Right", value: 0 }
534
497
  * ```
498
+ *
499
+ * @category Error Handling
535
500
  */
536
501
  declare const orElse: EitherOrElse;
537
502
  /**
@@ -544,16 +509,14 @@ declare const orElse: EitherOrElse;
544
509
  *
545
510
  * @example
546
511
  * ```ts
547
- * pipe(
548
- * left("error"),
549
- * swap()
550
- * ) // => right("error")
551
- *
552
- * pipe(
553
- * right(42),
554
- * swap()
555
- * ) // => left(42)
512
+ * import { Either } from "@nicolastoulemont/std"
513
+ *
514
+ * const swap = Either.swap<string, number>()
515
+ * const value = swap(Either.left("missing"))
516
+ * // => { _tag: "Right", value: "missing" }
556
517
  * ```
518
+ *
519
+ * @category Conversions
557
520
  */
558
521
  declare const swap: <L, R>() => (either: Either$1<L, R>) => Either$1<R, L>;
559
522
  /**
@@ -571,20 +534,17 @@ declare const swap: <L, R>() => (either: Either$1<L, R>) => Either$1<R, L>;
571
534
  *
572
535
  * @example
573
536
  * ```ts
574
- * // Data-first (direct call)
575
- * filter(right(5), x => x > 3, x => `${x} is too small`) // => right(5)
576
- *
577
- * // Data-last (curried for pipe)
578
- * pipe(
579
- * right(5),
580
- * filter(x => x > 3, x => `${x} is too small`)
581
- * ) // => right(5)
582
- *
583
- * pipe(
584
- * right(2),
585
- * filter(x => x > 3, x => `${x} is too small`)
586
- * ) // => left("2 is too small")
537
+ * import { Either } from "@nicolastoulemont/std"
538
+ *
539
+ * const input = Either.right(3)
540
+ * const dataFirst = Either.filter(input, (n) => n > 0, (n) => `${n} must be positive`)
541
+ * // => { _tag: "Right", value: 3 }
542
+ *
543
+ * const dataLast = Either.filter((n: number) => n > 0, (n) => `${n} must be positive`)(input)
544
+ * // => { _tag: "Right", value: 3 }
587
545
  * ```
546
+ *
547
+ * @category Filtering
588
548
  */
589
549
  declare const filter: EitherFilter;
590
550
  /**
@@ -600,17 +560,13 @@ declare const filter: EitherFilter;
600
560
  *
601
561
  * @example
602
562
  * ```ts
603
- * // Array form - tuple types inferred automatically for up to 6 elements
604
- * all([right(1), right("hello")])
605
- * // => right([1, "hello"])
606
- *
607
- * all([right(1), left("error"), right(3)])
608
- * // => left("error")
563
+ * import { Either } from "@nicolastoulemont/std"
609
564
  *
610
- * // Object form
611
- * all({ a: right(1), b: right("hello") })
612
- * // => right({ a: 1, b: "hello" })
565
+ * const combined = Either.all([Either.right(1), Either.right(2)] as const)
566
+ * // => { _tag: "Right", value: [1, 2] }
613
567
  * ```
568
+ *
569
+ * @category Combining
614
570
  */
615
571
  declare const all: EitherAll;
616
572
  /**
@@ -627,21 +583,17 @@ declare const all: EitherAll;
627
583
  *
628
584
  * @example
629
585
  * ```ts
630
- * // Data-first (direct call)
631
- * unwrapOr(right(42), 0) // => 42
632
- * unwrapOr(left("error"), 0) // => 0
633
- *
634
- * // Data-last (curried for pipe)
635
- * pipe(
636
- * right(42),
637
- * unwrapOr(0)
638
- * ) // => 42
639
- *
640
- * pipe(
641
- * left("error"),
642
- * unwrapOr(0)
643
- * ) // => 0
586
+ * import { Either } from "@nicolastoulemont/std"
587
+ *
588
+ * const input = Either.left("missing") as Either.Either<string, number>
589
+ * const dataFirst = Either.unwrapOr(input, 0)
590
+ * // => 0
591
+ *
592
+ * const dataLast = Either.unwrapOr(0)(input)
593
+ * // => 0
644
594
  * ```
595
+ *
596
+ * @category Getters
645
597
  */
646
598
  declare const unwrapOr: EitherUnwrapOr;
647
599
  /**
@@ -656,21 +608,17 @@ declare const unwrapOr: EitherUnwrapOr;
656
608
  *
657
609
  * @example
658
610
  * ```ts
659
- * // Data-first (direct call)
660
- * unwrapOrElse(right(42), () => 0) // => 42
661
- * unwrapOrElse(left("error"), e => e.length) // => 5
662
- *
663
- * // Data-last (curried for pipe)
664
- * pipe(
665
- * right(42),
666
- * unwrapOrElse(() => 0)
667
- * ) // => 42
668
- *
669
- * pipe(
670
- * left("error"),
671
- * unwrapOrElse(e => e.length)
672
- * ) // => 5
611
+ * import { Either } from "@nicolastoulemont/std"
612
+ *
613
+ * const input = Either.left("missing") as Either.Either<string, number>
614
+ * const dataFirst = Either.unwrapOrElse(input, () => 0)
615
+ * // => 0
616
+ *
617
+ * const dataLast = Either.unwrapOrElse(() => 0)(input)
618
+ * // => 0
673
619
  * ```
620
+ *
621
+ * @category Getters
674
622
  */
675
623
  declare const unwrapOrElse: EitherUnwrapOrElse;
676
624
  /**
@@ -685,21 +633,23 @@ declare const unwrapOrElse: EitherUnwrapOrElse;
685
633
  *
686
634
  * @example
687
635
  * ```ts
688
- * // Data-first (direct call)
689
- * match(right(42), {
690
- * Left: e => `Error: ${e}`,
691
- * Right: x => `Success: ${x}`
692
- * }) // => "Success: 42"
693
- *
694
- * // Data-last (curried for pipe)
695
- * pipe(
696
- * right(42),
697
- * match({
698
- * Left: e => `Error: ${e}`,
699
- * Right: x => `Success: ${x}`
700
- * })
701
- * ) // => "Success: 42"
636
+ * import { Either } from "@nicolastoulemont/std"
637
+ *
638
+ * const input = Either.right(2) as Either.Either<string, number>
639
+ * const dataFirst = Either.match(input, {
640
+ * Left: (left) => `error:${left}` ,
641
+ * Right: (right) => `ok:${right}` ,
642
+ * })
643
+ * // => "ok:2"
644
+ *
645
+ * const dataLast = Either.match({
646
+ * Left: (left: string) => `error:${left}` ,
647
+ * Right: (right: number) => `ok:${right}` ,
648
+ * })(input)
649
+ * // => "ok:2"
702
650
  * ```
651
+ *
652
+ * @category Pattern Matching
703
653
  */
704
654
  declare const match: EitherMatch;
705
655
  /**
@@ -711,9 +661,15 @@ declare const match: EitherMatch;
711
661
  *
712
662
  * @example
713
663
  * ```ts
714
- * fromResult(Result.ok(42)) // => right(42)
715
- * fromResult(Result.err("error")) // => left("error")
664
+ * import { Either } from "@nicolastoulemont/std"
665
+ *
666
+ * import { Result } from "@nicolastoulemont/std"
667
+ *
668
+ * const value = Either.fromResult(Result.ok(1))
669
+ * // => { _tag: "Right", value: 1 }
716
670
  * ```
671
+ *
672
+ * @category Conversions
717
673
  */
718
674
  declare const fromResult: <R, E>(result: Result<R, E>) => Either$1<E, R>;
719
675
  /**
@@ -727,16 +683,13 @@ declare const fromResult: <R, E>(result: Result<R, E>) => Either$1<E, R>;
727
683
  *
728
684
  * @example
729
685
  * ```ts
730
- * pipe(
731
- * right(42),
732
- * toResult
733
- * ) // => Result.ok(42)
734
- *
735
- * pipe(
736
- * left("error"),
737
- * toResult
738
- * ) // => Result.err("error")
686
+ * import { Either } from "@nicolastoulemont/std"
687
+ *
688
+ * const value = Either.toResult(Either.left("missing"))
689
+ * // => { _tag: "Err", error: "missing" }
739
690
  * ```
691
+ *
692
+ * @category Conversions
740
693
  */
741
694
  declare const toResult: <L, R>(either: Either$1<L, R>) => Result<R, L>;
742
695
  /**
@@ -749,9 +702,15 @@ declare const toResult: <L, R>(either: Either$1<L, R>) => Result<R, L>;
749
702
  *
750
703
  * @example
751
704
  * ```ts
752
- * fromOption(Option.some(42), () => "not found") // => right(42)
753
- * fromOption(Option.none(), () => "not found") // => left("not found")
705
+ * import { Either } from "@nicolastoulemont/std"
706
+ *
707
+ * import { Option } from "@nicolastoulemont/std"
708
+ *
709
+ * const value = Either.fromOption(Option.some(1), () => "missing")
710
+ * // => { _tag: "Right", value: 1 }
754
711
  * ```
712
+ *
713
+ * @category Conversions
755
714
  */
756
715
  declare const fromOption: <R, L>(option: Option<R>, onNone: () => L) => Either$1<L, R>;
757
716
  /**
@@ -765,16 +724,13 @@ declare const fromOption: <R, L>(option: Option<R>, onNone: () => L) => Either$1
765
724
  *
766
725
  * @example
767
726
  * ```ts
768
- * pipe(
769
- * right(42),
770
- * toOption
771
- * ) // => Option.some(42)
772
- *
773
- * pipe(
774
- * left("error"),
775
- * toOption
776
- * ) // => Option.none()
727
+ * import { Either } from "@nicolastoulemont/std"
728
+ *
729
+ * const value = Either.toOption(Either.left("missing"))
730
+ * // => { _tag: "None" }
777
731
  * ```
732
+ *
733
+ * @category Conversions
778
734
  */
779
735
  declare const toOption: <L, R>(either: Either$1<L, R>) => Option<R>;
780
736
  /**
@@ -787,10 +743,13 @@ declare const toOption: <L, R>(either: Either$1<L, R>) => Option<R>;
787
743
  *
788
744
  * @example
789
745
  * ```ts
790
- * fromNullable(42, () => "not found") // => right(42)
791
- * fromNullable(null, () => "not found") // => left("not found")
792
- * fromNullable(undefined, () => "not found") // => left("not found")
746
+ * import { Either } from "@nicolastoulemont/std"
747
+ *
748
+ * const value = Either.fromNullable("Ada", () => "missing")
749
+ * // => { _tag: "Right", value: "Ada" }
793
750
  * ```
751
+ *
752
+ * @category Conversions
794
753
  */
795
754
  declare const fromNullable: <R, L>(value: R | null | undefined, onNull: () => L) => Either$1<L, R>;
796
755
  /**
@@ -804,79 +763,15 @@ declare const fromNullable: <R, L>(value: R | null | undefined, onNull: () => L)
804
763
  *
805
764
  * @example
806
765
  * ```ts
807
- * fromPredicate(5, x => x > 3, x => `${x} is too small`)
808
- * // => right(5)
766
+ * import { Either } from "@nicolastoulemont/std"
809
767
  *
810
- * fromPredicate(2, x => x > 3, x => `${x} is too small`)
811
- * // => left("2 is too small")
768
+ * const value = Either.fromPredicate(3, (n) => n > 0, (n) => `${n} must be positive`)
769
+ * // => { _tag: "Right", value: 3 }
812
770
  * ```
813
- */
814
- declare const fromPredicate: <R, L>(value: R, predicate: (value: R) => boolean, onFail: (value: R) => L) => Either$1<L, R>;
815
- /**
816
- * Either namespace containing all utility functions for working with Either types.
817
- *
818
- * Either represents a value that can be one of two types: Left<L> or Right<R>.
819
- * By convention, Right is the "success" or preferred path, while Left represents
820
- * an alternative outcome (not necessarily an error, unlike Result).
821
- *
822
- * Use Either when both outcomes are valid and meaningful, not just success/failure.
823
- * For error handling, prefer Result instead.
824
771
  *
825
- * @see {@link Result} for success/error semantics
826
- * @see {@link Option} for presence/absence semantics
827
- *
828
- * @example
829
- * ```ts
830
- * import { Either, pipe } from '@nicolastoulemont/std'
831
- * import type { Either as EitherType } from '@nicolastoulemont/std'
832
- *
833
- * // Either for branching logic (cache vs fresh data)
834
- * const fetchOrCache = (id: number): EitherType<CachedData, FreshData> =>
835
- * cache.has(id) ? Either.left(cache.get(id)) : Either.right(fetch(id))
836
- *
837
- * const result = pipe(
838
- * fetchOrCache(1),
839
- * Either.map(data => data.value),
840
- * Either.unwrapOr(defaultValue)
841
- * )
842
- *
843
- * // Async example
844
- * const processed = await pipe(
845
- * Either.right(userId),
846
- * Either.map(async id => await fetchUser(id)),
847
- * Either.flatMap(async user => Either.right(await enrichUser(user)))
848
- * )
849
- * ```
772
+ * @category Constructors
850
773
  */
851
- declare const Either: {
852
- readonly left: <L, R = never>(value: L) => Either$1<L, R>;
853
- readonly right: <R, L = never>(value: R) => Either$1<L, R>;
854
- readonly isLeft: <L, R>(either: Either$1<L, R>) => either is Extract<Either$1<L, R>, {
855
- _tag: "Left";
856
- }>;
857
- readonly isRight: <L, R>(either: Either$1<L, R>) => either is Extract<Either$1<L, R>, {
858
- _tag: "Right";
859
- }>;
860
- readonly map: EitherMap;
861
- readonly mapLeft: EitherMapLeft;
862
- readonly bimap: EitherBimap;
863
- readonly flatMap: EitherFlatMap;
864
- readonly tap: EitherTap;
865
- readonly tapLeft: EitherTapLeft;
866
- readonly orElse: EitherOrElse;
867
- readonly swap: <L, R>() => (either: Either$1<L, R>) => Either$1<R, L>;
868
- readonly filter: EitherFilter;
869
- readonly all: EitherAll;
870
- readonly unwrapOr: EitherUnwrapOr;
871
- readonly unwrapOrElse: EitherUnwrapOrElse;
872
- readonly match: EitherMatch;
873
- readonly fromResult: <R, E>(result: Result<R, E>) => Either$1<E, R>;
874
- readonly toResult: <L, R>(either: Either$1<L, R>) => Result<R, L>;
875
- readonly fromOption: <R, L>(option: Option<R>, onNone: () => L) => Either$1<L, R>;
876
- readonly toOption: <L, R>(either: Either$1<L, R>) => Option<R>;
877
- readonly fromNullable: <R, L>(value: R | null | undefined, onNull: () => L) => Either$1<L, R>;
878
- readonly fromPredicate: <R, L>(value: R, predicate: (value: R) => boolean, onFail: (value: R) => L) => Either$1<L, R>;
879
- };
774
+ declare const fromPredicate: <R, L>(value: R, predicate: (value: R) => boolean, onFail: (value: R) => L) => Either$1<L, R>;
880
775
  //#endregion
881
- export { FlatMapReturn as A, unwrapOr as C, BimapReturn as D, AllObjectReturn as E, OrElseReturn as F, Right as I, RightValue as L, LeftValue as M, MapLeftReturn as N, Either$1 as O, MapReturn as P, TapReturn as R, toResult as S, AllArrayReturn as T, right as _, flatMap as a, tapLeft as b, fromPredicate as c, isRight as d, left as f, orElse as g, match as h, filter as i, Left as j, FilterReturn as k, fromResult as l, mapLeft as m, all as n, fromNullable as o, map as p, bimap as r, fromOption as s, Either as t, isLeft as u, swap as v, unwrapOrElse as w, toOption as x, tap as y };
882
- //# sourceMappingURL=index-CklRfom5.d.mts.map
776
+ export { either_d_exports as t };
777
+ //# sourceMappingURL=index-B1-tBzc0.d.mts.map