@tempots/std 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/array.cjs +1 -1
- package/array.d.ts +357 -35
- package/array.js +148 -152
- package/async-result.cjs +1 -1
- package/async-result.d.ts +152 -13
- package/async-result.js +112 -8
- package/bigint.cjs +1 -1
- package/bigint.d.ts +155 -18
- package/bigint.js +37 -37
- package/boolean.cjs +1 -1
- package/boolean.d.ts +39 -7
- package/boolean.js +10 -10
- package/domain.d.ts +146 -5
- package/equal.d.ts +26 -0
- package/function.cjs +1 -1
- package/function.d.ts +24 -1
- package/function.js +15 -19
- package/index.cjs +1 -0
- package/index.d.ts +13 -0
- package/index.js +185 -0
- package/json.d.ts +20 -1
- package/number.d.ts +324 -55
- package/object.cjs +1 -1
- package/object.d.ts +53 -5
- package/object.js +15 -15
- package/package.json +8 -8
- package/regexp.cjs +1 -1
- package/regexp.d.ts +5 -4
- package/regexp.js +8 -8
- package/result-Czm7RKNP.js +230 -0
- package/result-DzdZiQoR.cjs +1 -0
- package/result.cjs +1 -1
- package/result.d.ts +130 -6
- package/result.js +3 -54
- package/string.cjs +4 -4
- package/string.d.ts +217 -9
- package/string.js +153 -156
- package/validation.cjs +1 -1
- package/validation.d.ts +72 -4
- package/validation.js +2 -23
- package/maybe.cjs +0 -1
- package/maybe.d.ts +0 -9
- package/maybe.js +0 -9
package/array.js
CHANGED
|
@@ -1,223 +1,219 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return Array.from({ length: n.length }, (t, r) => e(n[r], r));
|
|
1
|
+
import { objectKeys as v } from "./object.js";
|
|
2
|
+
function q(n, r) {
|
|
3
|
+
return Array.from({ length: n.length }, (t, e) => r(n[e], e));
|
|
5
4
|
}
|
|
6
|
-
function
|
|
5
|
+
function B(n, r) {
|
|
7
6
|
const t = [];
|
|
8
|
-
for (
|
|
9
|
-
|
|
10
|
-
u != null && t.push(u);
|
|
11
|
-
}
|
|
12
|
-
return t;
|
|
13
|
-
}
|
|
14
|
-
function y(n, e) {
|
|
15
|
-
const t = [];
|
|
16
|
-
for (const r of n)
|
|
17
|
-
t.push(...e(r));
|
|
7
|
+
for (const e of n)
|
|
8
|
+
t.push(...r(e));
|
|
18
9
|
return t;
|
|
19
10
|
}
|
|
20
|
-
function
|
|
21
|
-
return n.length > 0 ?
|
|
11
|
+
function _(n) {
|
|
12
|
+
return n.length > 0 ? n[0] : void 0;
|
|
22
13
|
}
|
|
23
|
-
function
|
|
14
|
+
function k(n) {
|
|
24
15
|
return n.slice(1);
|
|
25
16
|
}
|
|
26
|
-
function
|
|
27
|
-
if (n.length !==
|
|
28
|
-
for (let
|
|
29
|
-
if (!t(n[
|
|
17
|
+
function F(n, r, t) {
|
|
18
|
+
if (n.length !== r.length) return !1;
|
|
19
|
+
for (let e = 0; e < n.length; e++)
|
|
20
|
+
if (!t(n[e], r[e])) return !1;
|
|
30
21
|
return !0;
|
|
31
22
|
}
|
|
32
|
-
function
|
|
33
|
-
return function(e, t) {
|
|
34
|
-
return A(e, t, n);
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function O(n) {
|
|
23
|
+
function I(n) {
|
|
38
24
|
return n.length === 0;
|
|
39
25
|
}
|
|
40
|
-
function
|
|
26
|
+
function M(n) {
|
|
41
27
|
return n.length > 0;
|
|
42
28
|
}
|
|
43
|
-
function
|
|
29
|
+
function x(n, r) {
|
|
44
30
|
const t = [];
|
|
45
|
-
for (const
|
|
31
|
+
for (const e of n) r(e) && t.push(e);
|
|
46
32
|
return t;
|
|
47
33
|
}
|
|
48
|
-
function
|
|
34
|
+
function b(n, r) {
|
|
49
35
|
const t = [];
|
|
50
|
-
for (let
|
|
51
|
-
const u =
|
|
36
|
+
for (let e = 0; e < n.length; e++) {
|
|
37
|
+
const u = r(n[e], e);
|
|
52
38
|
u != null && t.push(u);
|
|
53
39
|
}
|
|
54
40
|
return t;
|
|
55
41
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
42
|
+
function j(n) {
|
|
43
|
+
return x(n, (r) => r != null);
|
|
58
44
|
}
|
|
59
|
-
function
|
|
45
|
+
function D(n) {
|
|
60
46
|
return [].concat(...n);
|
|
61
47
|
}
|
|
62
|
-
function
|
|
63
|
-
for (const
|
|
64
|
-
t =
|
|
48
|
+
function P(n, r, t) {
|
|
49
|
+
for (const e of n)
|
|
50
|
+
t = r(t, e);
|
|
65
51
|
return t;
|
|
66
52
|
}
|
|
67
|
-
function
|
|
53
|
+
function S(n, r) {
|
|
68
54
|
for (const t of n)
|
|
69
|
-
if (!
|
|
55
|
+
if (!r(t))
|
|
70
56
|
return !1;
|
|
71
57
|
return !0;
|
|
72
58
|
}
|
|
73
|
-
function
|
|
59
|
+
function N(n, r) {
|
|
74
60
|
for (const t of n)
|
|
75
|
-
if (
|
|
61
|
+
if (r(t))
|
|
76
62
|
return !0;
|
|
77
63
|
return !1;
|
|
78
64
|
}
|
|
79
|
-
function T(n,
|
|
80
|
-
for (const t of n)
|
|
65
|
+
function T(n, r) {
|
|
66
|
+
for (const t of n) r(t);
|
|
81
67
|
}
|
|
82
|
-
function
|
|
68
|
+
function $(...n) {
|
|
83
69
|
return [].concat(...n);
|
|
84
70
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return 0;
|
|
96
|
-
};
|
|
71
|
+
function H(n, r, t, e = !0) {
|
|
72
|
+
if (n.length < r.length)
|
|
73
|
+
return -1 * (e ? 1 : -1);
|
|
74
|
+
if (n.length > r.length)
|
|
75
|
+
return 1 * (e ? 1 : -1);
|
|
76
|
+
for (let u = 0; u < n.length; u++) {
|
|
77
|
+
const l = t(n[u], r[u]);
|
|
78
|
+
if (l !== 0) return l;
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
97
81
|
}
|
|
98
|
-
function
|
|
99
|
-
return
|
|
82
|
+
function C(n, r) {
|
|
83
|
+
return n.slice().sort(r);
|
|
100
84
|
}
|
|
101
|
-
function
|
|
102
|
-
return Array.from({ length: n }, (t,
|
|
85
|
+
function g(n, r) {
|
|
86
|
+
return Array.from({ length: n }, (t, e) => r(e));
|
|
103
87
|
}
|
|
104
|
-
function
|
|
105
|
-
return
|
|
88
|
+
function L(n, r = 0) {
|
|
89
|
+
return g(n, (t) => r + t);
|
|
106
90
|
}
|
|
107
|
-
function
|
|
108
|
-
return
|
|
91
|
+
function R(n, r) {
|
|
92
|
+
return g(n, () => r);
|
|
109
93
|
}
|
|
110
|
-
function
|
|
94
|
+
function V(n) {
|
|
111
95
|
return Array.from(new Set(n));
|
|
112
96
|
}
|
|
113
|
-
function
|
|
97
|
+
function W(n, r) {
|
|
114
98
|
const t = {};
|
|
115
|
-
return n.forEach((
|
|
116
|
-
t[e
|
|
117
|
-
}),
|
|
99
|
+
return n.forEach((e) => {
|
|
100
|
+
t[r(e)] = e;
|
|
101
|
+
}), v(t).map((e) => t[e]);
|
|
118
102
|
}
|
|
119
|
-
function
|
|
120
|
-
const t = n.indexOf(
|
|
103
|
+
function E(n, r) {
|
|
104
|
+
const t = n.indexOf(r);
|
|
121
105
|
return t < 0 ? !1 : (n.splice(t, 1), !0);
|
|
122
106
|
}
|
|
123
|
-
function
|
|
124
|
-
|
|
107
|
+
function z(n, r) {
|
|
108
|
+
let t = !1;
|
|
109
|
+
for (; E(n, r); )
|
|
110
|
+
t = !0;
|
|
111
|
+
return t;
|
|
112
|
+
}
|
|
113
|
+
function w(n, r) {
|
|
114
|
+
const t = n.findIndex(r);
|
|
125
115
|
return t < 0 ? !1 : (n.splice(t, 1), !0);
|
|
126
116
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
117
|
+
function G(n, r) {
|
|
118
|
+
let t = !1;
|
|
119
|
+
for (; w(n, r); )
|
|
120
|
+
t = !0;
|
|
121
|
+
return t;
|
|
122
|
+
}
|
|
123
|
+
function J(n) {
|
|
124
|
+
const r = [];
|
|
129
125
|
for (let t = n.next(); !(t.done ?? !1); t = n.next())
|
|
130
|
-
|
|
131
|
-
return
|
|
126
|
+
r.push(t.value);
|
|
127
|
+
return r;
|
|
132
128
|
}
|
|
133
|
-
function
|
|
134
|
-
const
|
|
129
|
+
function Q(n, r, t) {
|
|
130
|
+
const e = {
|
|
135
131
|
removals: [],
|
|
136
132
|
swaps: [],
|
|
137
133
|
inserts: []
|
|
138
|
-
}, { removals: u, inserts:
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
for (let o =
|
|
142
|
-
const f =
|
|
143
|
-
|
|
134
|
+
}, { removals: u, inserts: l, swaps: c } = e, s = /* @__PURE__ */ new Map();
|
|
135
|
+
r.forEach((o, f) => s.set(t(o), f));
|
|
136
|
+
const a = n.map((o, f) => [o, f]).filter(([o]) => !s.has(t(o))).map(([o, f]) => f);
|
|
137
|
+
for (let o = a.length - 1; o >= 0; o--) {
|
|
138
|
+
const f = a[o], i = u.length > 0 ? u[u.length - 1] : void 0;
|
|
139
|
+
i != null && i.at === f + 1 ? (i.at--, i.qt++) : u.push({ at: f, qt: 1 });
|
|
144
140
|
}
|
|
145
141
|
const h = /* @__PURE__ */ new Map();
|
|
146
142
|
n.forEach((o, f) => h.set(t(o), f));
|
|
147
|
-
const
|
|
148
|
-
for (const o of
|
|
149
|
-
const f =
|
|
150
|
-
f != null && f.at + f.values.length === o ? f.values.push(
|
|
143
|
+
const y = r.map((o, f) => [o, f]).filter(([o]) => !h.has(t(o))).map(([o, f]) => f);
|
|
144
|
+
for (const o of y) {
|
|
145
|
+
const f = l.length > 0 ? l[l.length - 1] : void 0;
|
|
146
|
+
f != null && f.at + f.values.length === o ? f.values.push(r[o]) : l.push({ at: o, values: [r[o]] });
|
|
151
147
|
}
|
|
152
|
-
const p = n.filter((o, f) => !
|
|
148
|
+
const p = n.filter((o, f) => !a.includes(f)), m = /* @__PURE__ */ new Map();
|
|
153
149
|
for (let o = 0; o < p.length; o++)
|
|
154
150
|
m.set(t(p[o]), o);
|
|
155
|
-
const
|
|
156
|
-
for (let o = 0; o <
|
|
157
|
-
const f = t(
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
160
|
-
m.delete(
|
|
151
|
+
const A = r.filter((o, f) => !y.includes(f));
|
|
152
|
+
for (let o = 0; o < A.length; o++) {
|
|
153
|
+
const f = t(A[o]), i = m.get(f);
|
|
154
|
+
if (i == null || o === i) continue;
|
|
155
|
+
const d = t(p[o]);
|
|
156
|
+
m.delete(d), c.push({ from: o, to: i });
|
|
161
157
|
}
|
|
162
|
-
return
|
|
158
|
+
return e;
|
|
163
159
|
}
|
|
164
|
-
function
|
|
165
|
-
const t = [...
|
|
166
|
-
for (const { at:
|
|
167
|
-
t.splice(
|
|
168
|
-
for (const { from:
|
|
169
|
-
const
|
|
170
|
-
t[u] = t[
|
|
160
|
+
function U(n, r) {
|
|
161
|
+
const t = [...r];
|
|
162
|
+
for (const { at: e, qt: u } of n.removals)
|
|
163
|
+
t.splice(e, u);
|
|
164
|
+
for (const { from: e, to: u } of n.swaps) {
|
|
165
|
+
const l = t[u];
|
|
166
|
+
t[u] = t[e], t[e] = l;
|
|
171
167
|
}
|
|
172
|
-
for (const
|
|
173
|
-
t.splice(
|
|
168
|
+
for (const e of n.inserts)
|
|
169
|
+
t.splice(e.at, 0, ...e.values);
|
|
174
170
|
return t;
|
|
175
171
|
}
|
|
176
|
-
function
|
|
177
|
-
return n.length === 0 ? "" : n.length === 1 ? String(n[0]) : `${n.slice(0, -1).join(t)}${
|
|
178
|
-
}
|
|
179
|
-
function
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
const u = new Array(
|
|
183
|
-
let
|
|
184
|
-
for (let
|
|
185
|
-
const [
|
|
186
|
-
|
|
172
|
+
function X(n, r = " and ", t = ", ") {
|
|
173
|
+
return n.length === 0 ? "" : n.length === 1 ? String(n[0]) : `${n.slice(0, -1).join(t)}${r}${String(n[n.length - 1])}`;
|
|
174
|
+
}
|
|
175
|
+
function Y(n, r, t = !0) {
|
|
176
|
+
const e = n.map((s, a) => [s, a]);
|
|
177
|
+
e.sort((s, a) => r(s[0], a[0]));
|
|
178
|
+
const u = new Array(e.length);
|
|
179
|
+
let l = 0, c = e[0][0];
|
|
180
|
+
for (let s = 0; s < e.length; s++) {
|
|
181
|
+
const [a, h] = e[s];
|
|
182
|
+
r(a, c) !== 0 && (l = s, c = a), u[h] = l, t && l++;
|
|
187
183
|
}
|
|
188
184
|
return u;
|
|
189
185
|
}
|
|
190
186
|
export {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
q as
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
W as
|
|
222
|
-
|
|
187
|
+
S as allElements,
|
|
188
|
+
N as anyElement,
|
|
189
|
+
U as applyArrayDiffOperations,
|
|
190
|
+
F as areArraysEqual,
|
|
191
|
+
Q as arrayDiffOperations,
|
|
192
|
+
M as arrayHasValues,
|
|
193
|
+
_ as arrayHead,
|
|
194
|
+
J as arrayOfIterableIterator,
|
|
195
|
+
k as arrayTail,
|
|
196
|
+
H as compareArrays,
|
|
197
|
+
$ as concatArrays,
|
|
198
|
+
R as createFilledArray,
|
|
199
|
+
x as filterArray,
|
|
200
|
+
b as filterMapArray,
|
|
201
|
+
j as filterNullsFromArray,
|
|
202
|
+
B as flatMapArray,
|
|
203
|
+
D as flattenArray,
|
|
204
|
+
P as foldLeftArray,
|
|
205
|
+
T as forEachElement,
|
|
206
|
+
g as generateArray,
|
|
207
|
+
L as generateSequenceArray,
|
|
208
|
+
I as isArrayEmpty,
|
|
209
|
+
X as joinArrayWithConjunction,
|
|
210
|
+
q as mapArray,
|
|
211
|
+
Y as rankArray,
|
|
212
|
+
z as removeAllFromArray,
|
|
213
|
+
G as removeAllFromArrayByPredicate,
|
|
214
|
+
E as removeOneFromArray,
|
|
215
|
+
w as removeOneFromArrayByPredicate,
|
|
216
|
+
C as sortArray,
|
|
217
|
+
W as uniqueByPredicate,
|
|
218
|
+
V as uniquePrimitives
|
|
223
219
|
};
|
package/async-result.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s={notAsked:{type:"NotAsked"},loading(e=void 0){return{type:"Loading",previousValue:e}},success(e){return{type:"AsyncSuccess",value:e}},failure(e){return{type:"AsyncFailure",error:e}},isSuccess(e){return e.type==="AsyncSuccess"},isFailure(e){return e.type==="AsyncFailure"},isNotAsked(e){return e.type==="NotAsked"},isLoading(e){return e.type==="Loading"},getOrElse(e,u){return s.isSuccess(e)?e.value:u},getOrElseLazy(e,u){return s.isSuccess(e)?e.value:u()},getOrNull(e){return s.isSuccess(e)?e.value:null},getOrUndefined(e){return s.isSuccess(e)?e.value:void 0},match:(e,{success:u,failure:r,loading:t,notAsked:i=t})=>s.isSuccess(e)?u(e.value):s.isFailure(e)?r(e.error):s.isNotAsked(e)?i():t(e.previousValue),whenSuccess:(e,u)=>(s.isSuccess(e)&&u(e.value),e),whenFailure:(e,u)=>(s.isFailure(e)&&u(e.error),e)};exports.AsyncResult=s;
|
package/async-result.d.ts
CHANGED
|
@@ -1,36 +1,175 @@
|
|
|
1
|
+
import { Maybe } from './domain';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents the state when a result has not been requested yet.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
1
7
|
export interface NotAsked {
|
|
2
8
|
type: 'NotAsked';
|
|
3
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Represents a loading state in an asynchronous result.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
4
14
|
export interface Loading<V> {
|
|
5
15
|
type: 'Loading';
|
|
6
16
|
previousValue?: V;
|
|
7
17
|
}
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Represents a successful result.
|
|
20
|
+
* @typeParam V - The type of the value.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface AsyncSuccess<V> {
|
|
24
|
+
type: 'AsyncSuccess';
|
|
10
25
|
value: V;
|
|
11
26
|
}
|
|
12
|
-
|
|
13
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Represents a failure result.
|
|
29
|
+
* @typeParam E - - The type of the error.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export interface AsyncFailure<E> {
|
|
33
|
+
type: 'AsyncFailure';
|
|
14
34
|
error: E;
|
|
15
35
|
}
|
|
16
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Represents the result of an asynchronous operation that can be in one of the following states:
|
|
38
|
+
* - `NotAsked`: The operation has not been requested yet.
|
|
39
|
+
* - `Loading`: The operation is currently in progress.
|
|
40
|
+
* - `Success`: The operation has completed successfully and contains a value of type `V`.
|
|
41
|
+
* - `Failure`: The operation has completed with an error and contains an error of type `E`.
|
|
42
|
+
*
|
|
43
|
+
* @typeParam V - The type of the value on success.
|
|
44
|
+
* @typeParam E - The type of the error on failure.
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export type AsyncResult<V, E> = NotAsked | Loading<V> | AsyncSuccess<V> | AsyncFailure<E>;
|
|
48
|
+
/**
|
|
49
|
+
* A set of utility functions for working with `AsyncResult`.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
17
52
|
export declare const AsyncResult: {
|
|
53
|
+
/**
|
|
54
|
+
* Creates a loading state.
|
|
55
|
+
* @param previousValue - The previous value.
|
|
56
|
+
* @returns A loading state.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
18
59
|
notAsked: {
|
|
19
60
|
type: "NotAsked";
|
|
20
61
|
};
|
|
21
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Creates a loading state.
|
|
64
|
+
* @param previousValue - The previous value.
|
|
65
|
+
* @returns A loading state.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
loading<V>(previousValue?: Maybe<V>): AsyncResult<V, never>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a successful state.
|
|
71
|
+
* @param value - The value.
|
|
72
|
+
* @returns A successful state.
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
22
75
|
success<V>(value: V): AsyncResult<V, never>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a failure state.
|
|
78
|
+
* @param error - The error.
|
|
79
|
+
* @returns A failure state.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
23
82
|
failure<E>(error: E): AsyncResult<never, E>;
|
|
24
|
-
|
|
25
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the result is a success.
|
|
85
|
+
* @param r - The result.
|
|
86
|
+
* @returns `true` if the result is a success; otherwise, `false`.
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
isSuccess<V, E>(r: AsyncResult<V, E>): r is AsyncSuccess<V>;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if the result is a failure.
|
|
92
|
+
* @param r - The result.
|
|
93
|
+
* @returns `true` if the result is a failure; otherwise, `false`.
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
isFailure<V, E>(r: AsyncResult<V, E>): r is AsyncFailure<E>;
|
|
97
|
+
/**
|
|
98
|
+
* Checks if the result is a not-asked.
|
|
99
|
+
* @param r - The result.
|
|
100
|
+
* @returns `true` if the result is not-asked; otherwise, `false`.
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
26
103
|
isNotAsked<V, E>(r: AsyncResult<V, E>): r is NotAsked;
|
|
104
|
+
/**
|
|
105
|
+
* Checks if the result is a loading.
|
|
106
|
+
* @param r - The result.
|
|
107
|
+
* @returns `true` if the result is loading; otherwise, `false`.
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
27
110
|
isLoading<V, E>(r: AsyncResult<V, E>): r is Loading<V>;
|
|
111
|
+
/**
|
|
112
|
+
* Gets the value if the result is a success; otherwise, returns the alternative value.
|
|
113
|
+
* @param r - The result.
|
|
114
|
+
* @param alt - The alternative value.
|
|
115
|
+
* @returns The value if the result is a success; otherwise, the alternative value.
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
28
118
|
getOrElse<V, E>(r: AsyncResult<V, E>, alt: V): V;
|
|
119
|
+
/**
|
|
120
|
+
* Gets the value if the result is a success; otherwise, returns the value from the alternative function.
|
|
121
|
+
* @param r - The result.
|
|
122
|
+
* @param altf - The alternative function.
|
|
123
|
+
* @returns The value if the result is a success; otherwise, the value from the alternative
|
|
124
|
+
* @public
|
|
125
|
+
* function.
|
|
126
|
+
*/
|
|
29
127
|
getOrElseLazy<V, E>(r: AsyncResult<V, E>, altf: () => V): V;
|
|
128
|
+
/**
|
|
129
|
+
* Gets the value if the result is a success; otherwise, returns `null`.
|
|
130
|
+
* @param r - The result.
|
|
131
|
+
* @returns The value if the result is a success; otherwise, `null`.
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
30
134
|
getOrNull<V, E>(r: AsyncResult<V, E>): V | null;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Gets the value if the result is a success; otherwise, returns `undefined`.
|
|
137
|
+
* @param r - The result.
|
|
138
|
+
* @returns The value if the result is a success; otherwise, `undefined`.
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
getOrUndefined<V, E>(r: AsyncResult<V, E>): Maybe<V>;
|
|
142
|
+
/**
|
|
143
|
+
* Based on the state of the result, it picks the appropriate function to call and returns the result.
|
|
144
|
+
* @param success - The function to call if the result is a success.
|
|
145
|
+
* @param failure - The function to call if the result is a failure.
|
|
146
|
+
* @param loading - The function to call if the result is loading.
|
|
147
|
+
* @param notAsked - The function to call if the result is not-asked.
|
|
148
|
+
* @returns The result of calling the appropriate function based on the state of the result.
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
match: <V1, V2, E>(r: AsyncResult<V1, E>, { success, failure, loading, notAsked, }: {
|
|
152
|
+
success: (value: V1) => V2;
|
|
153
|
+
failure: (error: E) => V2;
|
|
154
|
+
loading: (previousValue?: V1) => V2;
|
|
155
|
+
notAsked: () => V2;
|
|
156
|
+
}) => V2;
|
|
157
|
+
/**
|
|
158
|
+
* When the result is a success, it applies the function to the value.
|
|
159
|
+
*
|
|
160
|
+
* @param r - The result.
|
|
161
|
+
* @param apply - The function to apply.
|
|
162
|
+
* @returns The result that was passed in.
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
whenSuccess: <V, E>(r: AsyncResult<V, E>, apply: (v: V) => void) => AsyncResult<V, E>;
|
|
166
|
+
/**
|
|
167
|
+
* When the result is a failure, it applies the function to the error.
|
|
168
|
+
*
|
|
169
|
+
* @param r - The result.
|
|
170
|
+
* @param apply - The function to apply.
|
|
171
|
+
* @returns The result that was passed in.
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
whenFailure: <V, E>(r: AsyncResult<V, E>, apply: (e: E) => void) => AsyncResult<V, E>;
|
|
36
175
|
};
|