@shirudo/result 1.1.0 → 1.2.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.
Files changed (66) hide show
  1. package/README.md +90 -38
  2. package/dist/collections.cjs +181 -9
  3. package/dist/collections.cjs.map +1 -0
  4. package/dist/collections.d.cts +101 -3
  5. package/dist/collections.d.cts.map +1 -0
  6. package/dist/collections.d.mts +101 -3
  7. package/dist/collections.d.mts.map +1 -0
  8. package/dist/collections.mjs +175 -3
  9. package/dist/collections.mjs.map +1 -0
  10. package/dist/errors-CVgC7NII.cjs +278 -0
  11. package/dist/errors-CVgC7NII.cjs.map +1 -0
  12. package/dist/errors-MuakEcnM.mjs +146 -0
  13. package/dist/errors-MuakEcnM.mjs.map +1 -0
  14. package/dist/errors.cjs +22 -130
  15. package/dist/errors.d.cts +9 -9
  16. package/dist/errors.d.cts.map +1 -1
  17. package/dist/errors.d.mts +9 -9
  18. package/dist/errors.d.mts.map +1 -1
  19. package/dist/errors.mjs +2 -109
  20. package/dist/index.cjs +99 -69
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +87 -74
  23. package/dist/index.d.cts.map +1 -1
  24. package/dist/index.d.mts +87 -74
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +64 -34
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/operators.cjs +412 -31
  29. package/dist/operators.cjs.map +1 -0
  30. package/dist/operators.d.cts +211 -3
  31. package/dist/operators.d.cts.map +1 -0
  32. package/dist/operators.d.mts +211 -3
  33. package/dist/operators.d.mts.map +1 -0
  34. package/dist/operators.mjs +384 -3
  35. package/dist/operators.mjs.map +1 -0
  36. package/dist/{result-q9Na2bGa.mjs → result-DQCpkuOJ.mjs} +36 -17
  37. package/dist/result-DQCpkuOJ.mjs.map +1 -0
  38. package/dist/{result-BBOGxvSH.cjs → result-DoqQufvR.cjs} +36 -17
  39. package/dist/result-DoqQufvR.cjs.map +1 -0
  40. package/dist/{sequence-DDwePRLd.d.cts → sequence-CmugKPbu.d.cts} +105 -84
  41. package/dist/sequence-CmugKPbu.d.cts.map +1 -0
  42. package/dist/{sequence-DDwePRLd.d.mts → sequence-CmugKPbu.d.mts} +105 -84
  43. package/dist/sequence-CmugKPbu.d.mts.map +1 -0
  44. package/package.json +20 -12
  45. package/dist/errors.cjs.map +0 -1
  46. package/dist/errors.mjs.map +0 -1
  47. package/dist/flatten-B_XIkaOK.cjs +0 -208
  48. package/dist/flatten-B_XIkaOK.cjs.map +0 -1
  49. package/dist/flatten-C7D6Kttf.d.mts +0 -81
  50. package/dist/flatten-C7D6Kttf.d.mts.map +0 -1
  51. package/dist/flatten-ChTL5BfA.mjs +0 -167
  52. package/dist/flatten-ChTL5BfA.mjs.map +0 -1
  53. package/dist/flatten-D0K8UcQH.d.cts +0 -81
  54. package/dist/flatten-D0K8UcQH.d.cts.map +0 -1
  55. package/dist/result-BBOGxvSH.cjs.map +0 -1
  56. package/dist/result-q9Na2bGa.mjs.map +0 -1
  57. package/dist/sequence-DDwePRLd.d.cts.map +0 -1
  58. package/dist/sequence-DDwePRLd.d.mts.map +0 -1
  59. package/dist/swap-BnyMBdD_.cjs +0 -552
  60. package/dist/swap-BnyMBdD_.cjs.map +0 -1
  61. package/dist/swap-CFD2g1cB.mjs +0 -385
  62. package/dist/swap-CFD2g1cB.mjs.map +0 -1
  63. package/dist/swap-CrHQZIax.d.cts +0 -212
  64. package/dist/swap-CrHQZIax.d.cts.map +0 -1
  65. package/dist/swap-DT4LdRFV.d.mts +0 -212
  66. package/dist/swap-DT4LdRFV.d.mts.map +0 -1
@@ -0,0 +1,146 @@
1
+ //#region src/describeValue.ts
2
+ const describeUnprintable = (value) => {
3
+ try {
4
+ return Object.prototype.toString.call(value);
5
+ } catch {
6
+ return `[unprintable ${typeof value}]`;
7
+ }
8
+ };
9
+ /**
10
+ * Formats a foreign value for an error message.
11
+ *
12
+ * `String(value)` runs the `toString`, `valueOf` or `Symbol.toPrimitive` of
13
+ * that value. An object with a null prototype has none of them, and a hostile
14
+ * one throws. Without this guard the conversion failure replaces the coded
15
+ * library error, and a caller that matches on the code never sees it.
16
+ */
17
+ function describeValue(value) {
18
+ try {
19
+ return String(value);
20
+ } catch {
21
+ return describeUnprintable(value);
22
+ }
23
+ }
24
+ /**
25
+ * Formats the `message` of a foreign error value, or the value itself when it
26
+ * carries none. The property access belongs to the value, not to this library:
27
+ * a getter or a Proxy trap can throw, and then the value itself is described.
28
+ */
29
+ function describeErrorMessage(value) {
30
+ try {
31
+ if (value !== null && typeof value === "object" && "message" in value) return describeValue(value.message);
32
+ } catch {}
33
+ return describeValue(value);
34
+ }
35
+
36
+ //#endregion
37
+ //#region src/errors.ts
38
+ const ERR_INVALID_RESULT_STATE = "ERR_INVALID_RESULT_STATE";
39
+ /** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
40
+ const ERR_INVALID_STATE = ERR_INVALID_RESULT_STATE;
41
+ const ERR_TASK_YIELD_NOT_RESULT = "ERR_TASK_YIELD_NOT_RESULT";
42
+ const ERR_MATCH_ON_OK = "ERR_MATCH_ON_OK";
43
+ const ERR_MATCH_ERR_HANDLER_NOT_RESULT = "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
44
+ const ERR_MATCH_TAG_MISSING_HANDLER = "ERR_MATCH_TAG_MISSING_HANDLER";
45
+ const ERR_UNWRAP_ON_ERR = "ERR_UNWRAP_ON_ERR";
46
+ const ERR_UNWRAP_ERR_ON_OK = "ERR_UNWRAP_ERR_ON_OK";
47
+ const ERR_EXPECT_OK = "ERR_EXPECT_OK";
48
+ const ERR_EXPECT_ERR = "ERR_EXPECT_ERR";
49
+ const formatResultErrorMessage = (code, message, context) => {
50
+ if (context) return `${code}: ${message} (context: ${context})`;
51
+ return `${code}: ${message}`;
52
+ };
53
+ var ResultError = class extends Error {
54
+ code;
55
+ context;
56
+ constructor(message, code, context) {
57
+ super(formatResultErrorMessage(code, message, context));
58
+ this.code = code;
59
+ this.context = context;
60
+ this.name = new.target.name;
61
+ Object.setPrototypeOf(this, new.target.prototype);
62
+ }
63
+ };
64
+ var ResultTypeError = class extends TypeError {
65
+ code;
66
+ context;
67
+ constructor(message, code, context) {
68
+ super(formatResultErrorMessage(code, message, context));
69
+ this.code = code;
70
+ this.context = context;
71
+ this.name = new.target.name;
72
+ Object.setPrototypeOf(this, new.target.prototype);
73
+ }
74
+ };
75
+ const INVALID_RESULT_STATE_MESSAGE = "Unreachable: Result is neither Ok nor Err";
76
+ var InvalidResultStateError = class extends ResultError {
77
+ constructor(context) {
78
+ super(INVALID_RESULT_STATE_MESSAGE, ERR_INVALID_RESULT_STATE, context);
79
+ }
80
+ };
81
+ var TaskYieldNotResultError = class extends ResultTypeError {
82
+ yieldedValue;
83
+ constructor(yieldedValue) {
84
+ super("task() expected yielded values to be Result. Use `yield*` on a Result.", ERR_TASK_YIELD_NOT_RESULT);
85
+ this.yieldedValue = yieldedValue;
86
+ }
87
+ };
88
+ var MatchOnOkError = class extends ResultTypeError {
89
+ constructor(methodName = "match") {
90
+ super(`${methodName}() can only be called on Err results. Use \`if (result.isErr()) { ... }\` first.`, ERR_MATCH_ON_OK);
91
+ }
92
+ };
93
+ var MatchErrHandlerNotResultError = class extends ResultTypeError {
94
+ handlerName;
95
+ returnedValue;
96
+ constructor(handlerName, returnedValue) {
97
+ super(`matchErr().${handlerName}() handlers must return a Result. Wrap values with ok(...) or err(...).`, ERR_MATCH_ERR_HANDLER_NOT_RESULT);
98
+ this.handlerName = handlerName;
99
+ this.returnedValue = returnedValue;
100
+ }
101
+ };
102
+ var MatchTagMissingHandlerError = class extends ResultTypeError {
103
+ tagValue;
104
+ constructor(tagValue) {
105
+ super(`matchTag() has no handler for tag "${describeValue(tagValue)}".`, ERR_MATCH_TAG_MISSING_HANDLER);
106
+ this.tagValue = tagValue;
107
+ }
108
+ };
109
+ var UnwrapOnErrError = class extends ResultTypeError {
110
+ errorValue;
111
+ constructor(errorValue) {
112
+ super(`Called unwrap() on Err: ${describeValue(errorValue)}`, ERR_UNWRAP_ON_ERR);
113
+ this.errorValue = errorValue;
114
+ }
115
+ };
116
+ var UnwrapErrOnOkError = class extends ResultTypeError {
117
+ okValue;
118
+ constructor(okValue) {
119
+ super(`Called unwrapErr() on Ok: ${describeValue(okValue)}`, ERR_UNWRAP_ERR_ON_OK);
120
+ this.okValue = okValue;
121
+ }
122
+ };
123
+ var ExpectOkError = class extends ResultError {
124
+ expectedMessage;
125
+ errorValue;
126
+ constructor(expectedMessage, errorValue) {
127
+ super(errorValue === void 0 ? expectedMessage : `${expectedMessage}: ${describeValue(errorValue)}`, ERR_EXPECT_OK);
128
+ this.expectedMessage = expectedMessage;
129
+ this.errorValue = errorValue;
130
+ if (errorValue !== void 0) this.cause = errorValue;
131
+ }
132
+ };
133
+ var ExpectErrError = class extends ResultError {
134
+ expectedMessage;
135
+ okValue;
136
+ constructor(expectedMessage, okValue) {
137
+ super(okValue === void 0 ? expectedMessage : `${expectedMessage}: ${describeValue(okValue)}`, ERR_EXPECT_ERR);
138
+ this.expectedMessage = expectedMessage;
139
+ this.okValue = okValue;
140
+ if (okValue !== void 0) this.cause = okValue;
141
+ }
142
+ };
143
+
144
+ //#endregion
145
+ export { describeErrorMessage as S, ResultError as _, ERR_MATCH_ERR_HANDLER_NOT_RESULT as a, UnwrapErrOnOkError as b, ERR_TASK_YIELD_NOT_RESULT as c, ExpectErrError as d, ExpectOkError as f, MatchTagMissingHandlerError as g, MatchOnOkError as h, ERR_INVALID_STATE as i, ERR_UNWRAP_ERR_ON_OK as l, MatchErrHandlerNotResultError as m, ERR_EXPECT_OK as n, ERR_MATCH_ON_OK as o, InvalidResultStateError as p, ERR_INVALID_RESULT_STATE as r, ERR_MATCH_TAG_MISSING_HANDLER as s, ERR_EXPECT_ERR as t, ERR_UNWRAP_ON_ERR as u, ResultTypeError as v, UnwrapOnErrError as x, TaskYieldNotResultError as y };
146
+ //# sourceMappingURL=errors-MuakEcnM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-MuakEcnM.mjs","names":[],"sources":["../src/describeValue.ts","../src/errors.ts"],"sourcesContent":["// `Object.prototype.toString` reads `Symbol.toStringTag`, which can be a\n// getter that throws, so even the fallback needs its own guard.\nconst describeUnprintable = (value: unknown): string => {\n try {\n return Object.prototype.toString.call(value);\n } catch {\n return `[unprintable ${typeof value}]`;\n }\n};\n\n/**\n * Formats a foreign value for an error message.\n *\n * `String(value)` runs the `toString`, `valueOf` or `Symbol.toPrimitive` of\n * that value. An object with a null prototype has none of them, and a hostile\n * one throws. Without this guard the conversion failure replaces the coded\n * library error, and a caller that matches on the code never sees it.\n */\nexport function describeValue(value: unknown): string {\n try {\n return String(value);\n } catch {\n return describeUnprintable(value);\n }\n}\n\n/**\n * Formats the `message` of a foreign error value, or the value itself when it\n * carries none. The property access belongs to the value, not to this library:\n * a getter or a Proxy trap can throw, and then the value itself is described.\n */\nexport function describeErrorMessage(value: unknown): string {\n try {\n if (value !== null && typeof value === 'object' && 'message' in value) {\n return describeValue((value as { message: unknown }).message);\n }\n } catch {\n // The `in` check or the getter threw, so fall through to the value.\n }\n\n return describeValue(value);\n}\n","import { describeValue } from './describeValue';\n\nexport const ERR_INVALID_RESULT_STATE = 'ERR_INVALID_RESULT_STATE' as const;\n/** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */\nexport const ERR_INVALID_STATE: typeof ERR_INVALID_RESULT_STATE = ERR_INVALID_RESULT_STATE;\nexport const ERR_TASK_YIELD_NOT_RESULT = 'ERR_TASK_YIELD_NOT_RESULT' as const;\nexport const ERR_MATCH_ON_OK = 'ERR_MATCH_ON_OK' as const;\nexport const ERR_MATCH_ERR_HANDLER_NOT_RESULT = 'ERR_MATCH_ERR_HANDLER_NOT_RESULT' as const;\nexport const ERR_MATCH_TAG_MISSING_HANDLER = 'ERR_MATCH_TAG_MISSING_HANDLER' as const;\nexport const ERR_UNWRAP_ON_ERR = 'ERR_UNWRAP_ON_ERR' as const;\nexport const ERR_UNWRAP_ERR_ON_OK = 'ERR_UNWRAP_ERR_ON_OK' as const;\nexport const ERR_EXPECT_OK = 'ERR_EXPECT_OK' as const;\nexport const ERR_EXPECT_ERR = 'ERR_EXPECT_ERR' as const;\n\nexport type ResultErrorCode =\n | typeof ERR_INVALID_RESULT_STATE\n | typeof ERR_TASK_YIELD_NOT_RESULT\n | typeof ERR_MATCH_ON_OK\n | typeof ERR_MATCH_ERR_HANDLER_NOT_RESULT\n | typeof ERR_MATCH_TAG_MISSING_HANDLER\n | typeof ERR_UNWRAP_ON_ERR\n | typeof ERR_UNWRAP_ERR_ON_OK\n | typeof ERR_EXPECT_OK\n | typeof ERR_EXPECT_ERR;\n\nconst formatResultErrorMessage = (code: ResultErrorCode, message: string, context?: string): string => {\n if (context) {\n return `${code}: ${message} (context: ${context})`;\n }\n return `${code}: ${message}`;\n};\n\nexport class ResultError extends Error {\n readonly code: ResultErrorCode;\n readonly context?: string;\n\n constructor(message: string, code: ResultErrorCode, context?: string) {\n super(formatResultErrorMessage(code, message, context));\n this.code = code;\n this.context = context;\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ResultTypeError extends TypeError {\n readonly code: ResultErrorCode;\n readonly context?: string;\n\n constructor(message: string, code: ResultErrorCode, context?: string) {\n super(formatResultErrorMessage(code, message, context));\n this.code = code;\n this.context = context;\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nconst INVALID_RESULT_STATE_MESSAGE = 'Unreachable: Result is neither Ok nor Err';\n\nexport class InvalidResultStateError extends ResultError {\n constructor(context?: string) {\n super(INVALID_RESULT_STATE_MESSAGE, ERR_INVALID_RESULT_STATE, context);\n }\n}\n\nexport class TaskYieldNotResultError extends ResultTypeError {\n readonly yieldedValue: unknown;\n\n constructor(yieldedValue: unknown) {\n super('task() expected yielded values to be Result. Use `yield*` on a Result.', ERR_TASK_YIELD_NOT_RESULT);\n this.yieldedValue = yieldedValue;\n }\n}\n\nexport class MatchOnOkError extends ResultTypeError {\n constructor(methodName = 'match') {\n super(`${methodName}() can only be called on Err results. Use \\`if (result.isErr()) { ... }\\` first.`, ERR_MATCH_ON_OK);\n }\n}\n\nexport class MatchErrHandlerNotResultError extends ResultTypeError {\n readonly handlerName: string;\n readonly returnedValue: unknown;\n\n constructor(handlerName: string, returnedValue: unknown) {\n super(`matchErr().${handlerName}() handlers must return a Result. Wrap values with ok(...) or err(...).`, ERR_MATCH_ERR_HANDLER_NOT_RESULT);\n this.handlerName = handlerName;\n this.returnedValue = returnedValue;\n }\n}\n\nexport class MatchTagMissingHandlerError extends ResultTypeError {\n readonly tagValue: unknown;\n\n constructor(tagValue: unknown) {\n super(`matchTag() has no handler for tag \"${describeValue(tagValue)}\".`, ERR_MATCH_TAG_MISSING_HANDLER);\n this.tagValue = tagValue;\n }\n}\n\nexport class UnwrapOnErrError extends ResultTypeError {\n readonly errorValue: unknown;\n\n constructor(errorValue: unknown) {\n super(`Called unwrap() on Err: ${describeValue(errorValue)}`, ERR_UNWRAP_ON_ERR);\n this.errorValue = errorValue;\n }\n}\n\nexport class UnwrapErrOnOkError extends ResultTypeError {\n readonly okValue: unknown;\n\n constructor(okValue: unknown) {\n super(`Called unwrapErr() on Ok: ${describeValue(okValue)}`, ERR_UNWRAP_ERR_ON_OK);\n this.okValue = okValue;\n }\n}\n\nexport class ExpectOkError extends ResultError {\n readonly expectedMessage: string;\n readonly errorValue: unknown;\n\n constructor(expectedMessage: string, errorValue?: unknown) {\n super(errorValue === undefined ? expectedMessage : `${expectedMessage}: ${describeValue(errorValue)}`, ERR_EXPECT_OK);\n this.expectedMessage = expectedMessage;\n this.errorValue = errorValue;\n if (errorValue !== undefined) this.cause = errorValue;\n }\n}\n\nexport class ExpectErrError extends ResultError {\n readonly expectedMessage: string;\n readonly okValue: unknown;\n\n constructor(expectedMessage: string, okValue?: unknown) {\n super(okValue === undefined ? expectedMessage : `${expectedMessage}: ${describeValue(okValue)}`, ERR_EXPECT_ERR);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AAkB,GAAG,gBAAgB,IAAI,cAAc,UAAU,KAAK,aAAa;EACpH,KAAK,kBAAkB;EACvB,KAAK,aAAa;EAClB,IAAI,eAAe,QAAW,KAAK,QAAQ;CAC/C;AACJ;AAEA,IAAa,iBAAb,cAAoC,YAAY;CAC5C,AAAS;CACT,AAAS;CAET,YAAY,iBAAyB,SAAmB;EACpD,MAAM,YAAY,SAAY,kBAAkB,GAAG,gBAAgB,IAAI,cAAc,OAAO,KAAK,cAAc;EAC/G,KAAK,kBAAkB;EACvB,KAAK,UAAU;EACf,IAAI,YAAY,QAAW,KAAK,QAAQ;CAC5C;AACJ"}
package/dist/errors.cjs CHANGED
@@ -1,132 +1,24 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_errors = require('./errors-CVgC7NII.cjs');
2
3
 
3
- //#region src/errors.ts
4
- const ERR_INVALID_RESULT_STATE = "ERR_INVALID_RESULT_STATE";
5
- /** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
6
- const ERR_INVALID_STATE = ERR_INVALID_RESULT_STATE;
7
- const ERR_TASK_YIELD_NOT_RESULT = "ERR_TASK_YIELD_NOT_RESULT";
8
- const ERR_MATCH_ON_OK = "ERR_MATCH_ON_OK";
9
- const ERR_MATCH_ERR_HANDLER_NOT_RESULT = "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
10
- const ERR_MATCH_TAG_MISSING_HANDLER = "ERR_MATCH_TAG_MISSING_HANDLER";
11
- const ERR_UNWRAP_ON_ERR = "ERR_UNWRAP_ON_ERR";
12
- const ERR_UNWRAP_ERR_ON_OK = "ERR_UNWRAP_ERR_ON_OK";
13
- const ERR_EXPECT_OK = "ERR_EXPECT_OK";
14
- const ERR_EXPECT_ERR = "ERR_EXPECT_ERR";
15
- const formatResultErrorMessage = (code, message, context) => {
16
- if (context) return `${code}: ${message} (context: ${context})`;
17
- return `${code}: ${message}`;
18
- };
19
- var ResultError = class extends Error {
20
- code;
21
- context;
22
- constructor(message, code, context) {
23
- super(formatResultErrorMessage(code, message, context));
24
- this.code = code;
25
- this.context = context;
26
- this.name = new.target.name;
27
- Object.setPrototypeOf(this, new.target.prototype);
28
- }
29
- };
30
- var ResultTypeError = class extends TypeError {
31
- code;
32
- context;
33
- constructor(message, code, context) {
34
- super(formatResultErrorMessage(code, message, context));
35
- this.code = code;
36
- this.context = context;
37
- this.name = new.target.name;
38
- Object.setPrototypeOf(this, new.target.prototype);
39
- }
40
- };
41
- const INVALID_RESULT_STATE_MESSAGE = "Unreachable: Result is neither Ok nor Err";
42
- var InvalidResultStateError = class extends ResultError {
43
- constructor(context) {
44
- super(INVALID_RESULT_STATE_MESSAGE, ERR_INVALID_RESULT_STATE, context);
45
- }
46
- };
47
- var TaskYieldNotResultError = class extends ResultTypeError {
48
- yieldedValue;
49
- constructor(yieldedValue) {
50
- super("task() expected yielded values to be Result. Use `yield*` on a Result.", ERR_TASK_YIELD_NOT_RESULT);
51
- this.yieldedValue = yieldedValue;
52
- }
53
- };
54
- var MatchOnOkError = class extends ResultTypeError {
55
- constructor(methodName = "match") {
56
- super(`${methodName}() can only be called on Err results. Use \`if (result.isErr()) { ... }\` first.`, ERR_MATCH_ON_OK);
57
- }
58
- };
59
- var MatchErrHandlerNotResultError = class extends ResultTypeError {
60
- handlerName;
61
- returnedValue;
62
- constructor(handlerName, returnedValue) {
63
- super(`matchErr().${handlerName}() handlers must return a Result. Wrap values with ok(...) or err(...).`, ERR_MATCH_ERR_HANDLER_NOT_RESULT);
64
- this.handlerName = handlerName;
65
- this.returnedValue = returnedValue;
66
- }
67
- };
68
- var MatchTagMissingHandlerError = class extends ResultTypeError {
69
- tagValue;
70
- constructor(tagValue) {
71
- super(`matchTag() has no handler for tag "${String(tagValue)}".`, ERR_MATCH_TAG_MISSING_HANDLER);
72
- this.tagValue = tagValue;
73
- }
74
- };
75
- var UnwrapOnErrError = class extends ResultTypeError {
76
- errorValue;
77
- constructor(errorValue) {
78
- super(`Called unwrap() on Err: ${String(errorValue)}`, ERR_UNWRAP_ON_ERR);
79
- this.errorValue = errorValue;
80
- }
81
- };
82
- var UnwrapErrOnOkError = class extends ResultTypeError {
83
- okValue;
84
- constructor(okValue) {
85
- super(`Called unwrapErr() on Ok: ${String(okValue)}`, ERR_UNWRAP_ERR_ON_OK);
86
- this.okValue = okValue;
87
- }
88
- };
89
- var ExpectOkError = class extends ResultError {
90
- expectedMessage;
91
- errorValue;
92
- constructor(expectedMessage, errorValue) {
93
- super(errorValue === void 0 ? expectedMessage : `${expectedMessage}: ${String(errorValue)}`, ERR_EXPECT_OK);
94
- this.expectedMessage = expectedMessage;
95
- this.errorValue = errorValue;
96
- if (errorValue !== void 0) this.cause = errorValue;
97
- }
98
- };
99
- var ExpectErrError = class extends ResultError {
100
- expectedMessage;
101
- okValue;
102
- constructor(expectedMessage, okValue) {
103
- super(okValue === void 0 ? expectedMessage : `${expectedMessage}: ${String(okValue)}`, ERR_EXPECT_ERR);
104
- this.expectedMessage = expectedMessage;
105
- this.okValue = okValue;
106
- if (okValue !== void 0) this.cause = okValue;
107
- }
108
- };
109
-
110
- //#endregion
111
- exports.ERR_EXPECT_ERR = ERR_EXPECT_ERR;
112
- exports.ERR_EXPECT_OK = ERR_EXPECT_OK;
113
- exports.ERR_INVALID_RESULT_STATE = ERR_INVALID_RESULT_STATE;
114
- exports.ERR_INVALID_STATE = ERR_INVALID_STATE;
115
- exports.ERR_MATCH_ERR_HANDLER_NOT_RESULT = ERR_MATCH_ERR_HANDLER_NOT_RESULT;
116
- exports.ERR_MATCH_ON_OK = ERR_MATCH_ON_OK;
117
- exports.ERR_MATCH_TAG_MISSING_HANDLER = ERR_MATCH_TAG_MISSING_HANDLER;
118
- exports.ERR_TASK_YIELD_NOT_RESULT = ERR_TASK_YIELD_NOT_RESULT;
119
- exports.ERR_UNWRAP_ERR_ON_OK = ERR_UNWRAP_ERR_ON_OK;
120
- exports.ERR_UNWRAP_ON_ERR = ERR_UNWRAP_ON_ERR;
121
- exports.ExpectErrError = ExpectErrError;
122
- exports.ExpectOkError = ExpectOkError;
123
- exports.InvalidResultStateError = InvalidResultStateError;
124
- exports.MatchErrHandlerNotResultError = MatchErrHandlerNotResultError;
125
- exports.MatchOnOkError = MatchOnOkError;
126
- exports.MatchTagMissingHandlerError = MatchTagMissingHandlerError;
127
- exports.ResultError = ResultError;
128
- exports.ResultTypeError = ResultTypeError;
129
- exports.TaskYieldNotResultError = TaskYieldNotResultError;
130
- exports.UnwrapErrOnOkError = UnwrapErrOnOkError;
131
- exports.UnwrapOnErrError = UnwrapOnErrError;
132
- //# sourceMappingURL=errors.cjs.map
4
+ exports.ERR_EXPECT_ERR = require_errors.ERR_EXPECT_ERR;
5
+ exports.ERR_EXPECT_OK = require_errors.ERR_EXPECT_OK;
6
+ exports.ERR_INVALID_RESULT_STATE = require_errors.ERR_INVALID_RESULT_STATE;
7
+ exports.ERR_INVALID_STATE = require_errors.ERR_INVALID_STATE;
8
+ exports.ERR_MATCH_ERR_HANDLER_NOT_RESULT = require_errors.ERR_MATCH_ERR_HANDLER_NOT_RESULT;
9
+ exports.ERR_MATCH_ON_OK = require_errors.ERR_MATCH_ON_OK;
10
+ exports.ERR_MATCH_TAG_MISSING_HANDLER = require_errors.ERR_MATCH_TAG_MISSING_HANDLER;
11
+ exports.ERR_TASK_YIELD_NOT_RESULT = require_errors.ERR_TASK_YIELD_NOT_RESULT;
12
+ exports.ERR_UNWRAP_ERR_ON_OK = require_errors.ERR_UNWRAP_ERR_ON_OK;
13
+ exports.ERR_UNWRAP_ON_ERR = require_errors.ERR_UNWRAP_ON_ERR;
14
+ exports.ExpectErrError = require_errors.ExpectErrError;
15
+ exports.ExpectOkError = require_errors.ExpectOkError;
16
+ exports.InvalidResultStateError = require_errors.InvalidResultStateError;
17
+ exports.MatchErrHandlerNotResultError = require_errors.MatchErrHandlerNotResultError;
18
+ exports.MatchOnOkError = require_errors.MatchOnOkError;
19
+ exports.MatchTagMissingHandlerError = require_errors.MatchTagMissingHandlerError;
20
+ exports.ResultError = require_errors.ResultError;
21
+ exports.ResultTypeError = require_errors.ResultTypeError;
22
+ exports.TaskYieldNotResultError = require_errors.TaskYieldNotResultError;
23
+ exports.UnwrapErrOnOkError = require_errors.UnwrapErrOnOkError;
24
+ exports.UnwrapOnErrError = require_errors.UnwrapOnErrError;
package/dist/errors.d.cts CHANGED
@@ -1,15 +1,15 @@
1
1
  //#region src/errors.d.ts
2
- declare const ERR_INVALID_RESULT_STATE: "ERR_INVALID_RESULT_STATE";
2
+ declare const ERR_INVALID_RESULT_STATE: 'ERR_INVALID_RESULT_STATE';
3
3
  /** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
4
4
  declare const ERR_INVALID_STATE: typeof ERR_INVALID_RESULT_STATE;
5
- declare const ERR_TASK_YIELD_NOT_RESULT: "ERR_TASK_YIELD_NOT_RESULT";
6
- declare const ERR_MATCH_ON_OK: "ERR_MATCH_ON_OK";
7
- declare const ERR_MATCH_ERR_HANDLER_NOT_RESULT: "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
8
- declare const ERR_MATCH_TAG_MISSING_HANDLER: "ERR_MATCH_TAG_MISSING_HANDLER";
9
- declare const ERR_UNWRAP_ON_ERR: "ERR_UNWRAP_ON_ERR";
10
- declare const ERR_UNWRAP_ERR_ON_OK: "ERR_UNWRAP_ERR_ON_OK";
11
- declare const ERR_EXPECT_OK: "ERR_EXPECT_OK";
12
- declare const ERR_EXPECT_ERR: "ERR_EXPECT_ERR";
5
+ declare const ERR_TASK_YIELD_NOT_RESULT: 'ERR_TASK_YIELD_NOT_RESULT';
6
+ declare const ERR_MATCH_ON_OK: 'ERR_MATCH_ON_OK';
7
+ declare const ERR_MATCH_ERR_HANDLER_NOT_RESULT: 'ERR_MATCH_ERR_HANDLER_NOT_RESULT';
8
+ declare const ERR_MATCH_TAG_MISSING_HANDLER: 'ERR_MATCH_TAG_MISSING_HANDLER';
9
+ declare const ERR_UNWRAP_ON_ERR: 'ERR_UNWRAP_ON_ERR';
10
+ declare const ERR_UNWRAP_ERR_ON_OK: 'ERR_UNWRAP_ERR_ON_OK';
11
+ declare const ERR_EXPECT_OK: 'ERR_EXPECT_OK';
12
+ declare const ERR_EXPECT_ERR: 'ERR_EXPECT_ERR';
13
13
  type ResultErrorCode = typeof ERR_INVALID_RESULT_STATE | typeof ERR_TASK_YIELD_NOT_RESULT | typeof ERR_MATCH_ON_OK | typeof ERR_MATCH_ERR_HANDLER_NOT_RESULT | typeof ERR_MATCH_TAG_MISSING_HANDLER | typeof ERR_UNWRAP_ON_ERR | typeof ERR_UNWRAP_ERR_ON_OK | typeof ERR_EXPECT_OK | typeof ERR_EXPECT_ERR;
14
14
  declare class ResultError extends Error {
15
15
  readonly code: ResultErrorCode;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.cts","names":[],"sources":["../src/errors.ts"],"mappings":";cAAa,wBAAA;AAAb;AAAA,cAEa,iBAAA,SAA0B,wBAAA;AAAA,cAC1B,yBAAA;AAAA,cACA,eAAA;AAAA,cACA,gCAAA;AAAA,cACA,6BAAA;AAAA,cACA,iBAAA;AAAA,cACA,oBAAA;AAAA,cACA,aAAA;AAAA,cACA,cAAA;AAAA,KAED,eAAA,UACC,wBAAA,UACA,yBAAA,UACA,eAAA,UACA,gCAAA,UACA,6BAAA,UACA,iBAAA,UACA,oBAAA,UACA,aAAA,UACA,cAAA;AAAA,cASA,WAAA,SAAoB,KAAA;EAAA,SACpB,IAAA,EAAM,eAAA;EAAA,SACN,OAAA;EAET,WAAA,CAAY,OAAA,UAAiB,IAAA,EAAM,eAAA,EAAiB,OAAA;AAAA;AAAA,cAS3C,eAAA,SAAwB,SAAA;EAAA,SACxB,IAAA,EAAM,eAAA;EAAA,SACN,OAAA;EAET,WAAA,CAAY,OAAA,UAAiB,IAAA,EAAM,eAAA,EAAiB,OAAA;AAAA;AAAA,cAW3C,uBAAA,SAAgC,WAAA;EACzC,WAAA,CAAY,OAAA;AAAA;AAAA,cAKH,uBAAA,SAAgC,e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MH,sBAAsB;WACtB;WACA;EAET,YAAY,yBAAyB;;cAQ5B,uBAAuB;WACvB;WACA;EAET,YAAY,yBAAyB"}
package/dist/errors.d.mts CHANGED
@@ -1,15 +1,15 @@
1
1
  //#region src/errors.d.ts
2
- declare const ERR_INVALID_RESULT_STATE: "ERR_INVALID_RESULT_STATE";
2
+ declare const ERR_INVALID_RESULT_STATE: 'ERR_INVALID_RESULT_STATE';
3
3
  /** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
4
4
  declare const ERR_INVALID_STATE: typeof ERR_INVALID_RESULT_STATE;
5
- declare const ERR_TASK_YIELD_NOT_RESULT: "ERR_TASK_YIELD_NOT_RESULT";
6
- declare const ERR_MATCH_ON_OK: "ERR_MATCH_ON_OK";
7
- declare const ERR_MATCH_ERR_HANDLER_NOT_RESULT: "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
8
- declare const ERR_MATCH_TAG_MISSING_HANDLER: "ERR_MATCH_TAG_MISSING_HANDLER";
9
- declare const ERR_UNWRAP_ON_ERR: "ERR_UNWRAP_ON_ERR";
10
- declare const ERR_UNWRAP_ERR_ON_OK: "ERR_UNWRAP_ERR_ON_OK";
11
- declare const ERR_EXPECT_OK: "ERR_EXPECT_OK";
12
- declare const ERR_EXPECT_ERR: "ERR_EXPECT_ERR";
5
+ declare const ERR_TASK_YIELD_NOT_RESULT: 'ERR_TASK_YIELD_NOT_RESULT';
6
+ declare const ERR_MATCH_ON_OK: 'ERR_MATCH_ON_OK';
7
+ declare const ERR_MATCH_ERR_HANDLER_NOT_RESULT: 'ERR_MATCH_ERR_HANDLER_NOT_RESULT';
8
+ declare const ERR_MATCH_TAG_MISSING_HANDLER: 'ERR_MATCH_TAG_MISSING_HANDLER';
9
+ declare const ERR_UNWRAP_ON_ERR: 'ERR_UNWRAP_ON_ERR';
10
+ declare const ERR_UNWRAP_ERR_ON_OK: 'ERR_UNWRAP_ERR_ON_OK';
11
+ declare const ERR_EXPECT_OK: 'ERR_EXPECT_OK';
12
+ declare const ERR_EXPECT_ERR: 'ERR_EXPECT_ERR';
13
13
  type ResultErrorCode = typeof ERR_INVALID_RESULT_STATE | typeof ERR_TASK_YIELD_NOT_RESULT | typeof ERR_MATCH_ON_OK | typeof ERR_MATCH_ERR_HANDLER_NOT_RESULT | typeof ERR_MATCH_TAG_MISSING_HANDLER | typeof ERR_UNWRAP_ON_ERR | typeof ERR_UNWRAP_ERR_ON_OK | typeof ERR_EXPECT_OK | typeof ERR_EXPECT_ERR;
14
14
  declare class ResultError extends Error {
15
15
  readonly code: ResultErrorCode;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";cAAa,wBAAA;AAAb;AAAA,cAEa,iBAAA,SAA0B,wBAAA;AAAA,cAC1B,yBAAA;AAAA,cACA,eAAA;AAAA,cACA,gCAAA;AAAA,cACA,6BAAA;AAAA,cACA,iBAAA;AAAA,cACA,oBAAA;AAAA,cACA,aAAA;AAAA,cACA,cAAA;AAAA,KAED,eAAA,UACC,wBAAA,UACA,yBAAA,UACA,eAAA,UACA,gCAAA,UACA,6BAAA,UACA,iBAAA,UACA,oBAAA,UACA,aAAA,UACA,cAAA;AAAA,cASA,WAAA,SAAoB,KAAA;EAAA,SACpB,IAAA,EAAM,eAAA;EAAA,SACN,OAAA;EAET,WAAA,CAAY,OAAA,UAAiB,IAAA,EAAM,eAAA,EAAiB,OAAA;AAAA;AAAA,cAS3C,eAAA,SAAwB,SAAA;EAAA,SACxB,IAAA,EAAM,eAAA;EAAA,SACN,OAAA;EAET,WAAA,CAAY,OAAA,UAAiB,IAAA,EAAM,eAAA,EAAiB,OAAA;AAAA;AAAA,cAW3C,uBAAA,SAAgC,WAAA;EACzC,WAAA,CAAY,OAAA;AAAA;AAAA,cAKH,uBAAA,SAAgC,eAAA;EAAA,SAChC,YAAA;EAET,WAAA,CAAY,YAAA;AAAA;AAAA,cAMH,cAAA,SAAuB,eAAA;EAChC,WAAA,CAAY,UAAA;AAAA;AAAA,cAKH,6BAAA,SAAsC,eAAA;EAAA,SACtC,WAAA;EAAA,SACA,aAAA;EAET,WAAA,CAAY,WAAA,UAAqB,aAAA;AAAA;AAAA,cAOxB,2BAAA,SAAoC,eAAA;EAAA,SACpC,QAAA;EAET,WAAA,CAAY,QAAA;AAAA;AAAA,cAMH,gBAAA,SAAyB,eAAA;EAAA,SACzB,UAAA;EAET,WAAA,CAAY,UAAA;AAAA;AAAA,cAMH,kBAAA,SAA2B,eAAA;EAAA,SAC3B,OAAA;EAET,WAAA,CAAY,OAAA;AAAA;AAAA,cAMH,aAAA,SAAsB,WAAA;EAAA,SACtB,eAAA;EAAA,SACA,UAAA;EAET,WAAA,CAAY,eAAA,UAAyB,UAAA;AAAA;AAAA,cAQ5B,cAAA,SAAuB,WAAA;EAAA,SACvB,eAAA;EAAA,SACA,OAAA;EAET,WAAA,CAAY,eAAA,UAAyB,OAAA;AAAA"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";cAEa;;cAEA,0BAA0B;cAC1B;cACA;cACA;cACA;cACA;cACA;cACA;cACA;KAED,yBACC,kCACA,mCACA,yBACA,0CACA,uCACA,2BACA,8BACA,uBACA;cASA,oBAAoB;WACpB,MAAM;WACN;EAET,YAAY,iBAAiB,MAAM,iBAAiB;;cAS3C,wBAAwB;WACxB,MAAM;WACN;EAET,YAAY,iBAAiB,MAAM,iBAAiB;;cAW3C,gCAAgC;EACzC,YAAY;;cAKH,gCAAgC;WAChC;EAET,YAAY;;cAMH,uBAAuB;EAChC,YAAY;;cAKH,sCAAsC;WACtC;WACA;EAET,YAAY,qBAAqB;;cAOxB,oCAAoC;WACpC;EAET,YAAY;;cAMH,yBAAyB;WACzB;EAET,YAAY;;cAMH,2BAA2B;WAC3B;EAET,YAAY;;cAMH,sBAAsB;WACtB;WACA;EAET,YAAY,yBAAyB;;cAQ5B,uBAAuB;WACvB;WACA;EAET,YAAY,yBAAyB"}
package/dist/errors.mjs CHANGED
@@ -1,110 +1,3 @@
1
- //#region src/errors.ts
2
- const ERR_INVALID_RESULT_STATE = "ERR_INVALID_RESULT_STATE";
3
- /** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
4
- const ERR_INVALID_STATE = ERR_INVALID_RESULT_STATE;
5
- const ERR_TASK_YIELD_NOT_RESULT = "ERR_TASK_YIELD_NOT_RESULT";
6
- const ERR_MATCH_ON_OK = "ERR_MATCH_ON_OK";
7
- const ERR_MATCH_ERR_HANDLER_NOT_RESULT = "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
8
- const ERR_MATCH_TAG_MISSING_HANDLER = "ERR_MATCH_TAG_MISSING_HANDLER";
9
- const ERR_UNWRAP_ON_ERR = "ERR_UNWRAP_ON_ERR";
10
- const ERR_UNWRAP_ERR_ON_OK = "ERR_UNWRAP_ERR_ON_OK";
11
- const ERR_EXPECT_OK = "ERR_EXPECT_OK";
12
- const ERR_EXPECT_ERR = "ERR_EXPECT_ERR";
13
- const formatResultErrorMessage = (code, message, context) => {
14
- if (context) return `${code}: ${message} (context: ${context})`;
15
- return `${code}: ${message}`;
16
- };
17
- var ResultError = class extends Error {
18
- code;
19
- context;
20
- constructor(message, code, context) {
21
- super(formatResultErrorMessage(code, message, context));
22
- this.code = code;
23
- this.context = context;
24
- this.name = new.target.name;
25
- Object.setPrototypeOf(this, new.target.prototype);
26
- }
27
- };
28
- var ResultTypeError = class extends TypeError {
29
- code;
30
- context;
31
- constructor(message, code, context) {
32
- super(formatResultErrorMessage(code, message, context));
33
- this.code = code;
34
- this.context = context;
35
- this.name = new.target.name;
36
- Object.setPrototypeOf(this, new.target.prototype);
37
- }
38
- };
39
- const INVALID_RESULT_STATE_MESSAGE = "Unreachable: Result is neither Ok nor Err";
40
- var InvalidResultStateError = class extends ResultError {
41
- constructor(context) {
42
- super(INVALID_RESULT_STATE_MESSAGE, ERR_INVALID_RESULT_STATE, context);
43
- }
44
- };
45
- var TaskYieldNotResultError = class extends ResultTypeError {
46
- yieldedValue;
47
- constructor(yieldedValue) {
48
- super("task() expected yielded values to be Result. Use `yield*` on a Result.", ERR_TASK_YIELD_NOT_RESULT);
49
- this.yieldedValue = yieldedValue;
50
- }
51
- };
52
- var MatchOnOkError = class extends ResultTypeError {
53
- constructor(methodName = "match") {
54
- super(`${methodName}() can only be called on Err results. Use \`if (result.isErr()) { ... }\` first.`, ERR_MATCH_ON_OK);
55
- }
56
- };
57
- var MatchErrHandlerNotResultError = class extends ResultTypeError {
58
- handlerName;
59
- returnedValue;
60
- constructor(handlerName, returnedValue) {
61
- super(`matchErr().${handlerName}() handlers must return a Result. Wrap values with ok(...) or err(...).`, ERR_MATCH_ERR_HANDLER_NOT_RESULT);
62
- this.handlerName = handlerName;
63
- this.returnedValue = returnedValue;
64
- }
65
- };
66
- var MatchTagMissingHandlerError = class extends ResultTypeError {
67
- tagValue;
68
- constructor(tagValue) {
69
- super(`matchTag() has no handler for tag "${String(tagValue)}".`, ERR_MATCH_TAG_MISSING_HANDLER);
70
- this.tagValue = tagValue;
71
- }
72
- };
73
- var UnwrapOnErrError = class extends ResultTypeError {
74
- errorValue;
75
- constructor(errorValue) {
76
- super(`Called unwrap() on Err: ${String(errorValue)}`, ERR_UNWRAP_ON_ERR);
77
- this.errorValue = errorValue;
78
- }
79
- };
80
- var UnwrapErrOnOkError = class extends ResultTypeError {
81
- okValue;
82
- constructor(okValue) {
83
- super(`Called unwrapErr() on Ok: ${String(okValue)}`, ERR_UNWRAP_ERR_ON_OK);
84
- this.okValue = okValue;
85
- }
86
- };
87
- var ExpectOkError = class extends ResultError {
88
- expectedMessage;
89
- errorValue;
90
- constructor(expectedMessage, errorValue) {
91
- super(errorValue === void 0 ? expectedMessage : `${expectedMessage}: ${String(errorValue)}`, ERR_EXPECT_OK);
92
- this.expectedMessage = expectedMessage;
93
- this.errorValue = errorValue;
94
- if (errorValue !== void 0) this.cause = errorValue;
95
- }
96
- };
97
- var ExpectErrError = class extends ResultError {
98
- expectedMessage;
99
- okValue;
100
- constructor(expectedMessage, okValue) {
101
- super(okValue === void 0 ? expectedMessage : `${expectedMessage}: ${String(okValue)}`, ERR_EXPECT_ERR);
102
- this.expectedMessage = expectedMessage;
103
- this.okValue = okValue;
104
- if (okValue !== void 0) this.cause = okValue;
105
- }
106
- };
1
+ import { _ as ResultError, a as ERR_MATCH_ERR_HANDLER_NOT_RESULT, b as UnwrapErrOnOkError, c as ERR_TASK_YIELD_NOT_RESULT, d as ExpectErrError, f as ExpectOkError, g as MatchTagMissingHandlerError, h as MatchOnOkError, i as ERR_INVALID_STATE, l as ERR_UNWRAP_ERR_ON_OK, m as MatchErrHandlerNotResultError, n as ERR_EXPECT_OK, o as ERR_MATCH_ON_OK, p as InvalidResultStateError, r as ERR_INVALID_RESULT_STATE, s as ERR_MATCH_TAG_MISSING_HANDLER, t as ERR_EXPECT_ERR, u as ERR_UNWRAP_ON_ERR, v as ResultTypeError, x as UnwrapOnErrError, y as TaskYieldNotResultError } from "./errors-MuakEcnM.mjs";
107
2
 
108
- //#endregion
109
- export { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError };
110
- //# sourceMappingURL=errors.mjs.map
3
+ export { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError };