@terrygonguet/utils 0.0.11 → 0.0.13
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/dist/functional.js +201 -164
- package/package.json +1 -1
- package/src/functional/index.ts +37 -2
- package/src/functional/maybe.ts +81 -61
- package/src/functional/result.ts +85 -69
- package/types/functional/index.d.ts +5 -0
- package/types/functional/maybe.d.ts +35 -19
- package/types/functional/result.d.ts +41 -20
package/dist/functional.js
CHANGED
|
@@ -1,229 +1,266 @@
|
|
|
1
|
-
var
|
|
2
|
-
var v = (
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
var S = Object.defineProperty;
|
|
2
|
+
var v = (r, e, t) => e in r ? S(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var u = (r, e, t) => (v(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
const a = "@terrygonguet/utils/functional/result", f = "@terrygonguet/utils/functional/result/Success", w = "@terrygonguet/utils/functional/result/Failure";
|
|
5
|
+
class l {
|
|
6
|
+
constructor(e) {
|
|
7
|
+
u(this, "value");
|
|
8
|
+
Object.defineProperties(this, {
|
|
9
|
+
$_kind: { value: a, enumerable: !1, writable: !1 },
|
|
10
|
+
$_variant: { value: f, enumerable: !1, writable: !1 },
|
|
11
|
+
value: { value: e, writable: !1 }
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
isSuccess() {
|
|
15
|
+
return !0;
|
|
16
|
+
}
|
|
17
|
+
isFailure() {
|
|
18
|
+
return !1;
|
|
19
|
+
}
|
|
20
|
+
merge(e) {
|
|
21
|
+
return e(this.value);
|
|
22
|
+
}
|
|
23
|
+
match(e) {
|
|
24
|
+
return e(this.value);
|
|
25
|
+
}
|
|
26
|
+
map(e) {
|
|
27
|
+
return new l(e(this.value));
|
|
28
|
+
}
|
|
29
|
+
flatMap(e) {
|
|
30
|
+
return e(this.value);
|
|
31
|
+
}
|
|
32
|
+
toJSON() {
|
|
33
|
+
return { $_kind: a, $_variant: f, value: this.value };
|
|
34
|
+
}
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
36
|
+
class g {
|
|
37
|
+
constructor(e) {
|
|
38
|
+
u(this, "reason");
|
|
39
|
+
Object.defineProperties(this, {
|
|
40
|
+
$_kind: { value: a, enumerable: !1, writable: !1 },
|
|
41
|
+
$_variant: { value: f, enumerable: !1, writable: !1 },
|
|
42
|
+
reason: { value: e, writable: !1 }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
isSuccess() {
|
|
46
|
+
return !1;
|
|
47
|
+
}
|
|
48
|
+
isFailure() {
|
|
49
|
+
return !0;
|
|
50
|
+
}
|
|
51
|
+
merge(e, t) {
|
|
52
|
+
return t(this.reason);
|
|
53
|
+
}
|
|
54
|
+
match(e, t) {
|
|
55
|
+
return t(this.reason);
|
|
56
|
+
}
|
|
57
|
+
map() {
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
flatMap() {
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
toJSON() {
|
|
64
|
+
return { $_kind: a, $_variant: w, reason: this.reason };
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
|
-
function y(
|
|
62
|
-
return e ?
|
|
67
|
+
function y(r, e) {
|
|
68
|
+
return e ? r.toResult(e) : r.toResult();
|
|
63
69
|
}
|
|
64
|
-
const
|
|
65
|
-
Success
|
|
66
|
-
|
|
67
|
-
try(t) {
|
|
68
|
-
return new k(t);
|
|
70
|
+
const c = {
|
|
71
|
+
Success(r) {
|
|
72
|
+
return new l(r);
|
|
69
73
|
},
|
|
70
|
-
|
|
71
|
-
return
|
|
74
|
+
Failure(r) {
|
|
75
|
+
return new g(r);
|
|
76
|
+
},
|
|
77
|
+
try(r) {
|
|
78
|
+
return new d(r);
|
|
79
|
+
},
|
|
80
|
+
fromPromise(r, e, t) {
|
|
81
|
+
return r.then(
|
|
82
|
+
b(e, this.Success),
|
|
83
|
+
b(t, this.Failure)
|
|
84
|
+
);
|
|
72
85
|
},
|
|
73
86
|
fromMaybe: y,
|
|
74
|
-
JSONReviver(
|
|
75
|
-
if ((e == null ? void 0 : e.$_kind) ==
|
|
76
|
-
const
|
|
77
|
-
return
|
|
87
|
+
JSONReviver(r, e) {
|
|
88
|
+
if ((e == null ? void 0 : e.$_kind) == a) {
|
|
89
|
+
const t = e == null ? void 0 : e.$_variant;
|
|
90
|
+
return t == f ? new l(e == null ? void 0 : e.value) : t == w ? new g(e == null ? void 0 : e.reason) : e;
|
|
78
91
|
} else
|
|
79
92
|
return e;
|
|
80
93
|
}
|
|
81
94
|
};
|
|
82
|
-
class
|
|
95
|
+
class d {
|
|
83
96
|
constructor(e) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.tryFn = e, this.catchFn =
|
|
97
|
+
u(this, "tryFn");
|
|
98
|
+
u(this, "catchFn");
|
|
99
|
+
this.tryFn = e, this.catchFn = $;
|
|
87
100
|
}
|
|
88
101
|
catch(e) {
|
|
89
102
|
return this.catchFn = e, this;
|
|
90
103
|
}
|
|
91
104
|
exec(e) {
|
|
92
105
|
try {
|
|
93
|
-
const
|
|
94
|
-
return e == null || e(
|
|
95
|
-
} catch (
|
|
96
|
-
const n =
|
|
106
|
+
const t = c.Success(this.tryFn());
|
|
107
|
+
return e == null || e(t), t;
|
|
108
|
+
} catch (t) {
|
|
109
|
+
const n = c.Failure(this.catchFn(t));
|
|
97
110
|
return e == null || e(n), n;
|
|
98
111
|
}
|
|
99
112
|
}
|
|
100
113
|
}
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
114
|
+
const h = "@terrygonguet/utils/functional/maybe", _ = "@terrygonguet/utils/functional/maybe/Some", p = "@terrygonguet/utils/functional/maybe/None";
|
|
115
|
+
class i {
|
|
116
|
+
constructor(e) {
|
|
117
|
+
u(this, "value");
|
|
118
|
+
Object.defineProperties(this, {
|
|
119
|
+
$_kind: { value: h, enumerable: !1, writable: !1 },
|
|
120
|
+
$_variant: { value: _, enumerable: !1, writable: !1 },
|
|
121
|
+
value: { value: e, writable: !1 }
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
isSome() {
|
|
125
|
+
return !0;
|
|
126
|
+
}
|
|
127
|
+
isNone() {
|
|
128
|
+
return !1;
|
|
129
|
+
}
|
|
130
|
+
orDefault() {
|
|
131
|
+
return this.value;
|
|
132
|
+
}
|
|
133
|
+
map(e) {
|
|
134
|
+
return new i(e(this.value));
|
|
135
|
+
}
|
|
136
|
+
flatMap(e) {
|
|
137
|
+
return e(this.value);
|
|
138
|
+
}
|
|
139
|
+
toResult() {
|
|
140
|
+
return c.Success(this.value);
|
|
141
|
+
}
|
|
142
|
+
toJSON() {
|
|
143
|
+
return { $_kind: h, $_variant: _, value: this.value };
|
|
144
|
+
}
|
|
129
145
|
}
|
|
130
|
-
|
|
131
|
-
{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
class k {
|
|
147
|
+
constructor() {
|
|
148
|
+
}
|
|
149
|
+
isSome() {
|
|
150
|
+
return !1;
|
|
151
|
+
}
|
|
152
|
+
isNone() {
|
|
153
|
+
return !0;
|
|
154
|
+
}
|
|
155
|
+
orDefault(e) {
|
|
156
|
+
return e;
|
|
157
|
+
}
|
|
158
|
+
map() {
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
flatMap() {
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
toResult(e) {
|
|
165
|
+
return e ? c.Failure(e == null ? void 0 : e()) : c.Failure(void 0);
|
|
166
|
+
}
|
|
167
|
+
toJSON() {
|
|
168
|
+
return { $_kind: h, $_variant: p };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const N = new k(), s = {
|
|
172
|
+
Some(r) {
|
|
173
|
+
return new i(r);
|
|
139
174
|
},
|
|
140
|
-
{
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
Some: l,
|
|
146
|
-
None: u,
|
|
147
|
-
from(t) {
|
|
148
|
-
switch (t) {
|
|
175
|
+
None() {
|
|
176
|
+
return N;
|
|
177
|
+
},
|
|
178
|
+
from(r) {
|
|
179
|
+
switch (r) {
|
|
149
180
|
case null:
|
|
150
181
|
case void 0:
|
|
151
|
-
return
|
|
182
|
+
return this.None();
|
|
152
183
|
default:
|
|
153
|
-
return
|
|
184
|
+
return new i(r);
|
|
154
185
|
}
|
|
155
186
|
},
|
|
156
187
|
/**
|
|
157
188
|
* CAUTION: this method swallows errors and simply returns None!
|
|
158
189
|
* Use `Result.fromPromise()` if you need error details.
|
|
159
190
|
*/
|
|
160
|
-
fromPromise(
|
|
161
|
-
return
|
|
191
|
+
fromPromise(r, e = $) {
|
|
192
|
+
return r.then(b(e, s.from), M(this.None()));
|
|
162
193
|
},
|
|
163
|
-
JSONReviver(
|
|
164
|
-
if ((e == null ? void 0 : e.$_kind) ==
|
|
165
|
-
const
|
|
166
|
-
return
|
|
194
|
+
JSONReviver(r, e) {
|
|
195
|
+
if ((e == null ? void 0 : e.$_kind) == h) {
|
|
196
|
+
const t = e == null ? void 0 : e.$_variant;
|
|
197
|
+
return t == _ ? new i(e == null ? void 0 : e.value) : t == p ? s.None() : e;
|
|
167
198
|
} else
|
|
168
199
|
return e;
|
|
169
200
|
}
|
|
170
201
|
};
|
|
171
|
-
var
|
|
172
|
-
function
|
|
202
|
+
var b = F;
|
|
203
|
+
function F(r, e) {
|
|
173
204
|
if (!arguments.length)
|
|
174
205
|
throw new Error(
|
|
175
206
|
"expected at least one (and probably more) function arguments"
|
|
176
207
|
);
|
|
177
|
-
var
|
|
208
|
+
var t = arguments;
|
|
178
209
|
return function() {
|
|
179
|
-
for (var n =
|
|
180
|
-
n =
|
|
210
|
+
for (var n = t[0].apply(this, arguments), o = t.length, m = 1; m < o; m++)
|
|
211
|
+
n = t[m].call(this, n);
|
|
181
212
|
return n;
|
|
182
213
|
};
|
|
183
214
|
}
|
|
184
|
-
var J =
|
|
185
|
-
function
|
|
215
|
+
var J = x;
|
|
216
|
+
function x(r, ...e) {
|
|
186
217
|
if (!arguments.length)
|
|
187
218
|
throw new Error("expected one value argument and least one function argument");
|
|
188
219
|
if (!e.length)
|
|
189
220
|
throw new Error(
|
|
190
221
|
"expected at least one (and probably more) function arguments"
|
|
191
222
|
);
|
|
192
|
-
for (var
|
|
193
|
-
|
|
194
|
-
return r;
|
|
195
|
-
}
|
|
196
|
-
function S(t) {
|
|
223
|
+
for (var t = e[0](r), n = e.length, o = 1; o < n; o++)
|
|
224
|
+
t = e[o](t);
|
|
197
225
|
return t;
|
|
198
226
|
}
|
|
199
|
-
function
|
|
200
|
-
return
|
|
227
|
+
function $(r) {
|
|
228
|
+
return r;
|
|
229
|
+
}
|
|
230
|
+
function M(r) {
|
|
231
|
+
return () => r;
|
|
201
232
|
}
|
|
202
|
-
function
|
|
203
|
-
return typeof
|
|
233
|
+
function j(r, e) {
|
|
234
|
+
return typeof r == "number" ? (t) => s.from(t.at(r)) : s.from(r.at(e));
|
|
204
235
|
}
|
|
205
|
-
function
|
|
206
|
-
return typeof
|
|
236
|
+
function E(r, e) {
|
|
237
|
+
return typeof r == "function" ? (t) => s.from(t.find(r)) : s.from(r.find(e));
|
|
207
238
|
}
|
|
208
|
-
function O(
|
|
209
|
-
if (typeof
|
|
210
|
-
return (
|
|
211
|
-
const n =
|
|
212
|
-
return n == -1 ? s.None : s.Some(n);
|
|
239
|
+
function O(r, e) {
|
|
240
|
+
if (typeof r == "function")
|
|
241
|
+
return (t) => {
|
|
242
|
+
const n = t.findIndex(r);
|
|
243
|
+
return n == -1 ? s.None() : s.Some(n);
|
|
213
244
|
};
|
|
214
245
|
{
|
|
215
|
-
const
|
|
216
|
-
return
|
|
246
|
+
const t = r.findIndex(e);
|
|
247
|
+
return t == -1 ? s.None() : s.Some(t);
|
|
217
248
|
}
|
|
218
249
|
}
|
|
250
|
+
function C(r, ...e) {
|
|
251
|
+
for (const t of e)
|
|
252
|
+
r = r == null ? void 0 : r[t];
|
|
253
|
+
return s.from(r);
|
|
254
|
+
}
|
|
219
255
|
export {
|
|
220
256
|
s as Maybe,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
257
|
+
c as Result,
|
|
258
|
+
j as at,
|
|
259
|
+
b as compose,
|
|
224
260
|
M as constant,
|
|
225
|
-
|
|
261
|
+
E as find,
|
|
226
262
|
O as findIndex,
|
|
227
|
-
|
|
228
|
-
J as pipe
|
|
263
|
+
$ as identity,
|
|
264
|
+
J as pipe,
|
|
265
|
+
C as prop
|
|
229
266
|
};
|
package/package.json
CHANGED
package/src/functional/index.ts
CHANGED
|
@@ -36,10 +36,45 @@ export function findIndex<T>(dataOrPredicate: T[] | Predicate<T>, predicate?: Pr
|
|
|
36
36
|
if (typeof dataOrPredicate == "function") {
|
|
37
37
|
return (data: T[]) => {
|
|
38
38
|
const idx = data.findIndex(dataOrPredicate)
|
|
39
|
-
return idx == -1 ? Maybe.None : Maybe.Some(idx)
|
|
39
|
+
return idx == -1 ? Maybe.None<number>() : Maybe.Some(idx)
|
|
40
40
|
}
|
|
41
41
|
} else {
|
|
42
42
|
const idx = dataOrPredicate.findIndex(predicate!)
|
|
43
|
-
return idx == -1 ? Maybe.None : Maybe.Some(idx)
|
|
43
|
+
return idx == -1 ? Maybe.None<number>() : Maybe.Some(idx)
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
export function prop<T extends {}, K1 extends keyof T = keyof T>(data: T, key1: K1): Maybe<T[K1]>
|
|
48
|
+
export function prop<
|
|
49
|
+
T extends {},
|
|
50
|
+
K1 extends keyof T = keyof T,
|
|
51
|
+
K2 extends keyof T[K1] = keyof T[K1],
|
|
52
|
+
>(data: T, key1: K1, key2: K2): Maybe<T[K1][K2]>
|
|
53
|
+
export function prop<
|
|
54
|
+
T extends {},
|
|
55
|
+
K1 extends keyof T = keyof T,
|
|
56
|
+
K2 extends keyof T[K1] = keyof T[K1],
|
|
57
|
+
K3 extends keyof T[K1][K2] = keyof T[K1][K2],
|
|
58
|
+
>(data: T, key1: K1, key2: K2, key: K3): Maybe<T[K1][K2][K3]>
|
|
59
|
+
export function prop<
|
|
60
|
+
T extends {},
|
|
61
|
+
K1 extends keyof T = keyof T,
|
|
62
|
+
K2 extends keyof T[K1] = keyof T[K1],
|
|
63
|
+
K3 extends keyof T[K1][K2] = keyof T[K1][K2],
|
|
64
|
+
K4 extends keyof T[K1][K2][K3] = keyof T[K1][K2][K3],
|
|
65
|
+
>(data: T, key1: K1, key2: K2, key: K3, key4: K4): Maybe<T[K1][K2][K3][K4]>
|
|
66
|
+
export function prop<
|
|
67
|
+
T extends {},
|
|
68
|
+
K1 extends keyof T = keyof T,
|
|
69
|
+
K2 extends keyof T[K1] = keyof T[K1],
|
|
70
|
+
K3 extends keyof T[K1][K2] = keyof T[K1][K2],
|
|
71
|
+
K4 extends keyof T[K1][K2][K3] = keyof T[K1][K2][K3],
|
|
72
|
+
K5 extends keyof T[K1][K2][K3][K4] = keyof T[K1][K2][K3][K4],
|
|
73
|
+
>(data: T, key1: K1, key2: K2, key: K3, key4: K4, key5: K5): Maybe<T[K1][K2][K3][K4][K5]>
|
|
74
|
+
|
|
75
|
+
export function prop(data: any, ...path: string[]) {
|
|
76
|
+
for (const key of path) {
|
|
77
|
+
data = data?.[key]
|
|
78
|
+
}
|
|
79
|
+
return Maybe.from(data)
|
|
80
|
+
}
|
package/src/functional/maybe.ts
CHANGED
|
@@ -1,80 +1,98 @@
|
|
|
1
1
|
import { compose, constant, identity } from "./index.ts"
|
|
2
2
|
import { Result } from "./result.ts"
|
|
3
3
|
|
|
4
|
-
interface API<T> {
|
|
5
|
-
isSome(this: Maybe<T>): this is Some<T>
|
|
6
|
-
isNone(this: Maybe<T>): this is None<T>
|
|
7
|
-
orDefault(this: Maybe<T>, defaultValue: T): T
|
|
8
|
-
map<U>(this: Maybe<T>, f: (value: T) => U): Maybe<U>
|
|
9
|
-
flatMap<U>(this: Maybe<T>, f: (value: T) => Maybe<U>): Maybe<U>
|
|
10
|
-
toResult(this: Maybe<T>): Result<T, undefined>
|
|
11
|
-
toResult<U>(this: Maybe<T>, mapNone: () => U): Result<T, U>
|
|
12
|
-
toJSON(this: Maybe<T>): Object
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type Some<T> = { value: T } & API<T>
|
|
16
|
-
export type None<T> = API<T>
|
|
17
|
-
export type Maybe<T> = Some<T> | None<T>
|
|
18
|
-
|
|
19
4
|
const $_kind = "@terrygonguet/utils/functional/maybe"
|
|
20
5
|
const $_variant_Some = "@terrygonguet/utils/functional/maybe/Some"
|
|
21
6
|
const $_variant_None = "@terrygonguet/utils/functional/maybe/None"
|
|
22
7
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
toJSON(this: Some<T>) {
|
|
41
|
-
return { $_kind, $_variant: $_variant_Some, value: this.value }
|
|
42
|
-
},
|
|
43
|
-
} satisfies API<T>,
|
|
44
|
-
{
|
|
8
|
+
export interface Maybe<T> {
|
|
9
|
+
isSome(): this is Some<T>
|
|
10
|
+
isNone(): this is None<T>
|
|
11
|
+
orDefault(defaultValue: T): T
|
|
12
|
+
map<U>(f: (value: T) => U): Maybe<U>
|
|
13
|
+
flatMap<U>(f: (value: T) => Maybe<U>): Maybe<U>
|
|
14
|
+
toResult(): Result<T, undefined>
|
|
15
|
+
toResult<U>(mapNone: () => U): Result<T, U>
|
|
16
|
+
toJSON(): Object
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class Some<T> implements Maybe<T> {
|
|
20
|
+
value!: T
|
|
21
|
+
|
|
22
|
+
constructor(value: T) {
|
|
23
|
+
Object.defineProperties(this, {
|
|
45
24
|
$_kind: { value: $_kind, enumerable: false, writable: false },
|
|
46
25
|
$_variant: { value: $_variant_Some, enumerable: false, writable: false },
|
|
47
26
|
value: { value, writable: false },
|
|
48
|
-
}
|
|
49
|
-
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
isSome(): true {
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
isNone(): false {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
orDefault() {
|
|
37
|
+
return this.value
|
|
38
|
+
}
|
|
39
|
+
map<U>(f: (value: T) => U) {
|
|
40
|
+
return new Some(f(this.value))
|
|
41
|
+
}
|
|
42
|
+
flatMap<U>(f: (value: T) => Maybe<U>) {
|
|
43
|
+
return f(this.value)
|
|
44
|
+
}
|
|
45
|
+
toResult<U>(): Result<T, U> {
|
|
46
|
+
return Result.Success(this.value)
|
|
47
|
+
}
|
|
48
|
+
toJSON(): Object {
|
|
49
|
+
return { $_kind, $_variant: $_variant_Some, value: this.value }
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
class None<T> implements Maybe<T> {
|
|
54
|
+
constructor() {}
|
|
55
|
+
|
|
56
|
+
isSome(): false {
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
isNone(): true {
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
orDefault(defaultValue: T) {
|
|
63
|
+
return defaultValue
|
|
64
|
+
}
|
|
65
|
+
map<U>() {
|
|
66
|
+
return this as unknown as Maybe<U>
|
|
67
|
+
}
|
|
68
|
+
flatMap<U>() {
|
|
69
|
+
return this as unknown as Maybe<U>
|
|
70
|
+
}
|
|
71
|
+
toResult(): Result<T, undefined>
|
|
72
|
+
toResult<U>(mapNone: () => U): Result<T, U>
|
|
73
|
+
toResult<U>(mapNone?: () => U) {
|
|
74
|
+
return mapNone ? Result.Failure<T, U>(mapNone?.()) : Result.Failure<T, undefined>(undefined)
|
|
75
|
+
}
|
|
76
|
+
toJSON(): Object {
|
|
77
|
+
return { $_kind, $_variant: $_variant_None }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
67
80
|
|
|
81
|
+
const none = new None()
|
|
68
82
|
export const Maybe = {
|
|
69
|
-
Some
|
|
70
|
-
|
|
83
|
+
Some<T>(value: T): Maybe<T> {
|
|
84
|
+
return new Some(value)
|
|
85
|
+
},
|
|
86
|
+
None<T>() {
|
|
87
|
+
return none as Maybe<T>
|
|
88
|
+
},
|
|
71
89
|
from<T>(value: T | undefined | null): Maybe<T> {
|
|
72
90
|
switch (value) {
|
|
73
91
|
case null:
|
|
74
92
|
case undefined:
|
|
75
|
-
return None
|
|
93
|
+
return this.None()
|
|
76
94
|
default:
|
|
77
|
-
return Some(value!)
|
|
95
|
+
return new Some(value!)
|
|
78
96
|
}
|
|
79
97
|
},
|
|
80
98
|
/**
|
|
@@ -82,14 +100,16 @@ export const Maybe = {
|
|
|
82
100
|
* Use `Result.fromPromise()` if you need error details.
|
|
83
101
|
*/
|
|
84
102
|
fromPromise<T>(promise: Promise<T>, onResolve: (value: T) => T = identity): Promise<Maybe<T>> {
|
|
85
|
-
return promise.then(compose(onResolve, Maybe.from), constant(None))
|
|
103
|
+
return promise.then(compose(onResolve, Maybe.from), constant(this.None()))
|
|
86
104
|
},
|
|
87
105
|
JSONReviver(_key: string, value: any) {
|
|
88
106
|
if (value?.$_kind == $_kind) {
|
|
89
107
|
const $_variant = value?.$_variant
|
|
90
|
-
if ($_variant == $_variant_Some) return Some<unknown>(value?.value)
|
|
91
|
-
else if ($_variant == $_variant_None) return None
|
|
108
|
+
if ($_variant == $_variant_Some) return new Some<unknown>(value?.value)
|
|
109
|
+
else if ($_variant == $_variant_None) return Maybe.None()
|
|
92
110
|
else return value
|
|
93
111
|
} else return value
|
|
94
112
|
},
|
|
95
113
|
}
|
|
114
|
+
|
|
115
|
+
export type { Some, None }
|
package/src/functional/result.ts
CHANGED
|
@@ -1,80 +1,86 @@
|
|
|
1
1
|
import { compose, identity } from "./index.ts"
|
|
2
2
|
import { Maybe } from "./maybe.ts"
|
|
3
3
|
|
|
4
|
-
interface API<S, F> {
|
|
5
|
-
isSuccess(this: Result<S, F>): this is Success<S, F>
|
|
6
|
-
isFailure(this: Result<S, F>): this is Failure<S, F>
|
|
7
|
-
merge<T>(this: Result<S, F>, f: (value: S) => T, g: (reason: F) => T): T
|
|
8
|
-
match(this: Result<S, F>, successFn: (value: S) => void, failureFn: (reason: F) => void): void
|
|
9
|
-
map<S2>(this: Result<S, F>, f: (value: S) => S2): Result<S2, F>
|
|
10
|
-
flatMap<S2, F2>(this: Result<S, F>, f: (value: S) => Result<S2, F | F2>): Result<S2, F | F2>
|
|
11
|
-
toJSON(this: Result<S, F>): Object
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type Success<S, F> = { value: S } & API<S, F>
|
|
15
|
-
export type Failure<S, F> = { reason: F } & API<S, F>
|
|
16
|
-
export type Result<S, F> = Success<S, F> | Failure<S, F>
|
|
17
|
-
|
|
18
4
|
const $_kind = "@terrygonguet/utils/functional/result"
|
|
19
5
|
const $_variant_Success = "@terrygonguet/utils/functional/result/Success"
|
|
20
6
|
const $_variant_Failure = "@terrygonguet/utils/functional/result/Failure"
|
|
21
7
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return f(this.value)
|
|
38
|
-
},
|
|
39
|
-
toJSON(this: Success<S, F>) {
|
|
40
|
-
return { $_kind, $_variant: $_variant_Success, value: this.value }
|
|
41
|
-
},
|
|
42
|
-
} satisfies API<S, F>,
|
|
43
|
-
{
|
|
8
|
+
export interface Result<S, F> {
|
|
9
|
+
isSuccess(): this is Success<S, F>
|
|
10
|
+
isFailure(): this is Failure<S, F>
|
|
11
|
+
merge<T>(whenSuccess: (value: S) => T, whenFailure: (reason: F) => T): T
|
|
12
|
+
match(onSuccess: (value: S) => void, onFailure: (reason: F) => void): void
|
|
13
|
+
map<S2>(f: (value: S) => S2): Result<S2, F>
|
|
14
|
+
flatMap<S2, F2>(f: (value: S) => Result<S2, F | F2>): Result<S2, F | F2>
|
|
15
|
+
toJSON(): Object
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class Success<S, F> implements Result<S, F> {
|
|
19
|
+
value!: S
|
|
20
|
+
|
|
21
|
+
constructor(value: S) {
|
|
22
|
+
Object.defineProperties(this, {
|
|
44
23
|
$_kind: { value: $_kind, enumerable: false, writable: false },
|
|
45
24
|
$_variant: { value: $_variant_Success, enumerable: false, writable: false },
|
|
46
25
|
value: { value, writable: false },
|
|
47
|
-
}
|
|
48
|
-
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
isSuccess(): true {
|
|
30
|
+
return true
|
|
31
|
+
}
|
|
32
|
+
isFailure(): false {
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
merge<T>(whenSuccess: (value: S) => T) {
|
|
36
|
+
return whenSuccess(this.value)
|
|
37
|
+
}
|
|
38
|
+
match(onSuccess: (value: S) => void) {
|
|
39
|
+
return onSuccess(this.value)
|
|
40
|
+
}
|
|
41
|
+
map<S2>(f: (value: S) => S2) {
|
|
42
|
+
return new Success<S2, F>(f(this.value))
|
|
43
|
+
}
|
|
44
|
+
flatMap<S2, F2>(f: (value: S) => Result<S2, F2>): Result<S2, F | F2> {
|
|
45
|
+
return f(this.value)
|
|
46
|
+
}
|
|
47
|
+
toJSON(this: Success<S, F>) {
|
|
48
|
+
return { $_kind, $_variant: $_variant_Success, value: this.value }
|
|
49
|
+
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
merge<T>(this: Failure<S, F>, _: (value: S) => T, g: (reason: F) => T) {
|
|
57
|
-
return g(this.reason)
|
|
58
|
-
},
|
|
59
|
-
match(this: Failure<S, F>, _, failureFn) {
|
|
60
|
-
return failureFn(this.reason)
|
|
61
|
-
},
|
|
62
|
-
map<S2>(this: Failure<S, F>) {
|
|
63
|
-
return this as unknown as Result<S2, F>
|
|
64
|
-
},
|
|
65
|
-
flatMap<S2, F2>(this: Failure<S, F>) {
|
|
66
|
-
return this as unknown as Result<S2, F | F2>
|
|
67
|
-
},
|
|
68
|
-
toJSON(this: Failure<S, F>) {
|
|
69
|
-
return { $_kind, $_variant: $_variant_Failure, reason: this.reason }
|
|
70
|
-
},
|
|
71
|
-
} satisfies API<S, F>,
|
|
72
|
-
{
|
|
52
|
+
class Failure<S, F> implements Result<S, F> {
|
|
53
|
+
reason!: F
|
|
54
|
+
|
|
55
|
+
constructor(reason: F) {
|
|
56
|
+
Object.defineProperties(this, {
|
|
73
57
|
$_kind: { value: $_kind, enumerable: false, writable: false },
|
|
74
58
|
$_variant: { value: $_variant_Success, enumerable: false, writable: false },
|
|
75
59
|
reason: { value: reason, writable: false },
|
|
76
|
-
}
|
|
77
|
-
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
isSuccess(): false {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
isFailure(): true {
|
|
67
|
+
return true
|
|
68
|
+
}
|
|
69
|
+
merge<T>(_: (value: S) => T, whenFailure: (reason: F) => T) {
|
|
70
|
+
return whenFailure(this.reason)
|
|
71
|
+
}
|
|
72
|
+
match(_: (value: S) => void, onFailure: (reason: F) => void) {
|
|
73
|
+
return onFailure(this.reason)
|
|
74
|
+
}
|
|
75
|
+
map<S2>() {
|
|
76
|
+
return this as unknown as Result<S2, F>
|
|
77
|
+
}
|
|
78
|
+
flatMap<S2, F2>() {
|
|
79
|
+
return this as unknown as Result<S2, F | F2>
|
|
80
|
+
}
|
|
81
|
+
toJSON() {
|
|
82
|
+
return { $_kind, $_variant: $_variant_Failure, reason: this.reason }
|
|
83
|
+
}
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
function resultFromMaybe<S>(maybe: Maybe<S>): Result<S, undefined>
|
|
@@ -84,8 +90,12 @@ function resultFromMaybe<S, F>(maybe: Maybe<S>, mapNone?: () => F) {
|
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
export const Result = {
|
|
87
|
-
Success,
|
|
88
|
-
|
|
93
|
+
Success<S, F>(value: S): Result<S, F> {
|
|
94
|
+
return new Success<S, F>(value)
|
|
95
|
+
},
|
|
96
|
+
Failure<S, F>(reason: F): Result<S, F> {
|
|
97
|
+
return new Failure<S, F>(reason)
|
|
98
|
+
},
|
|
89
99
|
try<S, F>(tryFn: () => S) {
|
|
90
100
|
return new TryCatch<S, F>(tryFn)
|
|
91
101
|
},
|
|
@@ -94,14 +104,18 @@ export const Result = {
|
|
|
94
104
|
onResolve: (value: S) => S,
|
|
95
105
|
onReject: (reason: unknown) => F,
|
|
96
106
|
): Promise<Result<S, F>> {
|
|
97
|
-
return promise.then(
|
|
107
|
+
return promise.then(
|
|
108
|
+
compose(onResolve, this.Success<S, F>),
|
|
109
|
+
compose(onReject, this.Failure<S, F>),
|
|
110
|
+
)
|
|
98
111
|
},
|
|
99
112
|
fromMaybe: resultFromMaybe,
|
|
100
113
|
JSONReviver(_key: string, value: any) {
|
|
101
114
|
if (value?.$_kind == $_kind) {
|
|
102
115
|
const $_variant = value?.$_variant
|
|
103
|
-
if ($_variant == $_variant_Success) return Success<unknown, unknown>(value?.value)
|
|
104
|
-
else if ($_variant == $_variant_Failure)
|
|
116
|
+
if ($_variant == $_variant_Success) return new Success<unknown, unknown>(value?.value)
|
|
117
|
+
else if ($_variant == $_variant_Failure)
|
|
118
|
+
return new Failure<unknown, unknown>(value?.reason)
|
|
105
119
|
else return value
|
|
106
120
|
} else return value
|
|
107
121
|
},
|
|
@@ -123,13 +137,15 @@ class TryCatch<S, F> {
|
|
|
123
137
|
|
|
124
138
|
exec(finallyFn?: (result: Result<S, F>) => void): Result<S, F> {
|
|
125
139
|
try {
|
|
126
|
-
const result = Success<S, F>(this.tryFn())
|
|
140
|
+
const result = Result.Success<S, F>(this.tryFn())
|
|
127
141
|
finallyFn?.(result)
|
|
128
142
|
return result
|
|
129
143
|
} catch (error) {
|
|
130
|
-
const result = Failure<S, F>(this.catchFn(error))
|
|
144
|
+
const result = Result.Failure<S, F>(this.catchFn(error))
|
|
131
145
|
finallyFn?.(result)
|
|
132
146
|
return result
|
|
133
147
|
}
|
|
134
148
|
}
|
|
135
149
|
}
|
|
150
|
+
|
|
151
|
+
export type { Success, Failure }
|
|
@@ -12,3 +12,8 @@ export declare function find<T>(predicate: Predicate<T>): (data: T[]) => Maybe<T
|
|
|
12
12
|
export declare function find<T>(data: T[], predicate: Predicate<T>): Maybe<T>;
|
|
13
13
|
export declare function findIndex<T>(predicate: Predicate<T>): (data: T[]) => Maybe<number>;
|
|
14
14
|
export declare function findIndex<T>(data: T[], predicate: Predicate<T>): Maybe<number>;
|
|
15
|
+
export declare function prop<T extends {}, K1 extends keyof T = keyof T>(data: T, key1: K1): Maybe<T[K1]>;
|
|
16
|
+
export declare function prop<T extends {}, K1 extends keyof T = keyof T, K2 extends keyof T[K1] = keyof T[K1]>(data: T, key1: K1, key2: K2): Maybe<T[K1][K2]>;
|
|
17
|
+
export declare function prop<T extends {}, K1 extends keyof T = keyof T, K2 extends keyof T[K1] = keyof T[K1], K3 extends keyof T[K1][K2] = keyof T[K1][K2]>(data: T, key1: K1, key2: K2, key: K3): Maybe<T[K1][K2][K3]>;
|
|
18
|
+
export declare function prop<T extends {}, K1 extends keyof T = keyof T, K2 extends keyof T[K1] = keyof T[K1], K3 extends keyof T[K1][K2] = keyof T[K1][K2], K4 extends keyof T[K1][K2][K3] = keyof T[K1][K2][K3]>(data: T, key1: K1, key2: K2, key: K3, key4: K4): Maybe<T[K1][K2][K3][K4]>;
|
|
19
|
+
export declare function prop<T extends {}, K1 extends keyof T = keyof T, K2 extends keyof T[K1] = keyof T[K1], K3 extends keyof T[K1][K2] = keyof T[K1][K2], K4 extends keyof T[K1][K2][K3] = keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4] = keyof T[K1][K2][K3][K4]>(data: T, key1: K1, key2: K2, key: K3, key4: K4, key5: K5): Maybe<T[K1][K2][K3][K4][K5]>;
|
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
import { Result } from "./result.ts";
|
|
2
|
-
interface
|
|
3
|
-
isSome(
|
|
4
|
-
isNone(
|
|
5
|
-
orDefault(
|
|
6
|
-
map<U>(
|
|
7
|
-
flatMap<U>(
|
|
8
|
-
toResult(
|
|
9
|
-
toResult<U>(
|
|
10
|
-
toJSON(
|
|
2
|
+
export interface Maybe<T> {
|
|
3
|
+
isSome(): this is Some<T>;
|
|
4
|
+
isNone(): this is None<T>;
|
|
5
|
+
orDefault(defaultValue: T): T;
|
|
6
|
+
map<U>(f: (value: T) => U): Maybe<U>;
|
|
7
|
+
flatMap<U>(f: (value: T) => Maybe<U>): Maybe<U>;
|
|
8
|
+
toResult(): Result<T, undefined>;
|
|
9
|
+
toResult<U>(mapNone: () => U): Result<T, U>;
|
|
10
|
+
toJSON(): Object;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
declare class Some<T> implements Maybe<T> {
|
|
13
13
|
value: T;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
constructor(value: T);
|
|
15
|
+
isSome(): true;
|
|
16
|
+
isNone(): false;
|
|
17
|
+
orDefault(): T;
|
|
18
|
+
map<U>(f: (value: T) => U): Some<U>;
|
|
19
|
+
flatMap<U>(f: (value: T) => Maybe<U>): Maybe<U>;
|
|
20
|
+
toResult<U>(): Result<T, U>;
|
|
21
|
+
toJSON(): Object;
|
|
22
|
+
}
|
|
23
|
+
declare class None<T> implements Maybe<T> {
|
|
24
|
+
constructor();
|
|
25
|
+
isSome(): false;
|
|
26
|
+
isNone(): true;
|
|
27
|
+
orDefault(defaultValue: T): T;
|
|
28
|
+
map<U>(): Maybe<U>;
|
|
29
|
+
flatMap<U>(): Maybe<U>;
|
|
30
|
+
toResult(): Result<T, undefined>;
|
|
31
|
+
toResult<U>(mapNone: () => U): Result<T, U>;
|
|
32
|
+
toJSON(): Object;
|
|
33
|
+
}
|
|
18
34
|
export declare const Maybe: {
|
|
19
|
-
Some:
|
|
20
|
-
None:
|
|
21
|
-
from<
|
|
35
|
+
Some<T>(value: T): Maybe<T>;
|
|
36
|
+
None<T_1>(): Maybe<T_1>;
|
|
37
|
+
from<T_2>(value: T_2 | null | undefined): Maybe<T_2>;
|
|
22
38
|
/**
|
|
23
39
|
* CAUTION: this method swallows errors and simply returns None!
|
|
24
40
|
* Use `Result.fromPromise()` if you need error details.
|
|
25
41
|
*/
|
|
26
|
-
fromPromise<
|
|
42
|
+
fromPromise<T_3>(promise: Promise<T_3>, onResolve?: (value: T_3) => T_3): Promise<Maybe<T_3>>;
|
|
27
43
|
JSONReviver(_key: string, value: any): any;
|
|
28
44
|
};
|
|
29
|
-
export {};
|
|
45
|
+
export type { Some, None };
|
|
@@ -1,29 +1,50 @@
|
|
|
1
1
|
import { Maybe } from "./maybe.ts";
|
|
2
|
-
interface
|
|
3
|
-
isSuccess(
|
|
4
|
-
isFailure(
|
|
5
|
-
merge<T>(
|
|
6
|
-
match(
|
|
7
|
-
map<S2>(
|
|
8
|
-
flatMap<S2, F2>(
|
|
9
|
-
toJSON(
|
|
2
|
+
export interface Result<S, F> {
|
|
3
|
+
isSuccess(): this is Success<S, F>;
|
|
4
|
+
isFailure(): this is Failure<S, F>;
|
|
5
|
+
merge<T>(whenSuccess: (value: S) => T, whenFailure: (reason: F) => T): T;
|
|
6
|
+
match(onSuccess: (value: S) => void, onFailure: (reason: F) => void): void;
|
|
7
|
+
map<S2>(f: (value: S) => S2): Result<S2, F>;
|
|
8
|
+
flatMap<S2, F2>(f: (value: S) => Result<S2, F | F2>): Result<S2, F | F2>;
|
|
9
|
+
toJSON(): Object;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
declare class Success<S, F> implements Result<S, F> {
|
|
12
12
|
value: S;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
constructor(value: S);
|
|
14
|
+
isSuccess(): true;
|
|
15
|
+
isFailure(): false;
|
|
16
|
+
merge<T>(whenSuccess: (value: S) => T): T;
|
|
17
|
+
match(onSuccess: (value: S) => void): void;
|
|
18
|
+
map<S2>(f: (value: S) => S2): Success<S2, F>;
|
|
19
|
+
flatMap<S2, F2>(f: (value: S) => Result<S2, F2>): Result<S2, F | F2>;
|
|
20
|
+
toJSON(this: Success<S, F>): {
|
|
21
|
+
$_kind: string;
|
|
22
|
+
$_variant: string;
|
|
23
|
+
value: S;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
declare class Failure<S, F> implements Result<S, F> {
|
|
15
27
|
reason: F;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
constructor(reason: F);
|
|
29
|
+
isSuccess(): false;
|
|
30
|
+
isFailure(): true;
|
|
31
|
+
merge<T>(_: (value: S) => T, whenFailure: (reason: F) => T): T;
|
|
32
|
+
match(_: (value: S) => void, onFailure: (reason: F) => void): void;
|
|
33
|
+
map<S2>(): Result<S2, F>;
|
|
34
|
+
flatMap<S2, F2>(): Result<S2, F | F2>;
|
|
35
|
+
toJSON(): {
|
|
36
|
+
$_kind: string;
|
|
37
|
+
$_variant: string;
|
|
38
|
+
reason: F;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
20
41
|
declare function resultFromMaybe<S>(maybe: Maybe<S>): Result<S, undefined>;
|
|
21
42
|
declare function resultFromMaybe<S, F>(maybe: Maybe<S>, mapNone: () => F): Result<S, F>;
|
|
22
43
|
export declare const Result: {
|
|
23
|
-
Success:
|
|
24
|
-
Failure:
|
|
25
|
-
try<
|
|
26
|
-
fromPromise<
|
|
44
|
+
Success<S, F>(value: S): Result<S, F>;
|
|
45
|
+
Failure<S_1, F_1>(reason: F_1): Result<S_1, F_1>;
|
|
46
|
+
try<S_2, F_2>(tryFn: () => S_2): TryCatch<S_2, F_2>;
|
|
47
|
+
fromPromise<S_3, F_3>(promise: Promise<S_3>, onResolve: (value: S_3) => S_3, onReject: (reason: unknown) => F_3): Promise<Result<S_3, F_3>>;
|
|
27
48
|
fromMaybe: typeof resultFromMaybe;
|
|
28
49
|
JSONReviver(_key: string, value: any): any;
|
|
29
50
|
};
|
|
@@ -34,4 +55,4 @@ declare class TryCatch<S, F> {
|
|
|
34
55
|
catch(catchFn: (err: unknown) => F): this;
|
|
35
56
|
exec(finallyFn?: (result: Result<S, F>) => void): Result<S, F>;
|
|
36
57
|
}
|
|
37
|
-
export {};
|
|
58
|
+
export type { Success, Failure };
|