@shirudo/result 1.1.1 → 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.
- package/README.md +6 -2
- package/dist/collections.cjs +181 -9
- package/dist/collections.cjs.map +1 -0
- package/dist/collections.d.cts +101 -3
- package/dist/collections.d.cts.map +1 -0
- package/dist/collections.d.mts +101 -3
- package/dist/collections.d.mts.map +1 -0
- package/dist/collections.mjs +175 -3
- package/dist/collections.mjs.map +1 -0
- package/dist/errors-CVgC7NII.cjs +278 -0
- package/dist/errors-CVgC7NII.cjs.map +1 -0
- package/dist/errors-MuakEcnM.mjs +146 -0
- package/dist/errors-MuakEcnM.mjs.map +1 -0
- package/dist/errors.cjs +22 -130
- package/dist/errors.d.cts +9 -9
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts +9 -9
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +2 -109
- package/dist/index.cjs +99 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -74
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +87 -74
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +64 -34
- package/dist/index.mjs.map +1 -1
- package/dist/operators.cjs +412 -31
- package/dist/operators.cjs.map +1 -0
- package/dist/operators.d.cts +211 -3
- package/dist/operators.d.cts.map +1 -0
- package/dist/operators.d.mts +211 -3
- package/dist/operators.d.mts.map +1 -0
- package/dist/operators.mjs +384 -3
- package/dist/operators.mjs.map +1 -0
- package/dist/{result-q9Na2bGa.mjs → result-DQCpkuOJ.mjs} +36 -17
- package/dist/result-DQCpkuOJ.mjs.map +1 -0
- package/dist/{result-BBOGxvSH.cjs → result-DoqQufvR.cjs} +36 -17
- package/dist/result-DoqQufvR.cjs.map +1 -0
- package/dist/{sequence-DDwePRLd.d.cts → sequence-CmugKPbu.d.cts} +105 -84
- package/dist/sequence-CmugKPbu.d.cts.map +1 -0
- package/dist/{sequence-DDwePRLd.d.mts → sequence-CmugKPbu.d.mts} +105 -84
- package/dist/sequence-CmugKPbu.d.mts.map +1 -0
- package/package.json +20 -12
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/flatten-B_XIkaOK.cjs +0 -208
- package/dist/flatten-B_XIkaOK.cjs.map +0 -1
- package/dist/flatten-C7D6Kttf.d.mts +0 -81
- package/dist/flatten-C7D6Kttf.d.mts.map +0 -1
- package/dist/flatten-ChTL5BfA.mjs +0 -167
- package/dist/flatten-ChTL5BfA.mjs.map +0 -1
- package/dist/flatten-D0K8UcQH.d.cts +0 -81
- package/dist/flatten-D0K8UcQH.d.cts.map +0 -1
- package/dist/result-BBOGxvSH.cjs.map +0 -1
- package/dist/result-q9Na2bGa.mjs.map +0 -1
- package/dist/sequence-DDwePRLd.d.cts.map +0 -1
- package/dist/sequence-DDwePRLd.d.mts.map +0 -1
- package/dist/swap-BnyMBdD_.cjs +0 -552
- package/dist/swap-BnyMBdD_.cjs.map +0 -1
- package/dist/swap-CFD2g1cB.mjs +0 -385
- package/dist/swap-CFD2g1cB.mjs.map +0 -1
- package/dist/swap-CrHQZIax.d.cts +0 -212
- package/dist/swap-CrHQZIax.d.cts.map +0 -1
- package/dist/swap-DT4LdRFV.d.mts +0 -212
- package/dist/swap-DT4LdRFV.d.mts.map +0 -1
|
@@ -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);\n this.expectedMessage = expectedMessage;\n this.okValue = okValue;\n if (okValue !== undefined) this.cause = okValue;\n }\n}\n"],"mappings":"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"}
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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:
|
|
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:
|
|
6
|
-
declare const ERR_MATCH_ON_OK:
|
|
7
|
-
declare const ERR_MATCH_ERR_HANDLER_NOT_RESULT:
|
|
8
|
-
declare const ERR_MATCH_TAG_MISSING_HANDLER:
|
|
9
|
-
declare const ERR_UNWRAP_ON_ERR:
|
|
10
|
-
declare const ERR_UNWRAP_ERR_ON_OK:
|
|
11
|
-
declare const ERR_EXPECT_OK:
|
|
12
|
-
declare const 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;
|
package/dist/errors.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","names":[],"sources":["../src/errors.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"errors.d.cts","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.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
//#region src/errors.d.ts
|
|
2
|
-
declare const 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:
|
|
6
|
-
declare const ERR_MATCH_ON_OK:
|
|
7
|
-
declare const ERR_MATCH_ERR_HANDLER_NOT_RESULT:
|
|
8
|
-
declare const ERR_MATCH_TAG_MISSING_HANDLER:
|
|
9
|
-
declare const ERR_UNWRAP_ON_ERR:
|
|
10
|
-
declare const ERR_UNWRAP_ERR_ON_OK:
|
|
11
|
-
declare const ERR_EXPECT_OK:
|
|
12
|
-
declare const 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;
|
package/dist/errors.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,46 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_result = require('./result-
|
|
3
|
-
const require_errors = require('./errors.cjs');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
2
|
+
const require_result = require('./result-DoqQufvR.cjs');
|
|
3
|
+
const require_errors = require('./errors-CVgC7NII.cjs');
|
|
4
|
+
const require_operators = require('./operators.cjs');
|
|
5
|
+
const require_collections = require('./collections.cjs');
|
|
6
6
|
|
|
7
7
|
//#region src/gen.ts
|
|
8
8
|
async function task(makeGenerator, onThrow) {
|
|
9
9
|
const iterator = makeGenerator();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const decide = (yielded) => {
|
|
11
|
+
if (!require_result.isResult(yielded)) return {
|
|
12
|
+
kind: "throw",
|
|
13
|
+
error: new require_errors.TaskYieldNotResultError(yielded)
|
|
14
|
+
};
|
|
15
|
+
if (yielded.isOk()) return {
|
|
16
|
+
kind: "continue",
|
|
17
|
+
input: yielded.value
|
|
18
|
+
};
|
|
19
|
+
if (yielded.isErr()) return {
|
|
20
|
+
kind: "return",
|
|
21
|
+
result: yielded
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
kind: "throw",
|
|
25
|
+
error: new require_errors.InvalidResultStateError("task")
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const abandon = async (pending) => {
|
|
29
|
+
if (typeof iterator.return !== "function") return pending;
|
|
30
|
+
let completion = pending;
|
|
13
31
|
let step = await iterator.return(void 0);
|
|
14
|
-
while (!step.done)
|
|
32
|
+
while (!step.done) {
|
|
33
|
+
const decision = decide(step.value);
|
|
34
|
+
if (decision.kind === "continue") {
|
|
35
|
+
step = await iterator.next(decision.input);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
completion = decision;
|
|
39
|
+
step = await iterator.return(void 0);
|
|
40
|
+
}
|
|
41
|
+
return completion;
|
|
15
42
|
};
|
|
43
|
+
let input = void 0;
|
|
16
44
|
while (true) {
|
|
17
45
|
let step;
|
|
18
46
|
try {
|
|
@@ -29,36 +57,20 @@ async function task(makeGenerator, onThrow) {
|
|
|
29
57
|
if (!onThrow) throw caught;
|
|
30
58
|
return require_result.err(onThrow(caught));
|
|
31
59
|
}
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
await runGeneratorReturn();
|
|
36
|
-
} catch (caught) {
|
|
37
|
-
if (!onThrow) throw caught;
|
|
38
|
-
return require_result.err(onThrow(caught));
|
|
39
|
-
}
|
|
40
|
-
throw new require_errors.TaskYieldNotResultError(yielded);
|
|
41
|
-
}
|
|
42
|
-
if (yielded.isOk()) {
|
|
43
|
-
input = yielded.value;
|
|
60
|
+
const decision = decide(step.value);
|
|
61
|
+
if (decision.kind === "continue") {
|
|
62
|
+
input = decision.input;
|
|
44
63
|
continue;
|
|
45
64
|
}
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
await runGeneratorReturn();
|
|
49
|
-
} catch (caught) {
|
|
50
|
-
if (!onThrow) throw caught;
|
|
51
|
-
return require_result.err(onThrow(caught));
|
|
52
|
-
}
|
|
53
|
-
return yielded;
|
|
54
|
-
}
|
|
65
|
+
let completion;
|
|
55
66
|
try {
|
|
56
|
-
await
|
|
67
|
+
completion = await abandon(decision);
|
|
57
68
|
} catch (caught) {
|
|
58
69
|
if (!onThrow) throw caught;
|
|
59
70
|
return require_result.err(onThrow(caught));
|
|
60
71
|
}
|
|
61
|
-
|
|
72
|
+
if (completion.kind === "throw") throw completion.error;
|
|
73
|
+
return completion.result;
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
76
|
const gen = task;
|
|
@@ -169,11 +181,29 @@ function expectErr(result, message) {
|
|
|
169
181
|
* by `Result.toSerialized()` and by `JSON.stringify` on a Result.
|
|
170
182
|
*
|
|
171
183
|
* Throws `InvalidResultStateError` for data that is not in that shape.
|
|
184
|
+
*
|
|
185
|
+
* @deprecated Rebuild the Result yourself after validating the payload:
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* const restored = parsed._tag === 'Ok' ? ok(parsed.value) : err(parsed.error);
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* `fromSerialized` only checks the envelope, the `_tag` discriminant plus the
|
|
192
|
+
* absence of an own key of the other state, never the payload itself, while its
|
|
193
|
+
* type parameters claim `T` and `E` for whatever `JSON.parse` returned. It
|
|
194
|
+
* also throws for malformed input at exactly the boundary where a Result
|
|
195
|
+
* should be returned. Validate foreign data with your schema tool and
|
|
196
|
+
* then call `ok`/`err`; the shape is exported as `ResultType<T, E>`. This
|
|
197
|
+
* function will be removed in 2.0.
|
|
172
198
|
*/
|
|
173
199
|
function fromSerialized(data) {
|
|
174
|
-
if (data !== null && typeof data === "object") {
|
|
175
|
-
if (data._tag === "Ok" && "
|
|
176
|
-
if (data._tag === "Err" && "
|
|
200
|
+
if (data !== null && typeof data === "object") try {
|
|
201
|
+
if (data._tag === "Ok" && !Object.hasOwn(data, "error")) return require_result.ok(data.value);
|
|
202
|
+
if (data._tag === "Err" && !Object.hasOwn(data, "value")) return require_result.err(data.error);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
const invalid = new require_errors.InvalidResultStateError("fromSerialized");
|
|
205
|
+
invalid.cause = error;
|
|
206
|
+
throw invalid;
|
|
177
207
|
}
|
|
178
208
|
throw new require_errors.InvalidResultStateError("fromSerialized");
|
|
179
209
|
}
|
|
@@ -282,25 +312,25 @@ exports.TaskYieldNotResultError = require_errors.TaskYieldNotResultError;
|
|
|
282
312
|
exports.UnwrapErrOnOkError = require_errors.UnwrapErrOnOkError;
|
|
283
313
|
exports.UnwrapOnErrError = require_errors.UnwrapOnErrError;
|
|
284
314
|
exports.all = require_result.all;
|
|
285
|
-
exports.and =
|
|
286
|
-
exports.bimap =
|
|
287
|
-
exports.collectAllErrors =
|
|
288
|
-
exports.collectFirstOk =
|
|
289
|
-
exports.collectFirstOkAsync =
|
|
290
|
-
exports.collectFirstOkParallelAsync =
|
|
315
|
+
exports.and = require_operators.and;
|
|
316
|
+
exports.bimap = require_operators.bimap;
|
|
317
|
+
exports.collectAllErrors = require_collections.collectAllErrors;
|
|
318
|
+
exports.collectFirstOk = require_collections.collectFirstOk;
|
|
319
|
+
exports.collectFirstOkAsync = require_collections.collectFirstOkAsync;
|
|
320
|
+
exports.collectFirstOkParallelAsync = require_collections.collectFirstOkParallelAsync;
|
|
291
321
|
exports.combine = require_result.combine;
|
|
292
322
|
exports.contains = contains;
|
|
293
323
|
exports.containsErr = containsErr;
|
|
294
324
|
exports.err = require_result.err;
|
|
295
325
|
exports.expectErr = expectErr;
|
|
296
326
|
exports.expectResult = expectResult;
|
|
297
|
-
exports.filter =
|
|
298
|
-
exports.filterAsync =
|
|
299
|
-
exports.flatMap =
|
|
300
|
-
exports.flatMapAsync =
|
|
301
|
-
exports.flatten =
|
|
302
|
-
exports.fold =
|
|
303
|
-
exports.foldAsync =
|
|
327
|
+
exports.filter = require_operators.filter;
|
|
328
|
+
exports.filterAsync = require_operators.filterAsync;
|
|
329
|
+
exports.flatMap = require_operators.flatMap;
|
|
330
|
+
exports.flatMapAsync = require_operators.flatMapAsync;
|
|
331
|
+
exports.flatten = require_collections.flatten;
|
|
332
|
+
exports.fold = require_operators.fold;
|
|
333
|
+
exports.foldAsync = require_operators.foldAsync;
|
|
304
334
|
exports.fromNullable = require_result.fromNullable;
|
|
305
335
|
exports.fromPromise = require_result.fromPromise;
|
|
306
336
|
exports.fromSerialized = fromSerialized;
|
|
@@ -309,38 +339,38 @@ exports.gen = gen;
|
|
|
309
339
|
exports.isErr = isErr;
|
|
310
340
|
exports.isOk = isOk;
|
|
311
341
|
exports.isResult = require_result.isResult;
|
|
312
|
-
exports.map =
|
|
313
|
-
exports.mapAsync =
|
|
314
|
-
exports.mapBoth =
|
|
315
|
-
exports.mapErr =
|
|
316
|
-
exports.mapErrAsync =
|
|
317
|
-
exports.mapOr =
|
|
318
|
-
exports.mapOrElse =
|
|
319
|
-
exports.match =
|
|
320
|
-
exports.matchAsync =
|
|
342
|
+
exports.map = require_operators.map;
|
|
343
|
+
exports.mapAsync = require_operators.mapAsync;
|
|
344
|
+
exports.mapBoth = require_operators.mapBoth;
|
|
345
|
+
exports.mapErr = require_operators.mapErr;
|
|
346
|
+
exports.mapErrAsync = require_operators.mapErrAsync;
|
|
347
|
+
exports.mapOr = require_operators.mapOr;
|
|
348
|
+
exports.mapOrElse = require_operators.mapOrElse;
|
|
349
|
+
exports.match = require_operators.match;
|
|
350
|
+
exports.matchAsync = require_operators.matchAsync;
|
|
321
351
|
exports.matchTag = require_result.matchTag;
|
|
322
352
|
exports.ok = require_result.ok;
|
|
323
353
|
exports.okIf = require_result.okIf;
|
|
324
354
|
exports.okIfLazy = require_result.okIfLazy;
|
|
325
|
-
exports.or =
|
|
326
|
-
exports.orElse =
|
|
327
|
-
exports.partition =
|
|
328
|
-
exports.recover =
|
|
329
|
-
exports.recoverWith =
|
|
355
|
+
exports.or = require_operators.or;
|
|
356
|
+
exports.orElse = require_operators.orElse;
|
|
357
|
+
exports.partition = require_collections.partition;
|
|
358
|
+
exports.recover = require_operators.recover;
|
|
359
|
+
exports.recoverWith = require_operators.recoverWith;
|
|
330
360
|
exports.sequence = require_result.sequence;
|
|
331
|
-
exports.sequenceRecord =
|
|
332
|
-
exports.swap =
|
|
333
|
-
exports.tap =
|
|
334
|
-
exports.tapAsync =
|
|
361
|
+
exports.sequenceRecord = require_collections.sequenceRecord;
|
|
362
|
+
exports.swap = require_operators.swap;
|
|
363
|
+
exports.tap = require_operators.tap;
|
|
364
|
+
exports.tapAsync = require_operators.tapAsync;
|
|
335
365
|
exports.task = task;
|
|
336
366
|
exports.toNullable = toNullable;
|
|
337
367
|
exports.toPromise = toPromise;
|
|
338
368
|
exports.tryAsync = require_result.tryAsync;
|
|
339
|
-
exports.tryCatch =
|
|
340
|
-
exports.tryCatchAsync =
|
|
369
|
+
exports.tryCatch = require_operators.tryCatch;
|
|
370
|
+
exports.tryCatchAsync = require_operators.tryCatchAsync;
|
|
341
371
|
exports.tryFn = require_result.tryFn;
|
|
342
|
-
exports.tryMap =
|
|
343
|
-
exports.tryMapAsync =
|
|
372
|
+
exports.tryMap = require_operators.tryMap;
|
|
373
|
+
exports.tryMapAsync = require_operators.tryMapAsync;
|
|
344
374
|
exports.unwrap = unwrap;
|
|
345
375
|
exports.unwrapErr = unwrapErr;
|
|
346
376
|
exports.unwrapOr = unwrapOr;
|