@terrygonguet/utils 0.0.5 → 0.0.6
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 +49 -47
- package/package.json +1 -1
- package/src/functional/result.ts +7 -3
- package/types/functional/result.d.ts +1 -1
package/dist/functional.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var f = (t, e, r) => (
|
|
4
|
-
const
|
|
5
|
-
function
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var S = (t, e, r) => e in t ? p(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var f = (t, e, r) => (S(t, typeof e != "symbol" ? e + "" : e, r), r);
|
|
4
|
+
const s = "@terrygonguet/utils/functional/maybe", _ = "@terrygonguet/utils/functional/maybe/Some", h = "@terrygonguet/utils/functional/maybe/None";
|
|
5
|
+
function u(t) {
|
|
6
6
|
return Object.create(
|
|
7
7
|
{
|
|
8
8
|
isSome: () => !0,
|
|
@@ -11,56 +11,56 @@ function i(t) {
|
|
|
11
11
|
return this.value;
|
|
12
12
|
},
|
|
13
13
|
map(e) {
|
|
14
|
-
return
|
|
14
|
+
return u(e(this.value));
|
|
15
15
|
},
|
|
16
16
|
flatMap(e) {
|
|
17
17
|
return e(this.value);
|
|
18
18
|
},
|
|
19
19
|
toJSON() {
|
|
20
|
-
return { $_kind:
|
|
20
|
+
return { $_kind: s, $_variant: _, value: this.value };
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
$_kind: { value:
|
|
24
|
+
$_kind: { value: s, enumerable: !1, writable: !1 },
|
|
25
25
|
$_variant: { value: _, enumerable: !1, writable: !1 },
|
|
26
26
|
value: { value: t, writable: !1 }
|
|
27
27
|
}
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const a = Object.create(
|
|
31
31
|
{
|
|
32
32
|
isSome: () => !1,
|
|
33
33
|
isNone: () => !0,
|
|
34
34
|
orDefault: $,
|
|
35
|
-
map: () =>
|
|
36
|
-
flatMap: () =>
|
|
37
|
-
toJSON: () => ({ $_kind:
|
|
35
|
+
map: () => a,
|
|
36
|
+
flatMap: () => a,
|
|
37
|
+
toJSON: () => ({ $_kind: s, $_variant: h })
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
|
-
$_kind: { value:
|
|
40
|
+
$_kind: { value: s, enumerable: !1, writable: !1 },
|
|
41
41
|
$_variant: { value: h, enumerable: !1, writable: !1 }
|
|
42
42
|
}
|
|
43
|
-
),
|
|
44
|
-
Some:
|
|
45
|
-
None:
|
|
43
|
+
), y = {
|
|
44
|
+
Some: u,
|
|
45
|
+
None: a,
|
|
46
46
|
from(t) {
|
|
47
47
|
switch (t) {
|
|
48
48
|
case null:
|
|
49
49
|
case void 0:
|
|
50
|
-
return
|
|
50
|
+
return a;
|
|
51
51
|
default:
|
|
52
|
-
return
|
|
52
|
+
return u(t);
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
JSONReviver(t, e) {
|
|
56
|
-
if ((e == null ? void 0 : e.$_kind) ==
|
|
56
|
+
if ((e == null ? void 0 : e.$_kind) == s) {
|
|
57
57
|
const r = e == null ? void 0 : e.$_variant;
|
|
58
|
-
return r == _ ?
|
|
58
|
+
return r == _ ? u(e == null ? void 0 : e.value) : r == h ? a : e;
|
|
59
59
|
} else
|
|
60
60
|
return e;
|
|
61
61
|
}
|
|
62
|
-
},
|
|
63
|
-
function
|
|
62
|
+
}, i = "@terrygonguet/utils/functional/result", o = "@terrygonguet/utils/functional/result/Success", b = "@terrygonguet/utils/functional/result/Failure";
|
|
63
|
+
function c(t) {
|
|
64
64
|
return Object.create(
|
|
65
65
|
{
|
|
66
66
|
isSuccess: () => !0,
|
|
@@ -69,18 +69,18 @@ function l(t) {
|
|
|
69
69
|
return e(this.value);
|
|
70
70
|
},
|
|
71
71
|
map(e) {
|
|
72
|
-
return
|
|
72
|
+
return c(e(this.value));
|
|
73
73
|
},
|
|
74
74
|
flatMap(e) {
|
|
75
75
|
return e(this.value);
|
|
76
76
|
},
|
|
77
77
|
toJSON() {
|
|
78
|
-
return { $_kind:
|
|
78
|
+
return { $_kind: i, $_variant: o, value: this.value };
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
|
-
$_kind: { value:
|
|
83
|
-
$_variant: { value:
|
|
82
|
+
$_kind: { value: i, enumerable: !1, writable: !1 },
|
|
83
|
+
$_variant: { value: o, enumerable: !1, writable: !1 },
|
|
84
84
|
value: { value: t, writable: !1 }
|
|
85
85
|
}
|
|
86
86
|
);
|
|
@@ -100,31 +100,31 @@ function m(t) {
|
|
|
100
100
|
return this;
|
|
101
101
|
},
|
|
102
102
|
toJSON() {
|
|
103
|
-
return { $_kind:
|
|
103
|
+
return { $_kind: i, $_variant: b, reason: this.reason };
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
|
-
$_kind: { value:
|
|
108
|
-
$_variant: { value:
|
|
107
|
+
$_kind: { value: i, enumerable: !1, writable: !1 },
|
|
108
|
+
$_variant: { value: o, enumerable: !1, writable: !1 },
|
|
109
109
|
reason: { value: t, writable: !1 }
|
|
110
110
|
}
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
const
|
|
114
|
-
Success:
|
|
113
|
+
const v = {
|
|
114
|
+
Success: c,
|
|
115
115
|
Failure: m,
|
|
116
116
|
try(t) {
|
|
117
|
-
return new
|
|
117
|
+
return new d(t);
|
|
118
118
|
},
|
|
119
119
|
JSONReviver(t, e) {
|
|
120
|
-
if ((e == null ? void 0 : e.$_kind) ==
|
|
120
|
+
if ((e == null ? void 0 : e.$_kind) == i) {
|
|
121
121
|
const r = e == null ? void 0 : e.$_variant;
|
|
122
|
-
return r ==
|
|
122
|
+
return r == o ? c(e == null ? void 0 : e.value) : r == b ? m(e == null ? void 0 : e.reason) : e;
|
|
123
123
|
} else
|
|
124
124
|
return e;
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
class
|
|
127
|
+
class d {
|
|
128
128
|
constructor(e) {
|
|
129
129
|
f(this, "tryFn");
|
|
130
130
|
f(this, "catchFn");
|
|
@@ -133,33 +133,35 @@ class S {
|
|
|
133
133
|
catch(e) {
|
|
134
134
|
return this.catchFn = e, this;
|
|
135
135
|
}
|
|
136
|
-
exec() {
|
|
136
|
+
exec(e) {
|
|
137
137
|
try {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
const r = c(this.tryFn());
|
|
139
|
+
return e == null || e(r), r;
|
|
140
|
+
} catch (r) {
|
|
141
|
+
const n = m(this.catchFn(r));
|
|
142
|
+
return e == null || e(n), n;
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
|
-
var
|
|
145
|
-
function
|
|
146
|
+
var N = w;
|
|
147
|
+
function w(t, e) {
|
|
146
148
|
if (!arguments.length)
|
|
147
149
|
throw new Error(
|
|
148
150
|
"expected at least one (and probably more) function arguments"
|
|
149
151
|
);
|
|
150
152
|
var r = arguments;
|
|
151
153
|
return function() {
|
|
152
|
-
for (var
|
|
153
|
-
|
|
154
|
-
return
|
|
154
|
+
for (var n = r[0].apply(this, arguments), g = r.length, l = 1; l < g; l++)
|
|
155
|
+
n = r[l].call(this, n);
|
|
156
|
+
return n;
|
|
155
157
|
};
|
|
156
158
|
}
|
|
157
159
|
function $(t) {
|
|
158
160
|
return t;
|
|
159
161
|
}
|
|
160
162
|
export {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
163
|
+
y as Maybe,
|
|
164
|
+
v as Result,
|
|
165
|
+
N as compose,
|
|
164
166
|
$ as identity
|
|
165
167
|
};
|
package/package.json
CHANGED
package/src/functional/result.ts
CHANGED
|
@@ -99,11 +99,15 @@ class TryCatch<S, F> {
|
|
|
99
99
|
return this
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
exec(): Result<S, F> {
|
|
102
|
+
exec(finallyFn?: (result: Result<S, F>) => void): Result<S, F> {
|
|
103
103
|
try {
|
|
104
|
-
|
|
104
|
+
const result = Success<S, F>(this.tryFn())
|
|
105
|
+
finallyFn?.(result)
|
|
106
|
+
return result
|
|
105
107
|
} catch (error) {
|
|
106
|
-
|
|
108
|
+
const result = Failure<S, F>(this.catchFn(error))
|
|
109
|
+
finallyFn?.(result)
|
|
110
|
+
return result
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
113
|
}
|