@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.
- package/README.md +232 -33
- package/dist/adt/index.d.mts +2 -2
- package/dist/adt/index.mjs +1 -1
- package/dist/adt-DajUZvJe.mjs +2 -0
- package/dist/adt-DajUZvJe.mjs.map +1 -0
- package/dist/brand/index.d.mts +2 -2
- package/dist/brand/index.mjs +1 -1
- package/dist/brand-Bia3Vj6l.mjs +2 -0
- package/dist/brand-Bia3Vj6l.mjs.map +1 -0
- package/dist/context/index.d.mts +2 -0
- package/dist/context/index.mjs +1 -0
- package/dist/context-CCHj1nab.mjs +2 -0
- package/dist/context-CCHj1nab.mjs.map +1 -0
- package/dist/context-r8ESJiFn.d.mts +176 -0
- package/dist/context-r8ESJiFn.d.mts.map +1 -0
- package/dist/data/index.d.mts +2 -2
- package/dist/data/index.mjs +1 -1
- package/dist/data-BLXO4XwS.mjs +2 -0
- package/dist/data-BLXO4XwS.mjs.map +1 -0
- package/dist/data.tagged-error.types-CGiKD-ES.d.mts +29 -0
- package/dist/data.tagged-error.types-CGiKD-ES.d.mts.map +1 -0
- package/dist/{discriminator.types-9PxvrZki.d.mts → discriminator.types-CTURejXz.d.mts} +1 -1
- package/dist/discriminator.types-CTURejXz.d.mts.map +1 -0
- package/dist/dual-CZhzZslG.mjs +2 -0
- package/dist/dual-CZhzZslG.mjs.map +1 -0
- package/dist/either/index.d.mts +2 -2
- package/dist/either/index.mjs +1 -1
- package/dist/either-BMLPfvMl.mjs +2 -0
- package/dist/either-BMLPfvMl.mjs.map +1 -0
- package/dist/{equality-CD4_A1Op.mjs → equality-CoyUHWh9.mjs} +1 -1
- package/dist/{equality-CD4_A1Op.mjs.map → equality-CoyUHWh9.mjs.map} +1 -1
- package/dist/{flow-CYjiodlC.mjs → flow-D8_tllWl.mjs} +1 -1
- package/dist/flow-D8_tllWl.mjs.map +1 -0
- package/dist/functions/index.d.mts +2 -0
- package/dist/functions/index.mjs +1 -0
- package/dist/functions-BkevX2Dw.mjs +2 -0
- package/dist/functions-BkevX2Dw.mjs.map +1 -0
- package/dist/fx/index.d.mts +2 -3
- package/dist/fx/index.mjs +1 -1
- package/dist/fx-K-a9Smhn.mjs +2 -0
- package/dist/fx-K-a9Smhn.mjs.map +1 -0
- package/dist/fx.runtime-DclEDyjY.mjs +2 -0
- package/dist/fx.runtime-DclEDyjY.mjs.map +1 -0
- package/dist/{fx.types-CDVjDn_3.mjs → fx.types-Bg-Mmdm5.mjs} +1 -1
- package/dist/fx.types-Bg-Mmdm5.mjs.map +1 -0
- package/dist/{fx.types-B34asVRX.d.mts → fx.types-DeEWEltG.d.mts} +2 -2
- package/dist/{fx.types-B34asVRX.d.mts.map → fx.types-DeEWEltG.d.mts.map} +1 -1
- package/dist/index-7Lv982Om.d.mts +217 -0
- package/dist/index-7Lv982Om.d.mts.map +1 -0
- package/dist/{index-CklRfom5.d.mts → index-B1-tBzc0.d.mts} +263 -368
- package/dist/index-B1-tBzc0.d.mts.map +1 -0
- package/dist/index-BNQ9xSAz.d.mts +464 -0
- package/dist/index-BNQ9xSAz.d.mts.map +1 -0
- package/dist/index-B_iY5tq0.d.mts +241 -0
- package/dist/index-B_iY5tq0.d.mts.map +1 -0
- package/dist/index-B_wWGszy.d.mts +129 -0
- package/dist/index-B_wWGszy.d.mts.map +1 -0
- package/dist/index-BiiE8NS7.d.mts +108 -0
- package/dist/index-BiiE8NS7.d.mts.map +1 -0
- package/dist/index-By6dNRc4.d.mts +277 -0
- package/dist/index-By6dNRc4.d.mts.map +1 -0
- package/dist/{index-BzYtgdX0.d.mts → index-CGiLfREk.d.mts} +123 -16
- package/dist/index-CGiLfREk.d.mts.map +1 -0
- package/dist/index-CUZn-ohG.d.mts +490 -0
- package/dist/index-CUZn-ohG.d.mts.map +1 -0
- package/dist/index-Cq2IFito.d.mts +121 -0
- package/dist/index-Cq2IFito.d.mts.map +1 -0
- package/dist/{index-B2l8_CiD.d.mts → index-DEAWPlcI.d.mts} +155 -216
- package/dist/index-DEAWPlcI.d.mts.map +1 -0
- package/dist/{index-C4v_3f3-.d.mts → index-DKS1g1oC.d.mts} +95 -42
- package/dist/index-DKS1g1oC.d.mts.map +1 -0
- package/dist/{index-jeC5jyRh.d.mts → index-DXbYlSnB.d.mts} +64 -101
- package/dist/index-DXbYlSnB.d.mts.map +1 -0
- package/dist/{index-CjZ95Dsv.d.mts → index-UzMbg1dh.d.mts} +188 -202
- package/dist/index-UzMbg1dh.d.mts.map +1 -0
- package/dist/index.d.mts +23 -16
- package/dist/index.mjs +1 -1
- package/dist/layer/index.d.mts +2 -0
- package/dist/layer/index.mjs +1 -0
- package/dist/layer-BttmtDrs.mjs +2 -0
- package/dist/layer-BttmtDrs.mjs.map +1 -0
- package/dist/layer.types-DgpCIsk_.d.mts +100 -0
- package/dist/layer.types-DgpCIsk_.d.mts.map +1 -0
- package/dist/multithread/index.d.mts +2 -0
- package/dist/multithread/index.mjs +1 -0
- package/dist/multithread-xUUh4eLn.mjs +19 -0
- package/dist/multithread-xUUh4eLn.mjs.map +1 -0
- package/dist/option/index.d.mts +2 -3
- package/dist/option/index.mjs +1 -1
- package/dist/option-Tfbo4wty.mjs +2 -0
- package/dist/option-Tfbo4wty.mjs.map +1 -0
- package/dist/option.types-D1mm0zUb.mjs +2 -0
- package/dist/option.types-D1mm0zUb.mjs.map +1 -0
- package/dist/{option.types-ClJiBTdg.d.mts → option.types-qPevEZQd.d.mts} +7 -12
- package/dist/option.types-qPevEZQd.d.mts.map +1 -0
- package/dist/order/index.d.mts +2 -0
- package/dist/order/index.mjs +1 -0
- package/dist/order-D5c4QChk.mjs +2 -0
- package/dist/order-D5c4QChk.mjs.map +1 -0
- package/dist/pipeable-COGyGMUV.mjs +2 -0
- package/dist/pipeable-COGyGMUV.mjs.map +1 -0
- package/dist/{pipeable-B4YJA56p.d.mts → pipeable-rfqacPxZ.d.mts} +2 -9
- package/dist/{pipeable-B4YJA56p.d.mts.map → pipeable-rfqacPxZ.d.mts.map} +1 -1
- package/dist/predicate/index.d.mts +2 -2
- package/dist/predicate/index.mjs +1 -1
- package/dist/predicate-DUhhQqWY.mjs +2 -0
- package/dist/predicate-DUhhQqWY.mjs.map +1 -0
- package/dist/provide/index.d.mts +2 -0
- package/dist/provide/index.mjs +1 -0
- package/dist/provide-C2cWOx2B.mjs +2 -0
- package/dist/provide-C2cWOx2B.mjs.map +1 -0
- package/dist/queue/index.d.mts +2 -0
- package/dist/queue/index.mjs +1 -0
- package/dist/queue-Sg6KJerl.mjs +2 -0
- package/dist/queue-Sg6KJerl.mjs.map +1 -0
- package/dist/queue.types-CD2LOu37.d.mts +36 -0
- package/dist/queue.types-CD2LOu37.d.mts.map +1 -0
- package/dist/result/index.d.mts +2 -3
- package/dist/result/index.mjs +1 -1
- package/dist/result-BEzV0DYC.mjs +2 -0
- package/dist/result-BEzV0DYC.mjs.map +1 -0
- package/dist/{result.types-HHDzgSTV.d.mts → result.types-_xDAei3-.d.mts} +5 -97
- package/dist/result.types-_xDAei3-.d.mts.map +1 -0
- package/dist/schedule/index.d.mts +2 -0
- package/dist/schedule/index.mjs +1 -0
- package/dist/schedule-C6tjcJ1O.mjs +2 -0
- package/dist/schedule-C6tjcJ1O.mjs.map +1 -0
- package/dist/schedule-DlX2Dg69.d.mts +144 -0
- package/dist/schedule-DlX2Dg69.d.mts.map +1 -0
- package/dist/scope/index.d.mts +2 -0
- package/dist/scope/index.mjs +1 -0
- package/dist/scope-CZdp4wKX.d.mts +79 -0
- package/dist/scope-CZdp4wKX.d.mts.map +1 -0
- package/dist/scope-D_kzd1nT.mjs +2 -0
- package/dist/scope-D_kzd1nT.mjs.map +1 -0
- package/dist/service/index.d.mts +2 -0
- package/dist/service/index.mjs +1 -0
- package/dist/service-3PYQTUdH.mjs +2 -0
- package/dist/service-3PYQTUdH.mjs.map +1 -0
- package/dist/service-DrXU7KJG.d.mts +69 -0
- package/dist/service-DrXU7KJG.d.mts.map +1 -0
- package/dist/service-resolution-C19smeaO.mjs +2 -0
- package/dist/service-resolution-C19smeaO.mjs.map +1 -0
- package/package.json +50 -12
- package/dist/adt-CkRcY_GA.mjs +0 -2
- package/dist/adt-CkRcY_GA.mjs.map +0 -1
- package/dist/apply-fn.types-0g_9eXRy.d.mts +0 -8
- package/dist/apply-fn.types-0g_9eXRy.d.mts.map +0 -1
- package/dist/brand-Gy0kW6-n.mjs +0 -2
- package/dist/brand-Gy0kW6-n.mjs.map +0 -1
- package/dist/data-C0_3MGwm.mjs +0 -2
- package/dist/data-C0_3MGwm.mjs.map +0 -1
- package/dist/discriminator.types-9PxvrZki.d.mts.map +0 -1
- package/dist/either-CPzK-s8W.mjs +0 -2
- package/dist/either-CPzK-s8W.mjs.map +0 -1
- package/dist/err/index.d.mts +0 -2
- package/dist/err/index.mjs +0 -1
- package/dist/err-3KpQ4pj9.mjs +0 -2
- package/dist/err-3KpQ4pj9.mjs.map +0 -1
- package/dist/flow/index.d.mts +0 -2
- package/dist/flow/index.mjs +0 -1
- package/dist/flow-CYjiodlC.mjs.map +0 -1
- package/dist/fx-vqywVJhV.mjs +0 -2
- package/dist/fx-vqywVJhV.mjs.map +0 -1
- package/dist/fx.types-CDVjDn_3.mjs.map +0 -1
- package/dist/index-8Ne4GdOG.d.mts +0 -288
- package/dist/index-8Ne4GdOG.d.mts.map +0 -1
- package/dist/index-B2l8_CiD.d.mts.map +0 -1
- package/dist/index-BOrJQBPO.d.mts +0 -80
- package/dist/index-BOrJQBPO.d.mts.map +0 -1
- package/dist/index-BsXtpnw-.d.mts +0 -225
- package/dist/index-BsXtpnw-.d.mts.map +0 -1
- package/dist/index-BzYtgdX0.d.mts.map +0 -1
- package/dist/index-C4v_3f3-.d.mts.map +0 -1
- package/dist/index-CjZ95Dsv.d.mts.map +0 -1
- package/dist/index-CklRfom5.d.mts.map +0 -1
- package/dist/index-DZdmFtjA.d.mts +0 -79
- package/dist/index-DZdmFtjA.d.mts.map +0 -1
- package/dist/index-a4MEBZZ1.d.mts +0 -850
- package/dist/index-a4MEBZZ1.d.mts.map +0 -1
- package/dist/index-jeC5jyRh.d.mts.map +0 -1
- package/dist/option-DawZC1cE.mjs +0 -2
- package/dist/option-DawZC1cE.mjs.map +0 -1
- package/dist/option.types-ClJiBTdg.d.mts.map +0 -1
- package/dist/pipe/index.d.mts +0 -2
- package/dist/pipe/index.mjs +0 -1
- package/dist/pipe-BPpJyZf7.mjs +0 -2
- package/dist/pipe-BPpJyZf7.mjs.map +0 -1
- package/dist/pipeable-BA0mXhs4.mjs +0 -2
- package/dist/pipeable-BA0mXhs4.mjs.map +0 -1
- package/dist/predicate-Cy_oHA1Q.mjs +0 -2
- package/dist/predicate-Cy_oHA1Q.mjs.map +0 -1
- package/dist/result-CgGYLp0L.mjs +0 -2
- package/dist/result-CgGYLp0L.mjs.map +0 -1
- package/dist/result.types-HHDzgSTV.d.mts.map +0 -1
- /package/dist/{chunk-DAexk1S7.mjs → chunk-C934ptG5.mjs} +0 -0
- /package/dist/{option-Bb-taghv.mjs → option-CBCwzF0L.mjs} +0 -0
- /package/dist/{result-fiJhwVGz.mjs → result-B5WbPg8C.mjs} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as Fx } from "./fx.types-
|
|
2
|
-
import { t as Pipeable } from "./pipeable-
|
|
3
|
-
import { t as Result } from "./result.types-
|
|
4
|
-
import { r as Option } from "./option.types-
|
|
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
|
|
116
|
-
<L1, L2
|
|
117
|
-
<L1, L2
|
|
118
|
-
<L1, L2
|
|
119
|
-
<L1, L2
|
|
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
|
|
140
|
-
<L1, R, L2
|
|
141
|
-
<L1, L2
|
|
142
|
-
<L1, L2
|
|
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
|
|
150
|
-
<L1, R1, L2
|
|
151
|
-
<L1, R1, L2
|
|
152
|
-
<L1, R1, L2
|
|
153
|
-
<L1, L2
|
|
154
|
-
<L1, L2
|
|
155
|
-
<L1, L2
|
|
156
|
-
<L1, L2
|
|
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
|
|
164
|
-
<L, A, B, L2
|
|
165
|
-
<A, B, L2
|
|
166
|
-
<A, B, L2
|
|
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
|
|
194
|
-
<L1, R, L2
|
|
195
|
-
<L1, L2
|
|
196
|
-
<L1, L2
|
|
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
|
|
204
|
-
<R, L2
|
|
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
|
|
229
|
-
Left: (value: L) => U
|
|
230
|
-
Right: (value: R) => U
|
|
231
|
-
}): U
|
|
232
|
-
<L, R, U
|
|
233
|
-
Left: (value: L) => U
|
|
234
|
-
Right: (value: R) => U
|
|
235
|
-
}): (either: Either$1<L, R>) => U
|
|
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
|
-
|
|
238
|
-
|
|
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
|
-
*
|
|
251
|
-
* // => { _tag: "Right", value: 42 }
|
|
228
|
+
* import { Either } from "@nicolastoulemont/std"
|
|
252
229
|
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
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
|
-
*
|
|
276
|
-
* // => { _tag: "Left", value: { source: "cache", data: cachedValue } }
|
|
251
|
+
* import { Either } from "@nicolastoulemont/std"
|
|
277
252
|
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
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
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
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
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
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
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
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
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
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
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
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
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
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
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
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
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
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
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
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
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
611
|
-
*
|
|
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
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
* //
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
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
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
* //
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
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
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
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
|
-
*
|
|
715
|
-
*
|
|
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
|
-
*
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
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
|
-
*
|
|
753
|
-
*
|
|
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
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
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
|
-
*
|
|
791
|
-
*
|
|
792
|
-
* fromNullable(
|
|
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
|
-
*
|
|
808
|
-
* // => right(5)
|
|
766
|
+
* import { Either } from "@nicolastoulemont/std"
|
|
809
767
|
*
|
|
810
|
-
* fromPredicate(
|
|
811
|
-
* // =>
|
|
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
|
-
* @
|
|
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
|
|
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 {
|
|
882
|
-
//# sourceMappingURL=index-
|
|
776
|
+
export { either_d_exports as t };
|
|
777
|
+
//# sourceMappingURL=index-B1-tBzc0.d.mts.map
|