decoders 2.0.0-beta8 → 2.0.0-beta9

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/README.md +234 -72
  3. package/_utils.js +1 -1
  4. package/_utils.js.flow +3 -3
  5. package/_utils.mjs +1 -1
  6. package/core/array.d.ts +3 -0
  7. package/core/array.js +12 -1
  8. package/core/array.js.flow +9 -2
  9. package/core/array.mjs +11 -2
  10. package/core/boolean.js +3 -3
  11. package/core/boolean.js.flow +2 -2
  12. package/core/boolean.mjs +2 -2
  13. package/core/composition.d.ts +5 -1
  14. package/core/composition.js +33 -5
  15. package/core/composition.js.flow +31 -5
  16. package/core/composition.mjs +31 -5
  17. package/core/date.js +3 -3
  18. package/core/date.js.flow +2 -2
  19. package/core/date.mjs +2 -2
  20. package/core/dispatch.d.ts +1 -1
  21. package/core/dispatch.js +8 -6
  22. package/core/dispatch.js.flow +9 -8
  23. package/core/dispatch.mjs +6 -5
  24. package/core/either.d.ts +63 -58
  25. package/core/either.js +30 -42
  26. package/core/either.js.flow +38 -84
  27. package/core/either.mjs +34 -34
  28. package/core/instanceOf.d.ts +1 -1
  29. package/core/json.js +3 -3
  30. package/core/json.js.flow +3 -3
  31. package/core/json.mjs +3 -3
  32. package/core/object.d.ts +5 -0
  33. package/core/object.js +59 -2
  34. package/core/object.js.flow +77 -21
  35. package/core/object.mjs +56 -3
  36. package/core/string.d.ts +3 -0
  37. package/core/string.js +15 -3
  38. package/core/string.js.flow +15 -2
  39. package/core/string.mjs +12 -3
  40. package/core/tuple.d.ts +28 -28
  41. package/core/tuple.js +28 -151
  42. package/core/tuple.js.flow +31 -191
  43. package/core/tuple.mjs +27 -141
  44. package/index.d.ts +17 -18
  45. package/index.js +33 -43
  46. package/index.js.flow +17 -18
  47. package/index.mjs +8 -9
  48. package/package.json +1 -1
  49. package/result.d.ts +2 -2
  50. package/result.js +9 -9
  51. package/result.js.flow +11 -11
  52. package/result.mjs +9 -9
  53. package/core/mapping.d.ts +0 -6
  54. package/core/mapping.js +0 -67
  55. package/core/mapping.js.flow +0 -62
  56. package/core/mapping.mjs +0 -58
package/core/boolean.js CHANGED
@@ -7,10 +7,10 @@ var _annotate = require("../annotate");
7
7
 
8
8
  var _result = require("../result");
9
9
 
10
- var _composition = require("./composition");
11
-
12
10
  var _number = require("./number");
13
11
 
12
+ var _composition = require("./composition");
13
+
14
14
  /**
15
15
  * Decoder that only returns Ok for boolean inputs. Err otherwise.
16
16
  */
@@ -34,7 +34,7 @@ var truthy = function truthy(blob) {
34
34
 
35
35
 
36
36
  exports.truthy = truthy;
37
- var numericBoolean = (0, _composition.map)(_number.number, function (n) {
37
+ var numericBoolean = (0, _composition.transform)(_number.number, function (n) {
38
38
  return !!n;
39
39
  });
40
40
  exports.numericBoolean = numericBoolean;
@@ -2,8 +2,8 @@
2
2
 
3
3
  import { annotate } from '../annotate';
4
4
  import { err, ok } from '../result';
5
- import { map } from './composition';
6
5
  import { number } from './number';
6
+ import { transform } from './composition';
7
7
  import type { Decoder } from '../_types';
8
8
 
9
9
  /**
@@ -24,4 +24,4 @@ export const truthy: Decoder<boolean> = (blob: mixed) => {
24
24
  * Decoder that only returns Ok for numeric input values representing booleans.
25
25
  * Returns their boolean representation. Err otherwise.
26
26
  */
27
- export const numericBoolean: Decoder<boolean> = map(number, (n) => !!n);
27
+ export const numericBoolean: Decoder<boolean> = transform(number, (n) => !!n);
package/core/boolean.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { annotate } from '../annotate.mjs';
2
2
  import { err, ok } from '../result.mjs';
3
- import { map } from './composition.mjs';
4
3
  import { number } from './number.mjs';
4
+ import { transform } from './composition.mjs';
5
5
 
6
6
  /**
7
7
  * Decoder that only returns Ok for boolean inputs. Err otherwise.
@@ -23,6 +23,6 @@ export var truthy = function truthy(blob) {
23
23
  * Returns their boolean representation. Err otherwise.
24
24
  */
25
25
 
26
- export var numericBoolean = map(number, function (n) {
26
+ export var numericBoolean = transform(number, function (n) {
27
27
  return !!n;
28
28
  });
@@ -1,6 +1,6 @@
1
1
  import { Decoder } from '../_types';
2
2
 
3
- export function map<T, V>(decoder: Decoder<T>, mapper: (value: T) => V): Decoder<V>;
3
+ export function transform<T, V>(decoder: Decoder<T>, mapper: (value: T) => V): Decoder<V>;
4
4
  export function compose<T, V>(decoder: Decoder<T>, next: Decoder<V, T>): Decoder<V>;
5
5
  export function predicate<T, N extends T>(
6
6
  decoder: Decoder<T>,
@@ -12,3 +12,7 @@ export function predicate<T>(
12
12
  predicate: (value: T) => boolean,
13
13
  msg: string,
14
14
  ): Decoder<T>;
15
+ export function prep<T, I>(
16
+ mapperFn: (blob: unknown) => I,
17
+ decoder: Decoder<T, I>,
18
+ ): Decoder<T>;
@@ -2,21 +2,24 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.compose = compose;
5
- exports.map = map;
6
5
  exports.predicate = predicate;
6
+ exports.prep = prep;
7
+ exports.transform = transform;
7
8
 
8
9
  var _result = require("../result");
9
10
 
10
11
  var _annotate = require("../annotate");
11
12
 
12
13
  /**
13
- * Given a decoder T and a mapping function from T's to V's, returns a decoder
14
- * for V's. This is useful to change the original input data.
14
+ * Accepts any value the given decoder accepts, and on success, will call the
15
+ * mapper value **on the decoded result**. If the mapper function throws an
16
+ * error, the whole decoder will fail using the error message as the failure
17
+ * reason.
15
18
  */
16
- function map(decoder, mapper) {
19
+ function transform(decoder, transformFn) {
17
20
  return compose(decoder, function (x) {
18
21
  try {
19
- return (0, _result.ok)(mapper(x));
22
+ return (0, _result.ok)(transformFn(x));
20
23
  } catch (e) {
21
24
  return (0, _result.err)((0, _annotate.annotate)(x, e instanceof Error ? e.message : String(e)));
22
25
  }
@@ -51,4 +54,29 @@ function predicate(decoder, predicateFn, msg) {
51
54
  return predicateFn(value) ? (0, _result.ok)(value) : (0, _result.err)((0, _annotate.annotate)(value, msg));
52
55
  });
53
56
  };
57
+ }
58
+ /**
59
+ * Pre-process the data input before passing it into the decoder. This gives
60
+ * you the ability to arbitrarily customize the input on the fly before passing
61
+ * it to the decoder. Of course, the input value at that point is still of
62
+ * `unknown` type, so you will have to deal with that accordingly.
63
+ */
64
+
65
+
66
+ function prep(mapperFn, decoder) {
67
+ return function (blob) {
68
+ var blob2;
69
+
70
+ try {
71
+ blob2 = mapperFn(blob);
72
+ } catch (e) {
73
+ return (0, _result.err)((0, _annotate.annotate)(blob, e.message));
74
+ }
75
+
76
+ return (0, _result.orElse)(decoder(blob2), function (ann) {
77
+ return (0, _result.err)((0, _annotate.annotate)(blob, ann.text));
78
+ } // ^^^^ Annotates the _original_ input value
79
+ // (instead of echoing back blob2 in the output)
80
+ );
81
+ };
54
82
  }
@@ -1,17 +1,19 @@
1
1
  // @flow strict
2
2
 
3
- import { andThen, err, ok } from '../result';
3
+ import { andThen, err, ok, orElse } from '../result';
4
4
  import { annotate } from '../annotate';
5
5
  import type { Decoder } from '../_types';
6
6
 
7
7
  /**
8
- * Given a decoder T and a mapping function from T's to V's, returns a decoder
9
- * for V's. This is useful to change the original input data.
8
+ * Accepts any value the given decoder accepts, and on success, will call the
9
+ * mapper value **on the decoded result**. If the mapper function throws an
10
+ * error, the whole decoder will fail using the error message as the failure
11
+ * reason.
10
12
  */
11
- export function map<T, V>(decoder: Decoder<T>, mapper: (T) => V): Decoder<V> {
13
+ export function transform<T, V>(decoder: Decoder<T>, transformFn: (T) => V): Decoder<V> {
12
14
  return compose(decoder, (x) => {
13
15
  try {
14
- return ok(mapper(x));
16
+ return ok(transformFn(x));
15
17
  } catch (e) {
16
18
  return err(annotate(x, e instanceof Error ? e.message : String(e)));
17
19
  }
@@ -46,3 +48,27 @@ export function predicate<T>(
46
48
  predicateFn(value) ? ok(value) : err(annotate(value, msg)),
47
49
  );
48
50
  }
51
+
52
+ /**
53
+ * Pre-process the data input before passing it into the decoder. This gives
54
+ * you the ability to arbitrarily customize the input on the fly before passing
55
+ * it to the decoder. Of course, the input value at that point is still of
56
+ * `unknown` type, so you will have to deal with that accordingly.
57
+ */
58
+ export function prep<I, T>(mapperFn: (mixed) => I, decoder: Decoder<T, I>): Decoder<T> {
59
+ return (blob: mixed) => {
60
+ let blob2;
61
+ try {
62
+ blob2 = mapperFn(blob);
63
+ } catch (e) {
64
+ return err(annotate(blob, e.message));
65
+ }
66
+
67
+ return orElse(
68
+ decoder(blob2),
69
+ (ann) => err(annotate(blob, ann.text)),
70
+ // ^^^^ Annotates the _original_ input value
71
+ // (instead of echoing back blob2 in the output)
72
+ );
73
+ };
74
+ }
@@ -1,14 +1,16 @@
1
- import { andThen, err, ok } from '../result.mjs';
1
+ import { andThen, err, ok, orElse } from '../result.mjs';
2
2
  import { annotate } from '../annotate.mjs';
3
3
 
4
4
  /**
5
- * Given a decoder T and a mapping function from T's to V's, returns a decoder
6
- * for V's. This is useful to change the original input data.
5
+ * Accepts any value the given decoder accepts, and on success, will call the
6
+ * mapper value **on the decoded result**. If the mapper function throws an
7
+ * error, the whole decoder will fail using the error message as the failure
8
+ * reason.
7
9
  */
8
- export function map(decoder, mapper) {
10
+ export function transform(decoder, transformFn) {
9
11
  return compose(decoder, function (x) {
10
12
  try {
11
- return ok(mapper(x));
13
+ return ok(transformFn(x));
12
14
  } catch (e) {
13
15
  return err(annotate(x, e instanceof Error ? e.message : String(e)));
14
16
  }
@@ -41,4 +43,28 @@ export function predicate(decoder, predicateFn, msg) {
41
43
  return predicateFn(value) ? ok(value) : err(annotate(value, msg));
42
44
  });
43
45
  };
46
+ }
47
+ /**
48
+ * Pre-process the data input before passing it into the decoder. This gives
49
+ * you the ability to arbitrarily customize the input on the fly before passing
50
+ * it to the decoder. Of course, the input value at that point is still of
51
+ * `unknown` type, so you will have to deal with that accordingly.
52
+ */
53
+
54
+ export function prep(mapperFn, decoder) {
55
+ return function (blob) {
56
+ var blob2;
57
+
58
+ try {
59
+ blob2 = mapperFn(blob);
60
+ } catch (e) {
61
+ return err(annotate(blob, e.message));
62
+ }
63
+
64
+ return orElse(decoder(blob2), function (ann) {
65
+ return err(annotate(blob, ann.text));
66
+ } // ^^^^ Annotates the _original_ input value
67
+ // (instead of echoing back blob2 in the output)
68
+ );
69
+ };
44
70
  }
package/core/date.js CHANGED
@@ -9,10 +9,10 @@ var _result = require("../result");
9
9
 
10
10
  var _utils = require("../_utils");
11
11
 
12
- var _composition = require("./composition");
13
-
14
12
  var _string = require("./string");
15
13
 
14
+ var _composition = require("./composition");
15
+
16
16
  // Only matches the shape. This "over-matches" some values that still aren't
17
17
  // valid dates (like 9999-99-99), but those will be caught by JS Date's
18
18
  // internal validations
@@ -28,7 +28,7 @@ var date = function date(value) {
28
28
 
29
29
 
30
30
  exports.date = date;
31
- var iso8601 = (0, _composition.map)( // Input itself needs to match the ISO8601 regex...
31
+ var iso8601 = (0, _composition.transform)( // Input itself needs to match the ISO8601 regex...
32
32
  (0, _string.regex)(iso8601_re, 'Must be ISO8601 format'), // Make sure it is a _valid_ date
33
33
  function (value) {
34
34
  var date = new Date(value);
package/core/date.js.flow CHANGED
@@ -3,8 +3,8 @@
3
3
  import { annotate } from '../annotate';
4
4
  import { err, ok } from '../result';
5
5
  import { isDate } from '../_utils';
6
- import { map } from './composition';
7
6
  import { regex } from './string';
7
+ import { transform } from './composition';
8
8
  import type { Decoder } from '../_types';
9
9
 
10
10
  // $FlowFixMe[unclear-type] (not really an issue) - deliberate casting
@@ -23,7 +23,7 @@ export const date: Decoder<Date> = (value: mixed) =>
23
23
  * Decoder that only returns Ok for strings that are valid ISO8601 date
24
24
  * strings. Err otherwise.
25
25
  */
26
- export const iso8601: Decoder<Date> = map(
26
+ export const iso8601: Decoder<Date> = transform(
27
27
  // Input itself needs to match the ISO8601 regex...
28
28
  regex(iso8601_re, 'Must be ISO8601 format'),
29
29
 
package/core/date.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { annotate } from '../annotate.mjs';
2
2
  import { err, ok } from '../result.mjs';
3
3
  import { isDate } from '../_utils.mjs';
4
- import { map } from './composition.mjs';
5
4
  import { regex } from './string.mjs';
5
+ import { transform } from './composition.mjs';
6
6
  // Only matches the shape. This "over-matches" some values that still aren't
7
7
  // valid dates (like 9999-99-99), but those will be caught by JS Date's
8
8
  // internal validations
@@ -15,7 +15,7 @@ export var date = function date(value) {
15
15
  * strings. Err otherwise.
16
16
  */
17
17
 
18
- export var iso8601 = map( // Input itself needs to match the ISO8601 regex...
18
+ export var iso8601 = transform( // Input itself needs to match the ISO8601 regex...
19
19
  regex(iso8601_re, 'Must be ISO8601 format'), // Make sure it is a _valid_ date
20
20
  function (value) {
21
21
  var date = new Date(value);
@@ -2,7 +2,7 @@ import { Decoder, DecoderType } from '../_types';
2
2
 
3
3
  export type Values<T extends object> = T[keyof T];
4
4
 
5
- export function disjointUnion<O extends { [key: string]: Decoder<any> }>(
5
+ export function taggedUnion<O extends { [key: string]: Decoder<any> }>(
6
6
  field: string,
7
7
  mapping: O,
8
8
  ): Decoder<Values<{ [key in keyof O]: DecoderType<O[key]> }>>;
package/core/dispatch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.disjointUnion = disjointUnion;
4
+ exports.taggedUnion = taggedUnion;
5
5
 
6
6
  var _result = require("../result");
7
7
 
@@ -9,6 +9,8 @@ var _object2 = require("./object");
9
9
 
10
10
  var _either = require("./either");
11
11
 
12
+ var _composition = require("./composition");
13
+
12
14
  /**
13
15
  * Dispatches to one of several given decoders, based on the value found at
14
16
  * runtime in the given field. For example, suppose you have these decoders:
@@ -31,23 +33,23 @@ var _either = require("./either");
31
33
  * Then these two decoders are equivalent:
32
34
  *
33
35
  * const shape = either(rectangle, circle)
34
- * const shape = disjointUnion('type', { rectangle, circle })
36
+ * const shape = taggedUnion('type', { rectangle, circle })
35
37
  *
36
38
  * Will be of type Decoder<Rectangle | Circle>.
37
39
  *
38
- * But `disjointUnion` will typically be more runtime-efficient. The reason is
40
+ * But `taggedUnion` will typically be more runtime-efficient. The reason is
39
41
  * that it will first do minimal work to "look ahead" into the `type` field
40
42
  * here, and based on that value, pick the decoder to invoke.
41
43
  *
42
44
  * The `either` version will simply try to invoke each decoder, until it finds
43
45
  * one that matches.
44
46
  *
45
- * Also, the error messages will be less ambiguous using `disjointUnion()`.
47
+ * Also, the error messages will be less ambiguous using `taggedUnion()`.
46
48
  */
47
- function disjointUnion(field, mapping) {
49
+ function taggedUnion(field, mapping) {
48
50
  var _object;
49
51
 
50
- var base = (0, _object2.object)((_object = {}, _object[field] = (0, _either.oneOf)(Object.keys(mapping)), _object));
52
+ var base = (0, _object2.object)((_object = {}, _object[field] = (0, _composition.prep)(String, (0, _either.oneOf)(Object.keys(mapping))), _object));
51
53
  return function (blob) {
52
54
  return (0, _result.andThen)(base(blob), function (baseObj) {
53
55
  var decoderName = baseObj[field];
@@ -3,11 +3,10 @@
3
3
  import { andThen } from '../result';
4
4
  import { object } from './object';
5
5
  import { oneOf } from './either';
6
+ import { prep } from './composition';
7
+ import type { _Any } from '../_utils';
6
8
  import type { Decoder, DecoderType } from '../_types';
7
9
 
8
- // $FlowFixMe[unclear-type] (not really an issue) - deliberate use of `any` - not sure how we should get rid of this
9
- type anything = any;
10
-
11
10
  /**
12
11
  * Dispatches to one of several given decoders, based on the value found at
13
12
  * runtime in the given field. For example, suppose you have these decoders:
@@ -30,24 +29,26 @@ type anything = any;
30
29
  * Then these two decoders are equivalent:
31
30
  *
32
31
  * const shape = either(rectangle, circle)
33
- * const shape = disjointUnion('type', { rectangle, circle })
32
+ * const shape = taggedUnion('type', { rectangle, circle })
34
33
  *
35
34
  * Will be of type Decoder<Rectangle | Circle>.
36
35
  *
37
- * But `disjointUnion` will typically be more runtime-efficient. The reason is
36
+ * But `taggedUnion` will typically be more runtime-efficient. The reason is
38
37
  * that it will first do minimal work to "look ahead" into the `type` field
39
38
  * here, and based on that value, pick the decoder to invoke.
40
39
  *
41
40
  * The `either` version will simply try to invoke each decoder, until it finds
42
41
  * one that matches.
43
42
  *
44
- * Also, the error messages will be less ambiguous using `disjointUnion()`.
43
+ * Also, the error messages will be less ambiguous using `taggedUnion()`.
45
44
  */
46
- export function disjointUnion<O: { +[field: string]: Decoder<anything>, ... }>(
45
+ export function taggedUnion<O: { +[field: string]: Decoder<_Any>, ... }>(
47
46
  field: string,
48
47
  mapping: O,
49
48
  ): Decoder<$Values<$ObjMap<O, DecoderType>>> {
50
- const base = object({ [field]: oneOf(Object.keys(mapping)) });
49
+ const base = object({
50
+ [field]: prep(String, oneOf(Object.keys(mapping))),
51
+ });
51
52
  return (blob: mixed) => {
52
53
  return andThen(base(blob), (baseObj) => {
53
54
  const decoderName = baseObj[field];
package/core/dispatch.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { andThen } from '../result.mjs';
2
2
  import { object } from './object.mjs';
3
3
  import { oneOf } from './either.mjs';
4
+ import { prep } from './composition.mjs';
4
5
 
5
6
  /**
6
7
  * Dispatches to one of several given decoders, based on the value found at
@@ -24,23 +25,23 @@ import { oneOf } from './either.mjs';
24
25
  * Then these two decoders are equivalent:
25
26
  *
26
27
  * const shape = either(rectangle, circle)
27
- * const shape = disjointUnion('type', { rectangle, circle })
28
+ * const shape = taggedUnion('type', { rectangle, circle })
28
29
  *
29
30
  * Will be of type Decoder<Rectangle | Circle>.
30
31
  *
31
- * But `disjointUnion` will typically be more runtime-efficient. The reason is
32
+ * But `taggedUnion` will typically be more runtime-efficient. The reason is
32
33
  * that it will first do minimal work to "look ahead" into the `type` field
33
34
  * here, and based on that value, pick the decoder to invoke.
34
35
  *
35
36
  * The `either` version will simply try to invoke each decoder, until it finds
36
37
  * one that matches.
37
38
  *
38
- * Also, the error messages will be less ambiguous using `disjointUnion()`.
39
+ * Also, the error messages will be less ambiguous using `taggedUnion()`.
39
40
  */
40
- export function disjointUnion(field, mapping) {
41
+ export function taggedUnion(field, mapping) {
41
42
  var _object;
42
43
 
43
- var base = object((_object = {}, _object[field] = oneOf(Object.keys(mapping)), _object));
44
+ var base = object((_object = {}, _object[field] = prep(String, oneOf(Object.keys(mapping))), _object));
44
45
  return function (blob) {
45
46
  return andThen(base(blob), function (baseObj) {
46
47
  var decoderName = baseObj[field];
package/core/either.d.ts CHANGED
@@ -1,61 +1,66 @@
1
1
  import { Decoder, Scalar } from '../_types';
2
2
 
3
- export function either<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
4
- export function either2<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
5
- export function either3<T1, T2, T3>(
6
- d1: Decoder<T1>,
7
- d2: Decoder<T2>,
8
- d3: Decoder<T3>,
9
- ): Decoder<T1 | T2 | T3>;
10
- export function either4<T1, T2, T3, T4>(
11
- d1: Decoder<T1>,
12
- d2: Decoder<T2>,
13
- d3: Decoder<T3>,
14
- d4: Decoder<T4>,
15
- ): Decoder<T1 | T2 | T3 | T4>;
16
- export function either5<T1, T2, T3, T4, T5>(
17
- d1: Decoder<T1>,
18
- d2: Decoder<T2>,
19
- d3: Decoder<T3>,
20
- d4: Decoder<T4>,
21
- d5: Decoder<T5>,
22
- ): Decoder<T1 | T2 | T3 | T4 | T5>;
23
- export function either6<T1, T2, T3, T4, T5, T6>(
24
- d1: Decoder<T1>,
25
- d2: Decoder<T2>,
26
- d3: Decoder<T3>,
27
- d4: Decoder<T4>,
28
- d5: Decoder<T5>,
29
- d6: Decoder<T6>,
30
- ): Decoder<T1 | T2 | T3 | T4 | T5 | T6>;
31
- export function either7<T1, T2, T3, T4, T5, T6, T7>(
32
- d1: Decoder<T1>,
33
- d2: Decoder<T2>,
34
- d3: Decoder<T3>,
35
- d4: Decoder<T4>,
36
- d5: Decoder<T5>,
37
- d6: Decoder<T6>,
38
- d7: Decoder<T7>,
39
- ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
40
- export function either8<T1, T2, T3, T4, T5, T6, T7, T8>(
41
- d1: Decoder<T1>,
42
- d2: Decoder<T2>,
43
- d3: Decoder<T3>,
44
- d4: Decoder<T4>,
45
- d5: Decoder<T5>,
46
- d6: Decoder<T6>,
47
- d7: Decoder<T7>,
48
- d8: Decoder<T8>,
49
- ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
50
- export function either9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
51
- d1: Decoder<T1>,
52
- d2: Decoder<T2>,
53
- d3: Decoder<T3>,
54
- d4: Decoder<T4>,
55
- d5: Decoder<T5>,
56
- d6: Decoder<T6>,
57
- d7: Decoder<T7>,
58
- d8: Decoder<T8>,
59
- d9: Decoder<T9>,
60
- ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
3
+ export type DecoderTypes<T> = T extends ReadonlyArray<Decoder<infer U>> ? U : never;
4
+
5
+ export function either<T extends ReadonlyArray<Decoder<any>>>(
6
+ ...args: T
7
+ ): Decoder<DecoderTypes<T>>;
8
+ // export function either<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
9
+ // export function either2<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
10
+ // export function either3<T1, T2, T3>(
11
+ // d1: Decoder<T1>,
12
+ // d2: Decoder<T2>,
13
+ // d3: Decoder<T3>,
14
+ // ): Decoder<T1 | T2 | T3>;
15
+ // export function either4<T1, T2, T3, T4>(
16
+ // d1: Decoder<T1>,
17
+ // d2: Decoder<T2>,
18
+ // d3: Decoder<T3>,
19
+ // d4: Decoder<T4>,
20
+ // ): Decoder<T1 | T2 | T3 | T4>;
21
+ // export function either5<T1, T2, T3, T4, T5>(
22
+ // d1: Decoder<T1>,
23
+ // d2: Decoder<T2>,
24
+ // d3: Decoder<T3>,
25
+ // d4: Decoder<T4>,
26
+ // d5: Decoder<T5>,
27
+ // ): Decoder<T1 | T2 | T3 | T4 | T5>;
28
+ // export function either6<T1, T2, T3, T4, T5, T6>(
29
+ // d1: Decoder<T1>,
30
+ // d2: Decoder<T2>,
31
+ // d3: Decoder<T3>,
32
+ // d4: Decoder<T4>,
33
+ // d5: Decoder<T5>,
34
+ // d6: Decoder<T6>,
35
+ // ): Decoder<T1 | T2 | T3 | T4 | T5 | T6>;
36
+ // export function either7<T1, T2, T3, T4, T5, T6, T7>(
37
+ // d1: Decoder<T1>,
38
+ // d2: Decoder<T2>,
39
+ // d3: Decoder<T3>,
40
+ // d4: Decoder<T4>,
41
+ // d5: Decoder<T5>,
42
+ // d6: Decoder<T6>,
43
+ // d7: Decoder<T7>,
44
+ // ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
45
+ // export function either8<T1, T2, T3, T4, T5, T6, T7, T8>(
46
+ // d1: Decoder<T1>,
47
+ // d2: Decoder<T2>,
48
+ // d3: Decoder<T3>,
49
+ // d4: Decoder<T4>,
50
+ // d5: Decoder<T5>,
51
+ // d6: Decoder<T6>,
52
+ // d7: Decoder<T7>,
53
+ // d8: Decoder<T8>,
54
+ // ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
55
+ // export function either9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
56
+ // d1: Decoder<T1>,
57
+ // d2: Decoder<T2>,
58
+ // d3: Decoder<T3>,
59
+ // d4: Decoder<T4>,
60
+ // d5: Decoder<T5>,
61
+ // d6: Decoder<T6>,
62
+ // d7: Decoder<T7>,
63
+ // d8: Decoder<T8>,
64
+ // d9: Decoder<T9>,
65
+ // ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
61
66
  export function oneOf<T extends Scalar>(constants: readonly T[]): Decoder<T>;