decoders 2.0.0-beta5 → 2.0.0-beta6
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/_esm/core/tuple.js +11 -7
- package/_esm/core/tuple.js.flow +24 -25
- package/_esm/result.js +0 -13
- package/_esm/result.js.flow +0 -16
- package/core/tuple.js +10 -6
- package/core/tuple.js.flow +24 -25
- package/package.json +1 -1
- package/result.js +0 -19
- package/result.js.flow +0 -16
package/_esm/core/tuple.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { annotate } from '../annotate';
|
|
2
2
|
import { compose, predicate } from './composition';
|
|
3
|
-
import { err, ok,
|
|
3
|
+
import { err, ok, unwrap } from '../result';
|
|
4
4
|
import { poja } from './array';
|
|
5
5
|
|
|
6
|
+
function okOrErr(result) {
|
|
7
|
+
return result.type === 'ok' ? result.value : result.error;
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
var ntuple = function ntuple(n) {
|
|
7
11
|
return compose(poja, predicate(function (arr) {
|
|
8
12
|
return arr.length === n;
|
|
@@ -24,7 +28,7 @@ export function tuple1(decoder1) {
|
|
|
24
28
|
} catch (e) {
|
|
25
29
|
// If a decoder error has happened while unwrapping all the
|
|
26
30
|
// results, try to construct a good error message
|
|
27
|
-
return err(annotate([
|
|
31
|
+
return err(annotate([okOrErr(result1)]));
|
|
28
32
|
}
|
|
29
33
|
});
|
|
30
34
|
}
|
|
@@ -45,7 +49,7 @@ export function tuple2(decoder1, decoder2) {
|
|
|
45
49
|
} catch (e) {
|
|
46
50
|
// If a decoder error has happened while unwrapping all the
|
|
47
51
|
// results, try to construct a good error message
|
|
48
|
-
return err(annotate([
|
|
52
|
+
return err(annotate([okOrErr(result1), okOrErr(result2)]));
|
|
49
53
|
}
|
|
50
54
|
});
|
|
51
55
|
}
|
|
@@ -68,7 +72,7 @@ export function tuple3(decoder1, decoder2, decoder3) {
|
|
|
68
72
|
} catch (e) {
|
|
69
73
|
// If a decoder error has happened while unwrapping all the
|
|
70
74
|
// results, try to construct a good error message
|
|
71
|
-
return err(annotate([
|
|
75
|
+
return err(annotate([okOrErr(result1), okOrErr(result2), okOrErr(result3)]));
|
|
72
76
|
}
|
|
73
77
|
});
|
|
74
78
|
}
|
|
@@ -93,7 +97,7 @@ export function tuple4(decoder1, decoder2, decoder3, decoder4) {
|
|
|
93
97
|
} catch (e) {
|
|
94
98
|
// If a decoder error has happened while unwrapping all the
|
|
95
99
|
// results, try to construct a good error message
|
|
96
|
-
return err(annotate([
|
|
100
|
+
return err(annotate([okOrErr(result1), okOrErr(result2), okOrErr(result3), okOrErr(result4)]));
|
|
97
101
|
}
|
|
98
102
|
});
|
|
99
103
|
}
|
|
@@ -120,7 +124,7 @@ export function tuple5(decoder1, decoder2, decoder3, decoder4, decoder5) {
|
|
|
120
124
|
} catch (e) {
|
|
121
125
|
// If a decoder error has happened while unwrapping all the
|
|
122
126
|
// results, try to construct a good error message
|
|
123
|
-
return err(annotate([
|
|
127
|
+
return err(annotate([okOrErr(result1), okOrErr(result2), okOrErr(result3), okOrErr(result4), okOrErr(result5)]));
|
|
124
128
|
}
|
|
125
129
|
});
|
|
126
130
|
}
|
|
@@ -149,7 +153,7 @@ export function tuple6(decoder1, decoder2, decoder3, decoder4, decoder5, decoder
|
|
|
149
153
|
} catch (e) {
|
|
150
154
|
// If a decoder error has happened while unwrapping all the
|
|
151
155
|
// results, try to construct a good error message
|
|
152
|
-
return err(annotate([
|
|
156
|
+
return err(annotate([okOrErr(result1), okOrErr(result2), okOrErr(result3), okOrErr(result4), okOrErr(result5), okOrErr(result6)]));
|
|
153
157
|
}
|
|
154
158
|
});
|
|
155
159
|
}
|
package/_esm/core/tuple.js.flow
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { annotate } from '../annotate';
|
|
4
4
|
import { compose, predicate } from './composition';
|
|
5
|
-
import { err, ok,
|
|
5
|
+
import { err, ok, unwrap } from '../result';
|
|
6
6
|
import { poja } from './array';
|
|
7
7
|
import type { Decoder } from '../_types';
|
|
8
|
+
import type { Result } from '../result';
|
|
9
|
+
|
|
10
|
+
function okOrErr<T, E>(result: Result<T, E>): T | E {
|
|
11
|
+
return result.type === 'ok' ? result.value : result.error;
|
|
12
|
+
}
|
|
8
13
|
|
|
9
14
|
const ntuple = (n: number) =>
|
|
10
15
|
compose(
|
|
@@ -26,7 +31,7 @@ export function tuple1<T>(decoder1: Decoder<T>): Decoder<[T]> {
|
|
|
26
31
|
} catch (e) {
|
|
27
32
|
// If a decoder error has happened while unwrapping all the
|
|
28
33
|
// results, try to construct a good error message
|
|
29
|
-
return err(annotate([
|
|
34
|
+
return err(annotate([okOrErr(result1)]));
|
|
30
35
|
}
|
|
31
36
|
});
|
|
32
37
|
}
|
|
@@ -49,7 +54,7 @@ export function tuple2<T1, T2>(
|
|
|
49
54
|
} catch (e) {
|
|
50
55
|
// If a decoder error has happened while unwrapping all the
|
|
51
56
|
// results, try to construct a good error message
|
|
52
|
-
return err(annotate([
|
|
57
|
+
return err(annotate([okOrErr(result1), okOrErr(result2)]));
|
|
53
58
|
}
|
|
54
59
|
});
|
|
55
60
|
}
|
|
@@ -74,13 +79,7 @@ export function tuple3<T1, T2, T3>(
|
|
|
74
79
|
} catch (e) {
|
|
75
80
|
// If a decoder error has happened while unwrapping all the
|
|
76
81
|
// results, try to construct a good error message
|
|
77
|
-
return err(
|
|
78
|
-
annotate([
|
|
79
|
-
okOrErrValue(result1),
|
|
80
|
-
okOrErrValue(result2),
|
|
81
|
-
okOrErrValue(result3),
|
|
82
|
-
]),
|
|
83
|
-
);
|
|
82
|
+
return err(annotate([okOrErr(result1), okOrErr(result2), okOrErr(result3)]));
|
|
84
83
|
}
|
|
85
84
|
});
|
|
86
85
|
}
|
|
@@ -114,10 +113,10 @@ export function tuple4<T1, T2, T3, T4>(
|
|
|
114
113
|
// results, try to construct a good error message
|
|
115
114
|
return err(
|
|
116
115
|
annotate([
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
okOrErr(result1),
|
|
117
|
+
okOrErr(result2),
|
|
118
|
+
okOrErr(result3),
|
|
119
|
+
okOrErr(result4),
|
|
121
120
|
]),
|
|
122
121
|
);
|
|
123
122
|
}
|
|
@@ -156,11 +155,11 @@ export function tuple5<T1, T2, T3, T4, T5>(
|
|
|
156
155
|
// results, try to construct a good error message
|
|
157
156
|
return err(
|
|
158
157
|
annotate([
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
okOrErr(result1),
|
|
159
|
+
okOrErr(result2),
|
|
160
|
+
okOrErr(result3),
|
|
161
|
+
okOrErr(result4),
|
|
162
|
+
okOrErr(result5),
|
|
164
163
|
]),
|
|
165
164
|
);
|
|
166
165
|
}
|
|
@@ -202,12 +201,12 @@ export function tuple6<T1, T2, T3, T4, T5, T6>(
|
|
|
202
201
|
// results, try to construct a good error message
|
|
203
202
|
return err(
|
|
204
203
|
annotate([
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
okOrErr(result1),
|
|
205
|
+
okOrErr(result2),
|
|
206
|
+
okOrErr(result3),
|
|
207
|
+
okOrErr(result4),
|
|
208
|
+
okOrErr(result5),
|
|
209
|
+
okOrErr(result6),
|
|
211
210
|
]),
|
|
212
211
|
);
|
|
213
212
|
}
|
package/_esm/result.js
CHANGED
|
@@ -36,19 +36,6 @@ export function isErr(result) {
|
|
|
36
36
|
}
|
|
37
37
|
export function withDefault(result, defaultValue) {
|
|
38
38
|
return result.type === 'ok' ? result.value : defaultValue;
|
|
39
|
-
} // TODO: Remove this from the public API? The same can be achieved now with
|
|
40
|
-
// TODO: const { value } = result;
|
|
41
|
-
|
|
42
|
-
export function okValue(result) {
|
|
43
|
-
return result.type === 'ok' ? result.value : undefined;
|
|
44
|
-
} // TODO: Remove this from the public API? The same can be achieved now with
|
|
45
|
-
// TODO: const { error } = result;
|
|
46
|
-
|
|
47
|
-
export function errValue(result) {
|
|
48
|
-
return result.type === 'err' ? result.error : undefined;
|
|
49
|
-
}
|
|
50
|
-
export function okOrErrValue(result) {
|
|
51
|
-
return result.type === 'ok' ? result.value : result.error;
|
|
52
39
|
}
|
|
53
40
|
/**
|
|
54
41
|
* Unwrap the value from this Result instance if this is an "Ok" result.
|
package/_esm/result.js.flow
CHANGED
|
@@ -43,22 +43,6 @@ export function withDefault<T>(result: Result<T, mixed>, defaultValue: T): T {
|
|
|
43
43
|
return result.type === 'ok' ? result.value : defaultValue;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
// TODO: Remove this from the public API? The same can be achieved now with
|
|
47
|
-
// TODO: const { value } = result;
|
|
48
|
-
export function okValue<T>(result: Result<T, mixed>): void | T {
|
|
49
|
-
return result.type === 'ok' ? result.value : undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// TODO: Remove this from the public API? The same can be achieved now with
|
|
53
|
-
// TODO: const { error } = result;
|
|
54
|
-
export function errValue<E>(result: Result<mixed, E>): void | E {
|
|
55
|
-
return result.type === 'err' ? result.error : undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function okOrErrValue<T, E>(result: Result<T, E>): T | E {
|
|
59
|
-
return result.type === 'ok' ? result.value : result.error;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
46
|
/**
|
|
63
47
|
* Unwrap the value from this Result instance if this is an "Ok" result.
|
|
64
48
|
* Otherwise, will throw the "Err" error via a runtime exception.
|
package/core/tuple.js
CHANGED
|
@@ -16,6 +16,10 @@ var _result = require("../result");
|
|
|
16
16
|
|
|
17
17
|
var _array = require("./array");
|
|
18
18
|
|
|
19
|
+
function okOrErr(result) {
|
|
20
|
+
return result.type === 'ok' ? result.value : result.error;
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
var ntuple = function ntuple(n) {
|
|
20
24
|
return (0, _composition.compose)(_array.poja, (0, _composition.predicate)(function (arr) {
|
|
21
25
|
return arr.length === n;
|
|
@@ -37,7 +41,7 @@ function tuple1(decoder1) {
|
|
|
37
41
|
} catch (e) {
|
|
38
42
|
// If a decoder error has happened while unwrapping all the
|
|
39
43
|
// results, try to construct a good error message
|
|
40
|
-
return (0, _result.err)((0, _annotate.annotate)([(
|
|
44
|
+
return (0, _result.err)((0, _annotate.annotate)([okOrErr(result1)]));
|
|
41
45
|
}
|
|
42
46
|
});
|
|
43
47
|
}
|
|
@@ -59,7 +63,7 @@ function tuple2(decoder1, decoder2) {
|
|
|
59
63
|
} catch (e) {
|
|
60
64
|
// If a decoder error has happened while unwrapping all the
|
|
61
65
|
// results, try to construct a good error message
|
|
62
|
-
return (0, _result.err)((0, _annotate.annotate)([(
|
|
66
|
+
return (0, _result.err)((0, _annotate.annotate)([okOrErr(result1), okOrErr(result2)]));
|
|
63
67
|
}
|
|
64
68
|
});
|
|
65
69
|
}
|
|
@@ -83,7 +87,7 @@ function tuple3(decoder1, decoder2, decoder3) {
|
|
|
83
87
|
} catch (e) {
|
|
84
88
|
// If a decoder error has happened while unwrapping all the
|
|
85
89
|
// results, try to construct a good error message
|
|
86
|
-
return (0, _result.err)((0, _annotate.annotate)([(
|
|
90
|
+
return (0, _result.err)((0, _annotate.annotate)([okOrErr(result1), okOrErr(result2), okOrErr(result3)]));
|
|
87
91
|
}
|
|
88
92
|
});
|
|
89
93
|
}
|
|
@@ -109,7 +113,7 @@ function tuple4(decoder1, decoder2, decoder3, decoder4) {
|
|
|
109
113
|
} catch (e) {
|
|
110
114
|
// If a decoder error has happened while unwrapping all the
|
|
111
115
|
// results, try to construct a good error message
|
|
112
|
-
return (0, _result.err)((0, _annotate.annotate)([(
|
|
116
|
+
return (0, _result.err)((0, _annotate.annotate)([okOrErr(result1), okOrErr(result2), okOrErr(result3), okOrErr(result4)]));
|
|
113
117
|
}
|
|
114
118
|
});
|
|
115
119
|
}
|
|
@@ -137,7 +141,7 @@ function tuple5(decoder1, decoder2, decoder3, decoder4, decoder5) {
|
|
|
137
141
|
} catch (e) {
|
|
138
142
|
// If a decoder error has happened while unwrapping all the
|
|
139
143
|
// results, try to construct a good error message
|
|
140
|
-
return (0, _result.err)((0, _annotate.annotate)([(
|
|
144
|
+
return (0, _result.err)((0, _annotate.annotate)([okOrErr(result1), okOrErr(result2), okOrErr(result3), okOrErr(result4), okOrErr(result5)]));
|
|
141
145
|
}
|
|
142
146
|
});
|
|
143
147
|
}
|
|
@@ -167,7 +171,7 @@ function tuple6(decoder1, decoder2, decoder3, decoder4, decoder5, decoder6) {
|
|
|
167
171
|
} catch (e) {
|
|
168
172
|
// If a decoder error has happened while unwrapping all the
|
|
169
173
|
// results, try to construct a good error message
|
|
170
|
-
return (0, _result.err)((0, _annotate.annotate)([(
|
|
174
|
+
return (0, _result.err)((0, _annotate.annotate)([okOrErr(result1), okOrErr(result2), okOrErr(result3), okOrErr(result4), okOrErr(result5), okOrErr(result6)]));
|
|
171
175
|
}
|
|
172
176
|
});
|
|
173
177
|
}
|
package/core/tuple.js.flow
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { annotate } from '../annotate';
|
|
4
4
|
import { compose, predicate } from './composition';
|
|
5
|
-
import { err, ok,
|
|
5
|
+
import { err, ok, unwrap } from '../result';
|
|
6
6
|
import { poja } from './array';
|
|
7
7
|
import type { Decoder } from '../_types';
|
|
8
|
+
import type { Result } from '../result';
|
|
9
|
+
|
|
10
|
+
function okOrErr<T, E>(result: Result<T, E>): T | E {
|
|
11
|
+
return result.type === 'ok' ? result.value : result.error;
|
|
12
|
+
}
|
|
8
13
|
|
|
9
14
|
const ntuple = (n: number) =>
|
|
10
15
|
compose(
|
|
@@ -26,7 +31,7 @@ export function tuple1<T>(decoder1: Decoder<T>): Decoder<[T]> {
|
|
|
26
31
|
} catch (e) {
|
|
27
32
|
// If a decoder error has happened while unwrapping all the
|
|
28
33
|
// results, try to construct a good error message
|
|
29
|
-
return err(annotate([
|
|
34
|
+
return err(annotate([okOrErr(result1)]));
|
|
30
35
|
}
|
|
31
36
|
});
|
|
32
37
|
}
|
|
@@ -49,7 +54,7 @@ export function tuple2<T1, T2>(
|
|
|
49
54
|
} catch (e) {
|
|
50
55
|
// If a decoder error has happened while unwrapping all the
|
|
51
56
|
// results, try to construct a good error message
|
|
52
|
-
return err(annotate([
|
|
57
|
+
return err(annotate([okOrErr(result1), okOrErr(result2)]));
|
|
53
58
|
}
|
|
54
59
|
});
|
|
55
60
|
}
|
|
@@ -74,13 +79,7 @@ export function tuple3<T1, T2, T3>(
|
|
|
74
79
|
} catch (e) {
|
|
75
80
|
// If a decoder error has happened while unwrapping all the
|
|
76
81
|
// results, try to construct a good error message
|
|
77
|
-
return err(
|
|
78
|
-
annotate([
|
|
79
|
-
okOrErrValue(result1),
|
|
80
|
-
okOrErrValue(result2),
|
|
81
|
-
okOrErrValue(result3),
|
|
82
|
-
]),
|
|
83
|
-
);
|
|
82
|
+
return err(annotate([okOrErr(result1), okOrErr(result2), okOrErr(result3)]));
|
|
84
83
|
}
|
|
85
84
|
});
|
|
86
85
|
}
|
|
@@ -114,10 +113,10 @@ export function tuple4<T1, T2, T3, T4>(
|
|
|
114
113
|
// results, try to construct a good error message
|
|
115
114
|
return err(
|
|
116
115
|
annotate([
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
okOrErr(result1),
|
|
117
|
+
okOrErr(result2),
|
|
118
|
+
okOrErr(result3),
|
|
119
|
+
okOrErr(result4),
|
|
121
120
|
]),
|
|
122
121
|
);
|
|
123
122
|
}
|
|
@@ -156,11 +155,11 @@ export function tuple5<T1, T2, T3, T4, T5>(
|
|
|
156
155
|
// results, try to construct a good error message
|
|
157
156
|
return err(
|
|
158
157
|
annotate([
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
okOrErr(result1),
|
|
159
|
+
okOrErr(result2),
|
|
160
|
+
okOrErr(result3),
|
|
161
|
+
okOrErr(result4),
|
|
162
|
+
okOrErr(result5),
|
|
164
163
|
]),
|
|
165
164
|
);
|
|
166
165
|
}
|
|
@@ -202,12 +201,12 @@ export function tuple6<T1, T2, T3, T4, T5, T6>(
|
|
|
202
201
|
// results, try to construct a good error message
|
|
203
202
|
return err(
|
|
204
203
|
annotate([
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
okOrErr(result1),
|
|
205
|
+
okOrErr(result2),
|
|
206
|
+
okOrErr(result3),
|
|
207
|
+
okOrErr(result4),
|
|
208
|
+
okOrErr(result5),
|
|
209
|
+
okOrErr(result6),
|
|
211
210
|
]),
|
|
212
211
|
);
|
|
213
212
|
}
|
package/package.json
CHANGED
package/result.js
CHANGED
|
@@ -4,15 +4,12 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.andThen = andThen;
|
|
5
5
|
exports.dispatch = dispatch;
|
|
6
6
|
exports.err = err;
|
|
7
|
-
exports.errValue = errValue;
|
|
8
7
|
exports.expect = expect;
|
|
9
8
|
exports.isErr = isErr;
|
|
10
9
|
exports.isOk = isOk;
|
|
11
10
|
exports.mapError = mapError;
|
|
12
11
|
exports.mapOk = mapOk;
|
|
13
12
|
exports.ok = ok;
|
|
14
|
-
exports.okOrErrValue = okOrErrValue;
|
|
15
|
-
exports.okValue = okValue;
|
|
16
13
|
exports.orElse = orElse;
|
|
17
14
|
exports.toString = toString;
|
|
18
15
|
exports.unwrap = unwrap;
|
|
@@ -61,22 +58,6 @@ function isErr(result) {
|
|
|
61
58
|
|
|
62
59
|
function withDefault(result, defaultValue) {
|
|
63
60
|
return result.type === 'ok' ? result.value : defaultValue;
|
|
64
|
-
} // TODO: Remove this from the public API? The same can be achieved now with
|
|
65
|
-
// TODO: const { value } = result;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
function okValue(result) {
|
|
69
|
-
return result.type === 'ok' ? result.value : undefined;
|
|
70
|
-
} // TODO: Remove this from the public API? The same can be achieved now with
|
|
71
|
-
// TODO: const { error } = result;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
function errValue(result) {
|
|
75
|
-
return result.type === 'err' ? result.error : undefined;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function okOrErrValue(result) {
|
|
79
|
-
return result.type === 'ok' ? result.value : result.error;
|
|
80
61
|
}
|
|
81
62
|
/**
|
|
82
63
|
* Unwrap the value from this Result instance if this is an "Ok" result.
|
package/result.js.flow
CHANGED
|
@@ -43,22 +43,6 @@ export function withDefault<T>(result: Result<T, mixed>, defaultValue: T): T {
|
|
|
43
43
|
return result.type === 'ok' ? result.value : defaultValue;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
// TODO: Remove this from the public API? The same can be achieved now with
|
|
47
|
-
// TODO: const { value } = result;
|
|
48
|
-
export function okValue<T>(result: Result<T, mixed>): void | T {
|
|
49
|
-
return result.type === 'ok' ? result.value : undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// TODO: Remove this from the public API? The same can be achieved now with
|
|
53
|
-
// TODO: const { error } = result;
|
|
54
|
-
export function errValue<E>(result: Result<mixed, E>): void | E {
|
|
55
|
-
return result.type === 'err' ? result.error : undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function okOrErrValue<T, E>(result: Result<T, E>): T | E {
|
|
59
|
-
return result.type === 'ok' ? result.value : result.error;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
46
|
/**
|
|
63
47
|
* Unwrap the value from this Result instance if this is an "Ok" result.
|
|
64
48
|
* Otherwise, will throw the "Err" error via a runtime exception.
|