@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
@@ -1,3 +1,211 @@
1
- import { v as combine, y as zip } from "./sequence-DDwePRLd.cjs";
2
- import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-CrHQZIax.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 };
1
+ import { s as Result, v as combine, y as zip } from "./sequence-CmugKPbu.cjs";
2
+ //#region src/core/map.d.ts
3
+ /**
4
+ * Transforms the value (Ok case).
5
+ * Corresponds to Rust `map`.
6
+ */
7
+ declare function map<T, E, U>(project: (value: T) => U): (source: Result<T, E>) => Result<U, E>;
8
+ //#endregion
9
+ //#region src/core/mapErr.d.ts
10
+ /**
11
+ * Transforms the error (Err case).
12
+ * Corresponds to Rust `map_err`.
13
+ */
14
+ declare function mapErr<T, E, F>(project: (error: E) => F): (source: Result<T, E>) => Result<T, F>;
15
+ //#endregion
16
+ //#region src/core/mapBoth.d.ts
17
+ /**
18
+ * Transforms both the Ok value and the Err error.
19
+ * Corresponds to FP `bimap` / `mapBoth`.
20
+ */
21
+ declare function mapBoth<T, E, U, F>(mapOk: (value: T) => U, mapErr: (error: E) => F): (source: Result<T, E>) => Result<U, F>;
22
+ /**
23
+ * Alias for `mapBoth`.
24
+ */
25
+ declare const bimap: typeof mapBoth;
26
+ //#endregion
27
+ //#region src/core/flatMap.d.ts
28
+ /**
29
+ * Chains another operation that returns a Result.
30
+ * Corresponds to Rust `and_then` or JS `flatMap`.
31
+ */
32
+ declare function flatMap<T, E, U, F>(project: (value: T) => Result<U, F>): (source: Result<T, E>) => Result<U, E | F>;
33
+ //#endregion
34
+ //#region src/core/tap.d.ts
35
+ /**
36
+ * Executes a side effect (logging, debugging) without changing the Result.
37
+ * Corresponds to Rust `inspect` / `inspect_err`.
38
+ */
39
+ declare function tap<T, E>(observer: {
40
+ ok?: (val: T) => void;
41
+ err?: (e: E) => void;
42
+ }): (source: Result<T, E>) => Result<T, E>;
43
+ //#endregion
44
+ //#region src/core/filter.d.ts
45
+ /**
46
+ * Checks a condition. If false, the Result becomes Err.
47
+ * Corresponds to Rust `filter` (partially).
48
+ */
49
+ declare function filter<T, E>(predicate: (val: T) => boolean, errorFn: () => E): (source: Result<T, E>) => Result<T, E>;
50
+ //#endregion
51
+ //#region src/core/fold.d.ts
52
+ /**
53
+ * Folds the Result into a single value by applying one of two functions.
54
+ * The end of the pipe.
55
+ *
56
+ * This is the pipe operator equivalent of the `.fold()` instance method.
57
+ */
58
+ declare function fold<T, E, R>(handlers: {
59
+ ok: (val: T) => R;
60
+ err: (e: E) => R;
61
+ }): (source: Result<T, E>) => R;
62
+ //#endregion
63
+ //#region src/core/tryCatch.d.ts
64
+ /**
65
+ * Executes a function and catches exceptions.
66
+ * Converts exceptions into Result<E>.
67
+ * Corresponds to Rust `Result::from` for fallible operations.
68
+ */
69
+ declare function tryCatch<T>(fn: () => T): <SE>(source: Result<unknown, SE>) => Result<T, unknown>;
70
+ declare function tryCatch<T, E>(fn: () => T, errorMapper: (error: unknown) => E): <SE>(source: Result<unknown, SE>) => Result<T, SE | E>;
71
+ //#endregion
72
+ //#region src/core/tryMap.d.ts
73
+ /**
74
+ * Like `map`, but catches exceptions and converts them to Err.
75
+ */
76
+ declare function tryMap<T, E, U>(project: (value: T) => U): (source: Result<T, E>) => Result<U, unknown>;
77
+ declare function tryMap<T, E, U, F>(project: (value: T) => U, errorMapper: (error: unknown) => F): (source: Result<T, E>) => Result<U, E | F>;
78
+ //#endregion
79
+ //#region src/core/recover.d.ts
80
+ /**
81
+ * Recover: converts Err to Ok(defaultValue).
82
+ * Result is guaranteed to be Ok → Error type becomes `never`.
83
+ */
84
+ declare function recover<T, E, F>(defaultValue: F): (source: Result<T, E>) => Result<T | F, never>;
85
+ /**
86
+ * Like `recover`, but calculates the default value based on the error.
87
+ */
88
+ declare function recoverWith<T, E, F>(fn: (error: E) => F): (source: Result<T, E>) => Result<T | F, never>;
89
+ //#endregion
90
+ //#region src/core/match.d.ts
91
+ /**
92
+ * Resolves the Result. The end of the pipe.
93
+ * Corresponds to Rust `match`.
94
+ */
95
+ declare function match<T, E, R>(handlers: {
96
+ ok: (val: T) => R;
97
+ err: (e: E) => R;
98
+ }): (source: Result<T, E>) => R;
99
+ //#endregion
100
+ //#region src/core/mapAsync.d.ts
101
+ /**
102
+ * Async version of map.
103
+ */
104
+ declare function mapAsync<T, E, U>(project: (value: T) => Promise<U>): (source: Result<T, E>) => Promise<Result<U, E>>;
105
+ //#endregion
106
+ //#region src/core/mapErrAsync.d.ts
107
+ /**
108
+ * Async version of mapErr.
109
+ */
110
+ declare function mapErrAsync<T, E, F>(project: (error: E) => Promise<F>): (source: Result<T, E>) => Promise<Result<T, F>>;
111
+ //#endregion
112
+ //#region src/core/flatMapAsync.d.ts
113
+ /**
114
+ * Async version of flatMap.
115
+ */
116
+ declare function flatMapAsync<T, E, U, F>(project: (value: T) => Promise<Result<U, F>>): (source: Result<T, E>) => Promise<Result<U, E | F>>;
117
+ //#endregion
118
+ //#region src/core/tapAsync.d.ts
119
+ /**
120
+ * Async version of tap.
121
+ */
122
+ declare function tapAsync<T, E>(observer: {
123
+ ok?: (val: T) => Promise<void>;
124
+ err?: (e: E) => Promise<void>;
125
+ }): (source: Result<T, E>) => Promise<Result<T, E>>;
126
+ //#endregion
127
+ //#region src/core/filterAsync.d.ts
128
+ /**
129
+ * Async version of filter.
130
+ */
131
+ declare function filterAsync<T, E>(predicate: (val: T) => Promise<boolean>, errorFn: () => Promise<E>): (source: Result<T, E>) => Promise<Result<T, E>>;
132
+ //#endregion
133
+ //#region src/core/foldAsync.d.ts
134
+ /**
135
+ * Async version of `fold`. Folds the Result into a single value asynchronously.
136
+ * The end of the pipe.
137
+ *
138
+ * This is the async pipe operator equivalent of the `.fold()` instance method.
139
+ */
140
+ declare function foldAsync<T, E, R>(handlers: {
141
+ ok: (val: T) => Promise<R>;
142
+ err: (e: E) => Promise<R>;
143
+ }): (source: Result<T, E>) => Promise<R>;
144
+ //#endregion
145
+ //#region src/core/tryCatchAsync.d.ts
146
+ /**
147
+ * Async version of tryCatch.
148
+ */
149
+ declare function tryCatchAsync<T>(fn: () => Promise<T>): <SE>(source: Result<unknown, SE>) => Promise<Result<T, unknown>>;
150
+ declare function tryCatchAsync<T, E>(fn: () => Promise<T>, errorMapper: (error: unknown) => E): <SE>(source: Result<unknown, SE>) => Promise<Result<T, SE | E>>;
151
+ //#endregion
152
+ //#region src/core/tryMapAsync.d.ts
153
+ /**
154
+ * Async version of tryMap.
155
+ */
156
+ declare function tryMapAsync<T, E, U>(project: (value: T) => Promise<U>): (source: Result<T, E>) => Promise<Result<U, unknown>>;
157
+ declare function tryMapAsync<T, E, U, F>(project: (value: T) => Promise<U>, errorMapper: (error: unknown) => F): (source: Result<T, E>) => Promise<Result<U, E | F>>;
158
+ //#endregion
159
+ //#region src/core/matchAsync.d.ts
160
+ /**
161
+ * Async version of match.
162
+ */
163
+ declare function matchAsync<T, E, R>(handlers: {
164
+ ok: (val: T) => Promise<R>;
165
+ err: (e: E) => Promise<R>;
166
+ }): (source: Result<T, E>) => Promise<R>;
167
+ //#endregion
168
+ //#region src/core/and.d.ts
169
+ /**
170
+ * Combines two Results. Returns the second one only if the first is Ok.
171
+ * Corresponds to Rust `and`.
172
+ */
173
+ declare function and<T, E, U>(result: Result<T, E>, other: Result<U, E>): Result<U, E>;
174
+ //#endregion
175
+ //#region src/core/or.d.ts
176
+ /**
177
+ * Fallback to another Result if the first is Err.
178
+ * Corresponds to Rust `or`.
179
+ */
180
+ declare function or<T, E, F>(result: Result<T, E>, other: Result<T, F>): Result<T, F>;
181
+ //#endregion
182
+ //#region src/core/orElse.d.ts
183
+ /**
184
+ * Fallback with a function that returns a Result.
185
+ * Corresponds to Rust `or_else`.
186
+ */
187
+ declare function orElse<T, E, F>(result: Result<T, E>, fn: (error: E) => Result<T, F>): Result<T, F>;
188
+ //#endregion
189
+ //#region src/core/mapOr.d.ts
190
+ /**
191
+ * Transforms the value or returns a default value.
192
+ * Corresponds to Rust `map_or`.
193
+ */
194
+ declare function mapOr<T, E, U>(result: Result<T, E>, defaultValue: U, fn: (value: T) => U): U;
195
+ //#endregion
196
+ //#region src/core/mapOrElse.d.ts
197
+ /**
198
+ * Transforms the value or calculates a default value using a function.
199
+ * Corresponds to Rust `map_or_else`.
200
+ */
201
+ declare function mapOrElse<T, E, U>(result: Result<T, E>, defaultFn: (error: E) => U, fn: (value: T) => U): U;
202
+ //#endregion
203
+ //#region src/core/swap.d.ts
204
+ /**
205
+ * Swaps Ok and Err.
206
+ * Result<T, E> → Result<E, T>
207
+ */
208
+ declare function swap<T, E>(result: Result<T, E>): Result<E, T>;
209
+ //#endregion
210
+ 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 };
211
+ //# sourceMappingURL=operators.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operators.d.cts","names":[],"sources":["../src/core/map.ts","../src/core/mapErr.ts","../src/core/mapBoth.ts","../src/core/flatMap.ts","../src/core/tap.ts","../src/core/filter.ts","../src/core/fold.ts","../src/core/tryCatch.ts","../src/core/tryMap.ts","../src/core/recover.ts","../src/core/match.ts","../src/core/mapAsync.ts","../src/core/mapErrAsync.ts","../src/core/flatMapAsync.ts","../src/core/tapAsync.ts","../src/core/filterAsync.ts","../src/core/foldAsync.ts","../src/core/tryCatchAsync.ts","../src/core/tryMapAsync.ts","../src/core/matchAsync.ts","../src/core/and.ts","../src/core/or.ts","../src/core/orElse.ts","../src/core/mapOr.ts","../src/core/mapOrElse.ts","../src/core/swap.ts"],"mappings":";;;;;;iBAQgB,IAAI,GAAG,GAAG,GAAG,UAAU,OAAO,MAAM,KAAC,Q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OAAO,MAAM,QAAQ,MAAM,QAAQ,OAAO,GAAG,OAAO,QAAQ,OAAO;iBAClG,YAAY,GAAG,GAAG,GAAG,GACjC,UAAU,OAAO,MAAM,QAAQ,IAC/B,cAAc,mBAAmB,KACjC,QAAQ,OAAO,GAAG,OAAO,QAAQ,OAAO,GAAG,IAAI;;;;;;iBCLnC,WAAW,GAAG,GAAG,GAAG;EAAY,KAAK,KAAK,MAAM,QAAQ;EAAI,MAAM,GAAG,MAAM,QAAQ;KAAI,QAC7E,OAAO,GAAG,OAAK,QAAQ;;;;;;;iBCAjC,IAAI,GAAG,GAAG,GAAG,QAAQ,OAAO,GAAG,IAAI,OAAO,OAAO,GAAG,KAAK,OAAO,GAAG;;;;;;;iBCAnE,GAAG,GAAG,GAAG,GAAG,QAAQ,OAAO,GAAG,IAAI,OAAO,OAAO,GAAG,KAAK,OAAO,GAAG;;;;;;;iBCAlE,OAAO,GAAG,GAAG,GAAG,QAAQ,OAAO,GAAG,IAAI,KAAK,OAAO,MAAM,OAAO,GAAG,KAAK,OAAO,GAAG;;;;;;;iBCAjF,MAAM,GAAG,GAAG,GAAG,QAAQ,OAAO,GAAG,IAAI,cAAc,GAAG,KAAK,OAAO,MAAM,IAAI;;;;;;;iBCA5E,UAAU,GAAG,GAAG,GAAG,QAAQ,OAAO,GAAG,IAAI,YAAY,OAAO,MAAM,GAAG,KAAK,OAAO,MAAM,IAAI;;;;;;;iBCC3F,KAAK,GAAG,GAAG,QAAQ,OAAO,GAAG,KAAK,OAAO,GAAG"}
@@ -1,3 +1,211 @@
1
- import { v as combine, y as zip } from "./sequence-DDwePRLd.mjs";
2
- import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-DT4LdRFV.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 };
1
+ import { s as Result, v as combine, y as zip } from "./sequence-CmugKPbu.mjs";
2
+ //#region src/core/map.d.ts
3
+ /**
4
+ * Transforms the value (Ok case).
5
+ * Corresponds to Rust `map`.
6
+ */
7
+ declare function map<T, E, U>(project: (value: T) => U): (source: Result<T, E>) => Result<U, E>;
8
+ //#endregion
9
+ //#region src/core/mapErr.d.ts
10
+ /**
11
+ * Transforms the error (Err case).
12
+ * Corresponds to Rust `map_err`.
13
+ */
14
+ declare function mapErr<T, E, F>(project: (error: E) => F): (source: Result<T, E>) => Result<T, F>;
15
+ //#endregion
16
+ //#region src/core/mapBoth.d.ts
17
+ /**
18
+ * Transforms both the Ok value and the Err error.
19
+ * Corresponds to FP `bimap` / `mapBoth`.
20
+ */
21
+ declare function mapBoth<T, E, U, F>(mapOk: (value: T) => U, mapErr: (error: E) => F): (source: Result<T, E>) => Result<U, F>;
22
+ /**
23
+ * Alias for `mapBoth`.
24
+ */
25
+ declare const bimap: typeof mapBoth;
26
+ //#endregion
27
+ //#region src/core/flatMap.d.ts
28
+ /**
29
+ * Chains another operation that returns a Result.
30
+ * Corresponds to Rust `and_then` or JS `flatMap`.
31
+ */
32
+ declare function flatMap<T, E, U, F>(project: (value: T) => Result<U, F>): (source: Result<T, E>) => Result<U, E | F>;
33
+ //#endregion
34
+ //#region src/core/tap.d.ts
35
+ /**
36
+ * Executes a side effect (logging, debugging) without changing the Result.
37
+ * Corresponds to Rust `inspect` / `inspect_err`.
38
+ */
39
+ declare function tap<T, E>(observer: {
40
+ ok?: (val: T) => void;
41
+ err?: (e: E) => void;
42
+ }): (source: Result<T, E>) => Result<T, E>;
43
+ //#endregion
44
+ //#region src/core/filter.d.ts
45
+ /**
46
+ * Checks a condition. If false, the Result becomes Err.
47
+ * Corresponds to Rust `filter` (partially).
48
+ */
49
+ declare function filter<T, E>(predicate: (val: T) => boolean, errorFn: () => E): (source: Result<T, E>) => Result<T, E>;
50
+ //#endregion
51
+ //#region src/core/fold.d.ts
52
+ /**
53
+ * Folds the Result into a single value by applying one of two functions.
54
+ * The end of the pipe.
55
+ *
56
+ * This is the pipe operator equivalent of the `.fold()` instance method.
57
+ */
58
+ declare function fold<T, E, R>(handlers: {
59
+ ok: (val: T) => R;
60
+ err: (e: E) => R;
61
+ }): (source: Result<T, E>) => R;
62
+ //#endregion
63
+ //#region src/core/tryCatch.d.ts
64
+ /**
65
+ * Executes a function and catches exceptions.
66
+ * Converts exceptions into Result<E>.
67
+ * Corresponds to Rust `Result::from` for fallible operations.
68
+ */
69
+ declare function tryCatch<T>(fn: () => T): <SE>(source: Result<unknown, SE>) => Result<T, unknown>;
70
+ declare function tryCatch<T, E>(fn: () => T, errorMapper: (error: unknown) => E): <SE>(source: Result<unknown, SE>) => Result<T, SE | E>;
71
+ //#endregion
72
+ //#region src/core/tryMap.d.ts
73
+ /**
74
+ * Like `map`, but catches exceptions and converts them to Err.
75
+ */
76
+ declare function tryMap<T, E, U>(project: (value: T) => U): (source: Result<T, E>) => Result<U, unknown>;
77
+ declare function tryMap<T, E, U, F>(project: (value: T) => U, errorMapper: (error: unknown) => F): (source: Result<T, E>) => Result<U, E | F>;
78
+ //#endregion
79
+ //#region src/core/recover.d.ts
80
+ /**
81
+ * Recover: converts Err to Ok(defaultValue).
82
+ * Result is guaranteed to be Ok → Error type becomes `never`.
83
+ */
84
+ declare function recover<T, E, F>(defaultValue: F): (source: Result<T, E>) => Result<T | F, never>;
85
+ /**
86
+ * Like `recover`, but calculates the default value based on the error.
87
+ */
88
+ declare function recoverWith<T, E, F>(fn: (error: E) => F): (source: Result<T, E>) => Result<T | F, never>;
89
+ //#endregion
90
+ //#region src/core/match.d.ts
91
+ /**
92
+ * Resolves the Result. The end of the pipe.
93
+ * Corresponds to Rust `match`.
94
+ */
95
+ declare function match<T, E, R>(handlers: {
96
+ ok: (val: T) => R;
97
+ err: (e: E) => R;
98
+ }): (source: Result<T, E>) => R;
99
+ //#endregion
100
+ //#region src/core/mapAsync.d.ts
101
+ /**
102
+ * Async version of map.
103
+ */
104
+ declare function mapAsync<T, E, U>(project: (value: T) => Promise<U>): (source: Result<T, E>) => Promise<Result<U, E>>;
105
+ //#endregion
106
+ //#region src/core/mapErrAsync.d.ts
107
+ /**
108
+ * Async version of mapErr.
109
+ */
110
+ declare function mapErrAsync<T, E, F>(project: (error: E) => Promise<F>): (source: Result<T, E>) => Promise<Result<T, F>>;
111
+ //#endregion
112
+ //#region src/core/flatMapAsync.d.ts
113
+ /**
114
+ * Async version of flatMap.
115
+ */
116
+ declare function flatMapAsync<T, E, U, F>(project: (value: T) => Promise<Result<U, F>>): (source: Result<T, E>) => Promise<Result<U, E | F>>;
117
+ //#endregion
118
+ //#region src/core/tapAsync.d.ts
119
+ /**
120
+ * Async version of tap.
121
+ */
122
+ declare function tapAsync<T, E>(observer: {
123
+ ok?: (val: T) => Promise<void>;
124
+ err?: (e: E) => Promise<void>;
125
+ }): (source: Result<T, E>) => Promise<Result<T, E>>;
126
+ //#endregion
127
+ //#region src/core/filterAsync.d.ts
128
+ /**
129
+ * Async version of filter.
130
+ */
131
+ declare function filterAsync<T, E>(predicate: (val: T) => Promise<boolean>, errorFn: () => Promise<E>): (source: Result<T, E>) => Promise<Result<T, E>>;
132
+ //#endregion
133
+ //#region src/core/foldAsync.d.ts
134
+ /**
135
+ * Async version of `fold`. Folds the Result into a single value asynchronously.
136
+ * The end of the pipe.
137
+ *
138
+ * This is the async pipe operator equivalent of the `.fold()` instance method.
139
+ */
140
+ declare function foldAsync<T, E, R>(handlers: {
141
+ ok: (val: T) => Promise<R>;
142
+ err: (e: E) => Promise<R>;
143
+ }): (source: Result<T, E>) => Promise<R>;
144
+ //#endregion
145
+ //#region src/core/tryCatchAsync.d.ts
146
+ /**
147
+ * Async version of tryCatch.
148
+ */
149
+ declare function tryCatchAsync<T>(fn: () => Promise<T>): <SE>(source: Result<unknown, SE>) => Promise<Result<T, unknown>>;
150
+ declare function tryCatchAsync<T, E>(fn: () => Promise<T>, errorMapper: (error: unknown) => E): <SE>(source: Result<unknown, SE>) => Promise<Result<T, SE | E>>;
151
+ //#endregion
152
+ //#region src/core/tryMapAsync.d.ts
153
+ /**
154
+ * Async version of tryMap.
155
+ */
156
+ declare function tryMapAsync<T, E, U>(project: (value: T) => Promise<U>): (source: Result<T, E>) => Promise<Result<U, unknown>>;
157
+ declare function tryMapAsync<T, E, U, F>(project: (value: T) => Promise<U>, errorMapper: (error: unknown) => F): (source: Result<T, E>) => Promise<Result<U, E | F>>;
158
+ //#endregion
159
+ //#region src/core/matchAsync.d.ts
160
+ /**
161
+ * Async version of match.
162
+ */
163
+ declare function matchAsync<T, E, R>(handlers: {
164
+ ok: (val: T) => Promise<R>;
165
+ err: (e: E) => Promise<R>;
166
+ }): (source: Result<T, E>) => Promise<R>;
167
+ //#endregion
168
+ //#region src/core/and.d.ts
169
+ /**
170
+ * Combines two Results. Returns the second one only if the first is Ok.
171
+ * Corresponds to Rust `and`.
172
+ */
173
+ declare function and<T, E, U>(result: Result<T, E>, other: Result<U, E>): Result<U, E>;
174
+ //#endregion
175
+ //#region src/core/or.d.ts
176
+ /**
177
+ * Fallback to another Result if the first is Err.
178
+ * Corresponds to Rust `or`.
179
+ */
180
+ declare function or<T, E, F>(result: Result<T, E>, other: Result<T, F>): Result<T, F>;
181
+ //#endregion
182
+ //#region src/core/orElse.d.ts
183
+ /**
184
+ * Fallback with a function that returns a Result.
185
+ * Corresponds to Rust `or_else`.
186
+ */
187
+ declare function orElse<T, E, F>(result: Result<T, E>, fn: (error: E) => Result<T, F>): Result<T, F>;
188
+ //#endregion
189
+ //#region src/core/mapOr.d.ts
190
+ /**
191
+ * Transforms the value or returns a default value.
192
+ * Corresponds to Rust `map_or`.
193
+ */
194
+ declare function mapOr<T, E, U>(result: Result<T, E>, defaultValue: U, fn: (value: T) => U): U;
195
+ //#endregion
196
+ //#region src/core/mapOrElse.d.ts
197
+ /**
198
+ * Transforms the value or calculates a default value using a function.
199
+ * Corresponds to Rust `map_or_else`.
200
+ */
201
+ declare function mapOrElse<T, E, U>(result: Result<T, E>, defaultFn: (error: E) => U, fn: (value: T) => U): U;
202
+ //#endregion
203
+ //#region src/core/swap.d.ts
204
+ /**
205
+ * Swaps Ok and Err.
206
+ * Result<T, E> → Result<E, T>
207
+ */
208
+ declare function swap<T, E>(result: Result<T, E>): Result<E, T>;
209
+ //#endregion
210
+ 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 };
211
+ //# sourceMappingURL=operators.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operators.d.mts","names":[],"sources":["../src/core/map.ts","../src/core/mapErr.ts","../src/core/mapBoth.ts","../src/core/flatMap.ts","../src/core/tap.ts","../src/core/filter.ts","../src/core/fold.ts","../src/core/tryCatch.ts","../src/core/tryMap.ts","../src/core/recover.ts","../src/core/match.ts","../src/core/mapAsync.ts","../src/core/mapErrAsync.ts","../src/core/flatMapAsync.ts","../src/core/tapAsync.ts","../src/core/filterAsync.ts","../src/core/foldAsync.ts","../src/core/tryCatchAsync.ts","../src/core/tryMapAsync.ts","../src/core/matchAsync.ts","../src/core/and.ts","../src/core/or.ts","../src/core/orElse.ts","../src/core/mapOr.ts","../src/core/mapOrElse.ts","../src/core/swap.ts"],"mappings":";;;;;;iBAQgB,IAAI,GAAG,GAAG,GAAG,UAAU,OAAO,MAAM,KAAC,QACjC,OAAO,GAAG,OAAK,OAAO,GAAG;;;;;;;iBCD7B,OA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