@shirudo/result 0.0.6 → 1.0.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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +137 -296
  3. package/dist/collections.cjs +12 -0
  4. package/dist/collections.d.cts +3 -0
  5. package/dist/collections.d.mts +3 -0
  6. package/dist/collections.mjs +4 -0
  7. package/dist/errors-2WOswg7r.mjs +95 -0
  8. package/dist/errors-2WOswg7r.mjs.map +1 -0
  9. package/dist/errors-BFjY06EV.d.cts +55 -0
  10. package/dist/errors-BFjY06EV.d.cts.map +1 -0
  11. package/dist/errors-C5qGMRiU.d.mts +55 -0
  12. package/dist/errors-C5qGMRiU.d.mts.map +1 -0
  13. package/dist/errors-D2EMzJQl.cjs +209 -0
  14. package/dist/errors-D2EMzJQl.cjs.map +1 -0
  15. package/dist/errors.cjs +21 -0
  16. package/dist/errors.d.cts +2 -0
  17. package/dist/errors.d.mts +2 -0
  18. package/dist/errors.mjs +3 -0
  19. package/dist/flatten-B8bN6fiI.d.mts +71 -0
  20. package/dist/flatten-B8bN6fiI.d.mts.map +1 -0
  21. package/dist/flatten-C6Y9hx79.mjs +147 -0
  22. package/dist/flatten-C6Y9hx79.mjs.map +1 -0
  23. package/dist/flatten-DK7eJKPx.d.cts +71 -0
  24. package/dist/flatten-DK7eJKPx.d.cts.map +1 -0
  25. package/dist/flatten-Df9U40nO.cjs +182 -0
  26. package/dist/flatten-Df9U40nO.cjs.map +1 -0
  27. package/dist/index.cjs +113 -1018
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +12 -546
  30. package/dist/index.d.cts.map +1 -1
  31. package/dist/index.d.mts +12 -546
  32. package/dist/index.d.mts.map +1 -1
  33. package/dist/index.mjs +25 -935
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/mapOrElse-B0_4r6Jn.mjs +96 -0
  36. package/dist/mapOrElse-B0_4r6Jn.mjs.map +1 -0
  37. package/dist/mapOrElse-B5gx9x2E.d.mts +64 -0
  38. package/dist/mapOrElse-B5gx9x2E.d.mts.map +1 -0
  39. package/dist/mapOrElse-DIe7LkYV.d.cts +64 -0
  40. package/dist/mapOrElse-DIe7LkYV.d.cts.map +1 -0
  41. package/dist/mapOrElse-H-GvAUka.cjs +137 -0
  42. package/dist/mapOrElse-H-GvAUka.cjs.map +1 -0
  43. package/dist/operators.cjs +33 -0
  44. package/dist/operators.d.cts +3 -0
  45. package/dist/operators.d.mts +3 -0
  46. package/dist/operators.mjs +4 -0
  47. package/dist/result-CY-KIivk.cjs +1100 -0
  48. package/dist/result-CY-KIivk.cjs.map +1 -0
  49. package/dist/result-DKKaNdOx.mjs +861 -0
  50. package/dist/result-DKKaNdOx.mjs.map +1 -0
  51. package/dist/sequence-Br6tAIIu.d.cts +419 -0
  52. package/dist/sequence-Br6tAIIu.d.cts.map +1 -0
  53. package/dist/sequence-C0jlR3AY.d.mts +419 -0
  54. package/dist/sequence-C0jlR3AY.d.mts.map +1 -0
  55. package/package.json +44 -10
@@ -0,0 +1,137 @@
1
+ const require_errors = require('./errors-D2EMzJQl.cjs');
2
+
3
+ //#region src/core/fold.ts
4
+ /**
5
+ * Folds the Result into a single value by applying one of two functions.
6
+ * The end of the pipe.
7
+ *
8
+ * This is the pipe operator equivalent of the `.fold()` instance method.
9
+ */
10
+ function fold(handlers) {
11
+ return (source) => {
12
+ if (source.isOk()) return handlers.ok(source.value);
13
+ if (source.isErr()) return handlers.err(source.error);
14
+ throw new require_errors.InvalidResultStateError("fold");
15
+ };
16
+ }
17
+
18
+ //#endregion
19
+ //#region src/core/foldAsync.ts
20
+ /**
21
+ * Async version of `fold`. Folds the Result into a single value asynchronously.
22
+ * The end of the pipe.
23
+ *
24
+ * This is the async pipe operator equivalent of the `.fold()` instance method.
25
+ */
26
+ function foldAsync(handlers) {
27
+ return async (source) => {
28
+ if (source.isOk()) return await handlers.ok(source.value);
29
+ if (source.isErr()) return await handlers.err(source.error);
30
+ throw new require_errors.InvalidResultStateError("foldAsync");
31
+ };
32
+ }
33
+
34
+ //#endregion
35
+ //#region src/core/and.ts
36
+ /**
37
+ * Combines two Results. Returns the second one only if the first is Ok.
38
+ * Corresponds to Rust `and`.
39
+ */
40
+ function and(result, other) {
41
+ if (result.isOk()) return other;
42
+ if (result.isErr()) return result;
43
+ throw new require_errors.InvalidResultStateError("and");
44
+ }
45
+
46
+ //#endregion
47
+ //#region src/core/or.ts
48
+ /**
49
+ * Fallback to another Result if the first is Err.
50
+ * Corresponds to Rust `or`.
51
+ */
52
+ function or(result, other) {
53
+ if (result.isOk()) return result;
54
+ if (result.isErr()) return other;
55
+ throw new require_errors.InvalidResultStateError("or");
56
+ }
57
+
58
+ //#endregion
59
+ //#region src/core/orElse.ts
60
+ /**
61
+ * Fallback with a function that returns a Result.
62
+ * Corresponds to Rust `or_else`.
63
+ */
64
+ function orElse(result, fn) {
65
+ if (result.isOk()) return result;
66
+ if (result.isErr()) return fn(result.error);
67
+ throw new require_errors.InvalidResultStateError("orElse");
68
+ }
69
+
70
+ //#endregion
71
+ //#region src/core/mapOr.ts
72
+ /**
73
+ * Transforms the value or returns a default value.
74
+ * Corresponds to Rust `map_or`.
75
+ */
76
+ function mapOr(result, defaultValue, fn) {
77
+ if (result.isOk()) return fn(result.value);
78
+ if (result.isErr()) return defaultValue;
79
+ throw new require_errors.InvalidResultStateError("mapOr");
80
+ }
81
+
82
+ //#endregion
83
+ //#region src/core/mapOrElse.ts
84
+ /**
85
+ * Transforms the value or calculates a default value using a function.
86
+ * Corresponds to Rust `map_or_else`.
87
+ */
88
+ function mapOrElse(result, defaultFn, fn) {
89
+ if (result.isOk()) return fn(result.value);
90
+ if (result.isErr()) return defaultFn(result.error);
91
+ throw new require_errors.InvalidResultStateError("mapOrElse");
92
+ }
93
+
94
+ //#endregion
95
+ Object.defineProperty(exports, 'and', {
96
+ enumerable: true,
97
+ get: function () {
98
+ return and;
99
+ }
100
+ });
101
+ Object.defineProperty(exports, 'fold', {
102
+ enumerable: true,
103
+ get: function () {
104
+ return fold;
105
+ }
106
+ });
107
+ Object.defineProperty(exports, 'foldAsync', {
108
+ enumerable: true,
109
+ get: function () {
110
+ return foldAsync;
111
+ }
112
+ });
113
+ Object.defineProperty(exports, 'mapOr', {
114
+ enumerable: true,
115
+ get: function () {
116
+ return mapOr;
117
+ }
118
+ });
119
+ Object.defineProperty(exports, 'mapOrElse', {
120
+ enumerable: true,
121
+ get: function () {
122
+ return mapOrElse;
123
+ }
124
+ });
125
+ Object.defineProperty(exports, 'or', {
126
+ enumerable: true,
127
+ get: function () {
128
+ return or;
129
+ }
130
+ });
131
+ Object.defineProperty(exports, 'orElse', {
132
+ enumerable: true,
133
+ get: function () {
134
+ return orElse;
135
+ }
136
+ });
137
+ //# sourceMappingURL=mapOrElse-H-GvAUka.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOrElse-H-GvAUka.cjs","names":["InvalidResultStateError","InvalidResultStateError","InvalidResultStateError","InvalidResultStateError","InvalidResultStateError","InvalidResultStateError","InvalidResultStateError"],"sources":["../src/core/fold.ts","../src/core/foldAsync.ts","../src/core/and.ts","../src/core/or.ts","../src/core/orElse.ts","../src/core/mapOr.ts","../src/core/mapOrElse.ts"],"sourcesContent":["import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Folds the Result into a single value by applying one of two functions.\n * The end of the pipe.\n *\n * This is the pipe operator equivalent of the `.fold()` instance method.\n */\nexport function fold<T, E, R>(handlers: { ok: (val: T) => R; err: (e: E) => R }) {\n return (source: Result<T, E>): R => {\n if (source.isOk()) {\n return handlers.ok(source.value);\n }\n if (source.isErr()) return handlers.err(source.error);\n throw new InvalidResultStateError('fold');\n };\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Async version of `fold`. Folds the Result into a single value asynchronously.\n * The end of the pipe.\n *\n * This is the async pipe operator equivalent of the `.fold()` instance method.\n */\nexport function foldAsync<T, E, R>(handlers: { ok: (val: T) => Promise<R>; err: (e: E) => Promise<R> }) {\n return async (source: Result<T, E>): Promise<R> => {\n if (source.isOk()) {\n return await handlers.ok(source.value);\n }\n if (source.isErr()) return await handlers.err(source.error);\n throw new InvalidResultStateError('foldAsync');\n };\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Combines two Results. Returns the second one only if the first is Ok.\n * Corresponds to Rust `and`.\n */\nexport function and<T, E, U>(result: Result<T, E>, other: Result<U, E>): Result<U, E> {\n if (result.isOk()) return other;\n if (result.isErr()) return result as unknown as Result<U, E>;\n throw new InvalidResultStateError('and');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Fallback to another Result if the first is Err.\n * Corresponds to Rust `or`.\n */\nexport function or<T, E, F>(result: Result<T, E>, other: Result<T, F>): Result<T, F> {\n if (result.isOk()) return result as unknown as Result<T, F>;\n if (result.isErr()) return other;\n throw new InvalidResultStateError('or');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Fallback with a function that returns a Result.\n * Corresponds to Rust `or_else`.\n */\nexport function orElse<T, E, F>(result: Result<T, E>, fn: (error: E) => Result<T, F>): Result<T, F> {\n if (result.isOk()) return result as unknown as Result<T, F>;\n if (result.isErr()) return fn(result.error);\n throw new InvalidResultStateError('orElse');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Transforms the value or returns a default value.\n * Corresponds to Rust `map_or`.\n */\nexport function mapOr<T, E, U>(result: Result<T, E>, defaultValue: U, fn: (value: T) => U): U {\n if (result.isOk()) return fn(result.value);\n if (result.isErr()) return defaultValue;\n throw new InvalidResultStateError('mapOr');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Transforms the value or calculates a default value using a function.\n * Corresponds to Rust `map_or_else`.\n */\nexport function mapOrElse<T, E, U>(result: Result<T, E>, defaultFn: (error: E) => U, fn: (value: T) => U): U {\n if (result.isOk()) return fn(result.value);\n if (result.isErr()) return defaultFn(result.error);\n throw new InvalidResultStateError('mapOrElse');\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,KAAc,UAAmD;AAC7E,SAAQ,WAA4B;AAChC,MAAI,OAAO,MAAM,CACb,QAAO,SAAS,GAAG,OAAO,MAAM;AAEpC,MAAI,OAAO,OAAO,CAAE,QAAO,SAAS,IAAI,OAAO,MAAM;AACrD,QAAM,IAAIA,uCAAwB,OAAO;;;;;;;;;;;;ACNjD,SAAgB,UAAmB,UAAqE;AACpG,QAAO,OAAO,WAAqC;AAC/C,MAAI,OAAO,MAAM,CACb,QAAO,MAAM,SAAS,GAAG,OAAO,MAAM;AAE1C,MAAI,OAAO,OAAO,CAAE,QAAO,MAAM,SAAS,IAAI,OAAO,MAAM;AAC3D,QAAM,IAAIC,uCAAwB,YAAY;;;;;;;;;;ACRtD,SAAgB,IAAa,QAAsB,OAAmC;AAClF,KAAI,OAAO,MAAM,CAAE,QAAO;AAC1B,KAAI,OAAO,OAAO,CAAE,QAAO;AAC3B,OAAM,IAAIC,uCAAwB,MAAM;;;;;;;;;ACH5C,SAAgB,GAAY,QAAsB,OAAmC;AACjF,KAAI,OAAO,MAAM,CAAE,QAAO;AAC1B,KAAI,OAAO,OAAO,CAAE,QAAO;AAC3B,OAAM,IAAIC,uCAAwB,KAAK;;;;;;;;;ACH3C,SAAgB,OAAgB,QAAsB,IAA8C;AAChG,KAAI,OAAO,MAAM,CAAE,QAAO;AAC1B,KAAI,OAAO,OAAO,CAAE,QAAO,GAAG,OAAO,MAAM;AAC3C,OAAM,IAAIC,uCAAwB,SAAS;;;;;;;;;ACH/C,SAAgB,MAAe,QAAsB,cAAiB,IAAwB;AAC1F,KAAI,OAAO,MAAM,CAAE,QAAO,GAAG,OAAO,MAAM;AAC1C,KAAI,OAAO,OAAO,CAAE,QAAO;AAC3B,OAAM,IAAIC,uCAAwB,QAAQ;;;;;;;;;ACH9C,SAAgB,UAAmB,QAAsB,WAA4B,IAAwB;AACzG,KAAI,OAAO,MAAM,CAAE,QAAO,GAAG,OAAO,MAAM;AAC1C,KAAI,OAAO,OAAO,CAAE,QAAO,UAAU,OAAO,MAAM;AAClD,OAAM,IAAIC,uCAAwB,YAAY"}
@@ -0,0 +1,33 @@
1
+ const require_result = require('./result-CY-KIivk.cjs');
2
+ const require_mapOrElse = require('./mapOrElse-H-GvAUka.cjs');
3
+
4
+ exports.and = require_mapOrElse.and;
5
+ exports.bimap = require_result.bimap;
6
+ exports.combine = require_result.combine;
7
+ exports.filter = require_result.filter;
8
+ exports.filterAsync = require_result.filterAsync;
9
+ exports.flatMap = require_result.flatMap;
10
+ exports.flatMapAsync = require_result.flatMapAsync;
11
+ exports.fold = require_mapOrElse.fold;
12
+ exports.foldAsync = require_mapOrElse.foldAsync;
13
+ exports.map = require_result.map;
14
+ exports.mapAsync = require_result.mapAsync;
15
+ exports.mapBoth = require_result.mapBoth;
16
+ exports.mapErr = require_result.mapErr;
17
+ exports.mapErrAsync = require_result.mapErrAsync;
18
+ exports.mapOr = require_mapOrElse.mapOr;
19
+ exports.mapOrElse = require_mapOrElse.mapOrElse;
20
+ exports.match = require_result.match;
21
+ exports.matchAsync = require_result.matchAsync;
22
+ exports.or = require_mapOrElse.or;
23
+ exports.orElse = require_mapOrElse.orElse;
24
+ exports.recover = require_result.recover;
25
+ exports.recoverWith = require_result.recoverWith;
26
+ exports.swap = require_result.swap;
27
+ exports.tap = require_result.tap;
28
+ exports.tapAsync = require_result.tapAsync;
29
+ exports.tryCatch = require_result.tryCatch;
30
+ exports.tryCatchAsync = require_result.tryCatchAsync;
31
+ exports.tryMap = require_result.tryMap;
32
+ exports.tryMapAsync = require_result.tryMapAsync;
33
+ exports.zip = require_result.zip;
@@ -0,0 +1,3 @@
1
+ import { A as recover, B as combine, C as flatMapAsync, D as tryMap, F as flatMap, I as bimap, L as mapBoth, M as match, N as filter, O as tryCatch, P as tap, R as mapErr, S as tapAsync, T as mapAsync, V as zip, b as matchAsync, j as recoverWith, k as swap, v as tryMapAsync, w as mapErrAsync, x as filterAsync, y as tryCatchAsync, z as map } from "./sequence-Br6tAIIu.cjs";
2
+ import { a as and, i as or, n as mapOr, o as foldAsync, r as orElse, s as fold, t as mapOrElse } from "./mapOrElse-DIe7LkYV.cjs";
3
+ export { and, bimap, combine, filter, filterAsync, flatMap, flatMapAsync, fold, foldAsync, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, or, orElse, recover, recoverWith, swap, tap, tapAsync, tryCatch, tryCatchAsync, tryMap, tryMapAsync, zip };
@@ -0,0 +1,3 @@
1
+ import { A as recover, B as combine, C as flatMapAsync, D as tryMap, F as flatMap, I as bimap, L as mapBoth, M as match, N as filter, O as tryCatch, P as tap, R as mapErr, S as tapAsync, T as mapAsync, V as zip, b as matchAsync, j as recoverWith, k as swap, v as tryMapAsync, w as mapErrAsync, x as filterAsync, y as tryCatchAsync, z as map } from "./sequence-C0jlR3AY.mjs";
2
+ import { a as and, i as or, n as mapOr, o as foldAsync, r as orElse, s as fold, t as mapOrElse } from "./mapOrElse-B5gx9x2E.mjs";
3
+ export { and, bimap, combine, filter, filterAsync, flatMap, flatMapAsync, fold, foldAsync, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, or, orElse, recover, recoverWith, swap, tap, tapAsync, tryCatch, tryCatchAsync, tryMap, tryMapAsync, zip };
@@ -0,0 +1,4 @@
1
+ import { A as flatMap, C as tryCatch, D as match, E as recoverWith, F as combine, I as zip, M as mapBoth, N as mapErr, O as filter, P as map, S as tryMap, T as recover, _ as tapAsync, b as mapAsync, g as filterAsync, h as matchAsync, j as bimap, k as tap, m as tryCatchAsync, p as tryMapAsync, v as flatMapAsync, w as swap, y as mapErrAsync } from "./result-DKKaNdOx.mjs";
2
+ import { a as and, i as or, n as mapOr, o as foldAsync, r as orElse, s as fold, t as mapOrElse } from "./mapOrElse-B0_4r6Jn.mjs";
3
+
4
+ export { and, bimap, combine, filter, filterAsync, flatMap, flatMapAsync, fold, foldAsync, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, or, orElse, recover, recoverWith, swap, tap, tapAsync, tryCatch, tryCatchAsync, tryMap, tryMapAsync, zip };