@tempots/std 0.25.2 → 0.26.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/async-result.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s={notAsked:{type:"NotAsked"},loading(e=void 0){return{type:"Loading",previousValue:e}},success(e){return{type:"AsyncSuccess",value:e}},failure(e){return{type:"AsyncFailure",error:e}},isSuccess(e){return e.type==="AsyncSuccess"},isFailure(e){return e.type==="AsyncFailure"},isNotAsked(e){return e.type==="NotAsked"},isLoading(e){return e.type==="Loading"},getOrElse(e,r){return s.isSuccess(e)?e.value:r},getOrElseLazy(e,r){return s.isSuccess(e)?e.value:r()},getOrNull(e){return s.isSuccess(e)?e.value:null},getOrUndefined(e){return s.isSuccess(e)?e.value:void 0},getUnsafe:e=>{if(s.isSuccess(e))return e.value;throw s.isFailure(e)?e.error:new Error("Cannot get value from a not-asked or loading result")},match:(e,{success:r,failure:u,loading:i,notAsked:c=i})=>s.isSuccess(e)?r(e.value):s.isFailure(e)?u(e.error):s.isNotAsked(e)?c():i(e.previousValue),effect:(e,r)=>{switch(e.type){case"AsyncSuccess":r.success?r.success(e.value):r.else?.();break;case"AsyncFailure":r.failure?r.failure(e.error):r.else?.();break;case"Loading":r.loading?r.loading(e.previousValue):r.else?.();break;case"NotAsked":r.notAsked?r.notAsked():r.else?.();break}return e},whenSuccess:(e,r)=>(s.isSuccess(e)&&r(e.value),e),whenFailure:(e,r)=>(s.isFailure(e)&&r(e.error),e),equals:(e,r,u={valueEquals:(i,c)=>i===c,errorEquals:(i,c)=>i===c})=>e.type==="AsyncSuccess"&&r.type==="AsyncSuccess"?u.valueEquals(e.value,r.value):e.type==="AsyncFailure"&&r.type==="AsyncFailure"?u.errorEquals(e.error,r.error):e.type==="Loading"&&r.type==="Loading"?u.valueEquals(e.previousValue,r.previousValue):e.type==="NotAsked"&&r.type==="NotAsked",all:e=>{const r=[];for(const u of e)if(s.isSuccess(u))r.push(u.value);else return u;return s.success(r)},ofPromise:async e=>{try{const r=await e;return s.success(r)}catch(r){return s.failure(r instanceof Error?r:new Error(String(r)))}},map:(e,r)=>{switch(e.type){case"AsyncSuccess":return s.success(r(e.value));case"NotAsked":return s.notAsked;case"AsyncFailure":return s.failure(e.error);case"Loading":return s.loading(e.previousValue!=null?r(e.previousValue):void 0)}},flatMap:(e,r)=>{switch(e.type){case"AsyncSuccess":return r(e.value);case"NotAsked":return s.notAsked;case"AsyncFailure":return s.failure(e.error);case"Loading":return s.loading()}},mapError:(e,r)=>{switch(e.type){case"AsyncSuccess":return s.success(e.value);case"NotAsked":return s.notAsked;case"AsyncFailure":return s.failure(r(e.error));case"Loading":return s.loading(e.previousValue)}},flatMapError:(e,r)=>{switch(e.type){case"AsyncSuccess":return s.success(e.value);case"NotAsked":return s.notAsked;case"AsyncFailure":return r(e.error);case"Loading":return s.loading(e.previousValue)}},toResult:e=>{switch(e.type){case"AsyncSuccess":return{type:"Success",value:e.value};case"AsyncFailure":return{type:"Failure",error:e.error};case"NotAsked":case"Loading":return}},isSettled(e){return e.type==="AsyncSuccess"||e.type==="AsyncFailure"},recover:(e,r)=>{switch(e.type){case"AsyncSuccess":return s.success(e.value);case"NotAsked":return s.notAsked;case"AsyncFailure":return s.success(r(e.error));case"Loading":return s.loading(e.previousValue)}},ap:(e,r)=>s.isSuccess(e)&&s.isSuccess(r)?s.success(e.value(r.value)):s.isFailure(e)?s.failure(e.error):s.isFailure(r)?s.failure(r.error):s.isLoading(e)||s.isLoading(r)?s.loading():s.notAsked,map2:(e,r,u)=>s.isSuccess(e)&&s.isSuccess(r)?s.success(u(e.value,r.value)):s.isFailure(e)?s.failure(e.error):s.isFailure(r)?s.failure(r.error):s.isLoading(e)||s.isLoading(r)?s.loading():s.notAsked,map3:(e,r,u,i)=>s.isSuccess(e)&&s.isSuccess(r)&&s.isSuccess(u)?s.success(i(e.value,r.value,u.value)):s.isFailure(e)?s.failure(e.error):s.isFailure(r)?s.failure(r.error):s.isFailure(u)?s.failure(u.error):s.isLoading(e)||s.isLoading(r)||s.isLoading(u)?s.loading():s.notAsked};exports.AsyncResult=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s={notAsked:{type:"NotAsked"},loading(e=void 0){return{type:"Loading",previousValue:e}},success(e){return{type:"AsyncSuccess",value:e}},failure(e){return{type:"AsyncFailure",error:e}},isSuccess(e){return e.type==="AsyncSuccess"},isFailure(e){return e.type==="AsyncFailure"},isNotAsked(e){return e.type==="NotAsked"},isLoading(e){return e.type==="Loading"},getOrElse(e,u){return s.isSuccess(e)?e.value:s.isLoading(e)&&e.previousValue!==void 0?e.previousValue:u},getOrElseLazy(e,u){return s.isSuccess(e)?e.value:s.isLoading(e)&&e.previousValue!==void 0?e.previousValue:u()},getOrNull(e){return s.isSuccess(e)?e.value:s.isLoading(e)&&e.previousValue!==void 0?e.previousValue:null},getOrUndefined(e){if(s.isSuccess(e))return e.value;if(s.isLoading(e)&&e.previousValue!==void 0)return e.previousValue},getUnsafe:e=>{if(s.isSuccess(e))return e.value;if(s.isLoading(e)&&e.previousValue!==void 0)return e.previousValue;throw s.isFailure(e)?e.error:new Error("Cannot get value from a not-asked or loading result without previous value")},match:(e,{success:u,failure:r,loading:i,notAsked:a=i})=>s.isSuccess(e)?u(e.value):s.isFailure(e)?r(e.error):s.isNotAsked(e)?a():i(e.previousValue),effect:(e,u)=>{switch(e.type){case"AsyncSuccess":u.success?u.success(e.value):u.else?.();break;case"AsyncFailure":u.failure?u.failure(e.error):u.else?.();break;case"Loading":u.loading?u.loading(e.previousValue):u.else?.();break;case"NotAsked":u.notAsked?u.notAsked():u.else?.();break}return e},whenSuccess:(e,u)=>(s.isSuccess(e)&&u(e.value),e),whenFailure:(e,u)=>(s.isFailure(e)&&u(e.error),e),equals:(e,u,r={valueEquals:(i,a)=>i===a,errorEquals:(i,a)=>i===a})=>e.type==="AsyncSuccess"&&u.type==="AsyncSuccess"?r.valueEquals(e.value,u.value):e.type==="AsyncFailure"&&u.type==="AsyncFailure"?r.errorEquals(e.error,u.error):e.type==="Loading"&&u.type==="Loading"?r.valueEquals(e.previousValue,u.previousValue):e.type==="NotAsked"&&u.type==="NotAsked",all:e=>{const u=[];for(const r of e)if(s.isSuccess(r))u.push(r.value);else return r;return s.success(u)},ofPromise:async e=>{try{const u=await e;return s.success(u)}catch(u){return s.failure(u instanceof Error?u:new Error(String(u)))}},map:(e,u)=>{switch(e.type){case"AsyncSuccess":return s.success(u(e.value));case"NotAsked":return s.notAsked;case"AsyncFailure":return s.failure(e.error);case"Loading":return s.loading(e.previousValue!=null?u(e.previousValue):void 0)}},flatMap:(e,u)=>{switch(e.type){case"AsyncSuccess":return u(e.value);case"NotAsked":return s.notAsked;case"AsyncFailure":return s.failure(e.error);case"Loading":return s.loading()}},mapError:(e,u)=>{switch(e.type){case"AsyncSuccess":return s.success(e.value);case"NotAsked":return s.notAsked;case"AsyncFailure":return s.failure(u(e.error));case"Loading":return s.loading(e.previousValue)}},flatMapError:(e,u)=>{switch(e.type){case"AsyncSuccess":return s.success(e.value);case"NotAsked":return s.notAsked;case"AsyncFailure":return u(e.error);case"Loading":return s.loading(e.previousValue)}},toResult:e=>{switch(e.type){case"AsyncSuccess":return{type:"Success",value:e.value};case"AsyncFailure":return{type:"Failure",error:e.error};case"NotAsked":case"Loading":return}},isSettled(e){return e.type==="AsyncSuccess"||e.type==="AsyncFailure"},recover:(e,u)=>{switch(e.type){case"AsyncSuccess":return s.success(e.value);case"NotAsked":return s.notAsked;case"AsyncFailure":return s.success(u(e.error));case"Loading":return s.loading(e.previousValue)}},ap:(e,u)=>s.isSuccess(e)&&s.isSuccess(u)?s.success(e.value(u.value)):s.isFailure(e)?s.failure(e.error):s.isFailure(u)?s.failure(u.error):s.isLoading(e)||s.isLoading(u)?s.loading():s.notAsked,map2:(e,u,r)=>s.isSuccess(e)&&s.isSuccess(u)?s.success(r(e.value,u.value)):s.isFailure(e)?s.failure(e.error):s.isFailure(u)?s.failure(u.error):s.isLoading(e)||s.isLoading(u)?s.loading():s.notAsked,map3:(e,u,r,i)=>s.isSuccess(e)&&s.isSuccess(u)&&s.isSuccess(r)?s.success(i(e.value,u.value,r.value)):s.isFailure(e)?s.failure(e.error):s.isFailure(u)?s.failure(u.error):s.isFailure(r)?s.failure(r.error):s.isLoading(e)||s.isLoading(u)||s.isLoading(r)?s.loading():s.notAsked};exports.AsyncResult=s;
package/async-result.d.ts CHANGED
@@ -118,40 +118,39 @@ export declare const AsyncResult: {
118
118
  */
119
119
  isLoading<V, E>(r: AsyncResult<V, E>): r is Loading<V>;
120
120
  /**
121
- * Gets the value if the result is a success; otherwise, returns the alternative value.
121
+ * Gets the value if the result is a success or loading with a previous value; otherwise, returns the alternative value.
122
122
  * @param r - The result.
123
123
  * @param alt - The alternative value.
124
- * @returns The value if the result is a success; otherwise, the alternative value.
124
+ * @returns The value if the result is a success or loading with previous value; otherwise, the alternative value.
125
125
  * @public
126
126
  */
127
127
  getOrElse<V, E>(r: AsyncResult<V, E>, alt: V): V;
128
128
  /**
129
- * Gets the value if the result is a success; otherwise, returns the value from the alternative function.
129
+ * Gets the value if the result is a success or loading with a previous value; otherwise, returns the value from the alternative function.
130
130
  * @param r - The result.
131
131
  * @param altf - The alternative function.
132
- * @returns The value if the result is a success; otherwise, the value from the alternative
132
+ * @returns The value if the result is a success or loading with previous value; otherwise, the value from the alternative function.
133
133
  * @public
134
- * function.
135
134
  */
136
135
  getOrElseLazy<V, E>(r: AsyncResult<V, E>, altf: () => V): V;
137
136
  /**
138
- * Gets the value if the result is a success; otherwise, returns `null`.
137
+ * Gets the value if the result is a success or loading with a previous value; otherwise, returns `null`.
139
138
  * @param r - The result.
140
- * @returns The value if the result is a success; otherwise, `null`.
139
+ * @returns The value if the result is a success or loading with previous value; otherwise, `null`.
141
140
  * @public
142
141
  */
143
142
  getOrNull<V, E>(r: AsyncResult<V, E>): V | null;
144
143
  /**
145
- * Gets the value if the result is a success; otherwise, returns `undefined`.
144
+ * Gets the value if the result is a success or loading with a previous value; otherwise, returns `undefined`.
146
145
  * @param r - The result.
147
- * @returns The value if the result is a success; otherwise, `undefined`.
146
+ * @returns The value if the result is a success or loading with previous value; otherwise, `undefined`.
148
147
  * @public
149
148
  */
150
149
  getOrUndefined<V, E>(r: AsyncResult<V, E>): Maybe<V>;
151
150
  /**
152
- * Gets the value of a `AsyncResult` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
151
+ * Gets the value of a `AsyncResult` if it is a `Success` or loading with a previous value, otherwise it throws the error contained in the `Failure`.
153
152
  * @param r - The `AsyncResult` to get the value from.
154
- * @returns The value of the `AsyncResult` if it is a `Success`.
153
+ * @returns The value of the `AsyncResult` if it is a `Success` or loading with previous value.
155
154
  */
156
155
  getUnsafe: <V, E>(r: AsyncResult<V, E>) => V;
157
156
  /**
package/async-result.js CHANGED
@@ -70,53 +70,59 @@ const s = {
70
70
  return e.type === "Loading";
71
71
  },
72
72
  /**
73
- * Gets the value if the result is a success; otherwise, returns the alternative value.
73
+ * Gets the value if the result is a success or loading with a previous value; otherwise, returns the alternative value.
74
74
  * @param r - The result.
75
75
  * @param alt - The alternative value.
76
- * @returns The value if the result is a success; otherwise, the alternative value.
76
+ * @returns The value if the result is a success or loading with previous value; otherwise, the alternative value.
77
77
  * @public
78
78
  */
79
- getOrElse(e, r) {
80
- return s.isSuccess(e) ? e.value : r;
79
+ getOrElse(e, u) {
80
+ return s.isSuccess(e) ? e.value : s.isLoading(e) && e.previousValue !== void 0 ? e.previousValue : u;
81
81
  },
82
82
  /**
83
- * Gets the value if the result is a success; otherwise, returns the value from the alternative function.
83
+ * Gets the value if the result is a success or loading with a previous value; otherwise, returns the value from the alternative function.
84
84
  * @param r - The result.
85
85
  * @param altf - The alternative function.
86
- * @returns The value if the result is a success; otherwise, the value from the alternative
86
+ * @returns The value if the result is a success or loading with previous value; otherwise, the value from the alternative function.
87
87
  * @public
88
- * function.
89
88
  */
90
- getOrElseLazy(e, r) {
91
- return s.isSuccess(e) ? e.value : r();
89
+ getOrElseLazy(e, u) {
90
+ return s.isSuccess(e) ? e.value : s.isLoading(e) && e.previousValue !== void 0 ? e.previousValue : u();
92
91
  },
93
92
  /**
94
- * Gets the value if the result is a success; otherwise, returns `null`.
93
+ * Gets the value if the result is a success or loading with a previous value; otherwise, returns `null`.
95
94
  * @param r - The result.
96
- * @returns The value if the result is a success; otherwise, `null`.
95
+ * @returns The value if the result is a success or loading with previous value; otherwise, `null`.
97
96
  * @public
98
97
  */
99
98
  getOrNull(e) {
100
- return s.isSuccess(e) ? e.value : null;
99
+ return s.isSuccess(e) ? e.value : s.isLoading(e) && e.previousValue !== void 0 ? e.previousValue : null;
101
100
  },
102
101
  /**
103
- * Gets the value if the result is a success; otherwise, returns `undefined`.
102
+ * Gets the value if the result is a success or loading with a previous value; otherwise, returns `undefined`.
104
103
  * @param r - The result.
105
- * @returns The value if the result is a success; otherwise, `undefined`.
104
+ * @returns The value if the result is a success or loading with previous value; otherwise, `undefined`.
106
105
  * @public
107
106
  */
108
107
  getOrUndefined(e) {
109
- return s.isSuccess(e) ? e.value : void 0;
108
+ if (s.isSuccess(e))
109
+ return e.value;
110
+ if (s.isLoading(e) && e.previousValue !== void 0)
111
+ return e.previousValue;
110
112
  },
111
113
  /**
112
- * Gets the value of a `AsyncResult` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
114
+ * Gets the value of a `AsyncResult` if it is a `Success` or loading with a previous value, otherwise it throws the error contained in the `Failure`.
113
115
  * @param r - The `AsyncResult` to get the value from.
114
- * @returns The value of the `AsyncResult` if it is a `Success`.
116
+ * @returns The value of the `AsyncResult` if it is a `Success` or loading with previous value.
115
117
  */
116
118
  getUnsafe: (e) => {
117
119
  if (s.isSuccess(e))
118
120
  return e.value;
119
- throw s.isFailure(e) ? e.error : new Error("Cannot get value from a not-asked or loading result");
121
+ if (s.isLoading(e) && e.previousValue !== void 0)
122
+ return e.previousValue;
123
+ throw s.isFailure(e) ? e.error : new Error(
124
+ "Cannot get value from a not-asked or loading result without previous value"
125
+ );
120
126
  },
121
127
  /**
122
128
  * Based on the state of the result, it picks the appropriate function to call and returns the result.
@@ -128,11 +134,11 @@ const s = {
128
134
  * @public
129
135
  */
130
136
  match: (e, {
131
- success: r,
132
- failure: u,
137
+ success: u,
138
+ failure: r,
133
139
  loading: i,
134
- notAsked: c = i
135
- }) => s.isSuccess(e) ? r(e.value) : s.isFailure(e) ? u(e.error) : s.isNotAsked(e) ? c() : i(e.previousValue),
140
+ notAsked: a = i
141
+ }) => s.isSuccess(e) ? u(e.value) : s.isFailure(e) ? r(e.error) : s.isNotAsked(e) ? a() : i(e.previousValue),
136
142
  /**
137
143
  * Executes side effects based on the state of the result.
138
144
  * Unlike `match`, all handlers are optional, allowing you to react only to specific states.
@@ -142,19 +148,19 @@ const s = {
142
148
  * @returns The result that was passed in, allowing for chaining.
143
149
  * @public
144
150
  */
145
- effect: (e, r) => {
151
+ effect: (e, u) => {
146
152
  switch (e.type) {
147
153
  case "AsyncSuccess":
148
- r.success ? r.success(e.value) : r.else?.();
154
+ u.success ? u.success(e.value) : u.else?.();
149
155
  break;
150
156
  case "AsyncFailure":
151
- r.failure ? r.failure(e.error) : r.else?.();
157
+ u.failure ? u.failure(e.error) : u.else?.();
152
158
  break;
153
159
  case "Loading":
154
- r.loading ? r.loading(e.previousValue) : r.else?.();
160
+ u.loading ? u.loading(e.previousValue) : u.else?.();
155
161
  break;
156
162
  case "NotAsked":
157
- r.notAsked ? r.notAsked() : r.else?.();
163
+ u.notAsked ? u.notAsked() : u.else?.();
158
164
  break;
159
165
  }
160
166
  return e;
@@ -167,7 +173,7 @@ const s = {
167
173
  * @returns The result that was passed in.
168
174
  * @public
169
175
  */
170
- whenSuccess: (e, r) => (s.isSuccess(e) && r(e.value), e),
176
+ whenSuccess: (e, u) => (s.isSuccess(e) && u(e.value), e),
171
177
  /**
172
178
  * When the result is a failure, it applies the function to the error.
173
179
  *
@@ -176,7 +182,7 @@ const s = {
176
182
  * @returns The result that was passed in.
177
183
  * @public
178
184
  */
179
- whenFailure: (e, r) => (s.isFailure(e) && r(e.error), e),
185
+ whenFailure: (e, u) => (s.isFailure(e) && u(e.error), e),
180
186
  /**
181
187
  * Compares two results for equality.
182
188
  * @param r1 - The first result.
@@ -184,23 +190,23 @@ const s = {
184
190
  * @param options - The options to use for comparison. By default, uses strict equality.
185
191
  * @returns `true` if the results are equal, `false` otherwise.
186
192
  */
187
- equals: (e, r, u = {
188
- valueEquals: (i, c) => i === c,
189
- errorEquals: (i, c) => i === c
190
- }) => e.type === "AsyncSuccess" && r.type === "AsyncSuccess" ? u.valueEquals(e.value, r.value) : e.type === "AsyncFailure" && r.type === "AsyncFailure" ? u.errorEquals(e.error, r.error) : e.type === "Loading" && r.type === "Loading" ? u.valueEquals(e.previousValue, r.previousValue) : e.type === "NotAsked" && r.type === "NotAsked",
193
+ equals: (e, u, r = {
194
+ valueEquals: (i, a) => i === a,
195
+ errorEquals: (i, a) => i === a
196
+ }) => e.type === "AsyncSuccess" && u.type === "AsyncSuccess" ? r.valueEquals(e.value, u.value) : e.type === "AsyncFailure" && u.type === "AsyncFailure" ? r.errorEquals(e.error, u.error) : e.type === "Loading" && u.type === "Loading" ? r.valueEquals(e.previousValue, u.previousValue) : e.type === "NotAsked" && u.type === "NotAsked",
191
197
  /**
192
198
  * Combines multiple results into a single result.
193
199
  * @param results - The results to combine.
194
200
  * @returns A single result that is a success if all the input results are successes, otherwise a failure.
195
201
  */
196
202
  all: (e) => {
197
- const r = [];
198
- for (const u of e)
199
- if (s.isSuccess(u))
200
- r.push(u.value);
203
+ const u = [];
204
+ for (const r of e)
205
+ if (s.isSuccess(r))
206
+ u.push(r.value);
201
207
  else
202
- return u;
203
- return s.success(r);
208
+ return r;
209
+ return s.success(u);
204
210
  },
205
211
  /**
206
212
  * Converts a Promise to an AsyncResult.
@@ -209,10 +215,10 @@ const s = {
209
215
  */
210
216
  ofPromise: async (e) => {
211
217
  try {
212
- const r = await e;
213
- return s.success(r);
214
- } catch (r) {
215
- return s.failure(r instanceof Error ? r : new Error(String(r)));
218
+ const u = await e;
219
+ return s.success(u);
220
+ } catch (u) {
221
+ return s.failure(u instanceof Error ? u : new Error(String(u)));
216
222
  }
217
223
  },
218
224
  /**
@@ -224,17 +230,17 @@ const s = {
224
230
  * @returns A new `AsyncResult` with the mapped value if successful, otherwise the original state.
225
231
  * @public
226
232
  */
227
- map: (e, r) => {
233
+ map: (e, u) => {
228
234
  switch (e.type) {
229
235
  case "AsyncSuccess":
230
- return s.success(r(e.value));
236
+ return s.success(u(e.value));
231
237
  case "NotAsked":
232
238
  return s.notAsked;
233
239
  case "AsyncFailure":
234
240
  return s.failure(e.error);
235
241
  case "Loading":
236
242
  return s.loading(
237
- e.previousValue != null ? r(e.previousValue) : void 0
243
+ e.previousValue != null ? u(e.previousValue) : void 0
238
244
  );
239
245
  }
240
246
  },
@@ -246,10 +252,10 @@ const s = {
246
252
  * @returns The result of the mapping function if successful, otherwise the original state.
247
253
  * @public
248
254
  */
249
- flatMap: (e, r) => {
255
+ flatMap: (e, u) => {
250
256
  switch (e.type) {
251
257
  case "AsyncSuccess":
252
- return r(e.value);
258
+ return u(e.value);
253
259
  case "NotAsked":
254
260
  return s.notAsked;
255
261
  case "AsyncFailure":
@@ -266,14 +272,14 @@ const s = {
266
272
  * @returns A new `AsyncResult` with the mapped error if failed, otherwise the original state.
267
273
  * @public
268
274
  */
269
- mapError: (e, r) => {
275
+ mapError: (e, u) => {
270
276
  switch (e.type) {
271
277
  case "AsyncSuccess":
272
278
  return s.success(e.value);
273
279
  case "NotAsked":
274
280
  return s.notAsked;
275
281
  case "AsyncFailure":
276
- return s.failure(r(e.error));
282
+ return s.failure(u(e.error));
277
283
  case "Loading":
278
284
  return s.loading(e.previousValue);
279
285
  }
@@ -286,14 +292,14 @@ const s = {
286
292
  * @returns The result of the recovery function if failed, otherwise the original state.
287
293
  * @public
288
294
  */
289
- flatMapError: (e, r) => {
295
+ flatMapError: (e, u) => {
290
296
  switch (e.type) {
291
297
  case "AsyncSuccess":
292
298
  return s.success(e.value);
293
299
  case "NotAsked":
294
300
  return s.notAsked;
295
301
  case "AsyncFailure":
296
- return r(e.error);
302
+ return u(e.error);
297
303
  case "Loading":
298
304
  return s.loading(e.previousValue);
299
305
  }
@@ -332,14 +338,14 @@ const s = {
332
338
  * @returns A successful `AsyncResult` with the alternative value if failed, otherwise the original state.
333
339
  * @public
334
340
  */
335
- recover: (e, r) => {
341
+ recover: (e, u) => {
336
342
  switch (e.type) {
337
343
  case "AsyncSuccess":
338
344
  return s.success(e.value);
339
345
  case "NotAsked":
340
346
  return s.notAsked;
341
347
  case "AsyncFailure":
342
- return s.success(r(e.error));
348
+ return s.success(u(e.error));
343
349
  case "Loading":
344
350
  return s.loading(e.previousValue);
345
351
  }
@@ -352,7 +358,7 @@ const s = {
352
358
  * @returns A new `AsyncResult` with the result of applying the function to the value.
353
359
  * @public
354
360
  */
355
- ap: (e, r) => s.isSuccess(e) && s.isSuccess(r) ? s.success(e.value(r.value)) : s.isFailure(e) ? s.failure(e.error) : s.isFailure(r) ? s.failure(r.error) : s.isLoading(e) || s.isLoading(r) ? s.loading() : s.notAsked,
361
+ ap: (e, u) => s.isSuccess(e) && s.isSuccess(u) ? s.success(e.value(u.value)) : s.isFailure(e) ? s.failure(e.error) : s.isFailure(u) ? s.failure(u.error) : s.isLoading(e) || s.isLoading(u) ? s.loading() : s.notAsked,
356
362
  /**
357
363
  * Maps two `AsyncResult` values using a function.
358
364
  * @param r1 - The first `AsyncResult`.
@@ -361,7 +367,7 @@ const s = {
361
367
  * @returns A new `AsyncResult` with the result of applying the function to both values.
362
368
  * @public
363
369
  */
364
- map2: (e, r, u) => s.isSuccess(e) && s.isSuccess(r) ? s.success(u(e.value, r.value)) : s.isFailure(e) ? s.failure(e.error) : s.isFailure(r) ? s.failure(r.error) : s.isLoading(e) || s.isLoading(r) ? s.loading() : s.notAsked,
370
+ map2: (e, u, r) => s.isSuccess(e) && s.isSuccess(u) ? s.success(r(e.value, u.value)) : s.isFailure(e) ? s.failure(e.error) : s.isFailure(u) ? s.failure(u.error) : s.isLoading(e) || s.isLoading(u) ? s.loading() : s.notAsked,
365
371
  /**
366
372
  * Maps three `AsyncResult` values using a function.
367
373
  * @param r1 - The first `AsyncResult`.
@@ -371,7 +377,7 @@ const s = {
371
377
  * @returns A new `AsyncResult` with the result of applying the function to all three values.
372
378
  * @public
373
379
  */
374
- map3: (e, r, u, i) => s.isSuccess(e) && s.isSuccess(r) && s.isSuccess(u) ? s.success(i(e.value, r.value, u.value)) : s.isFailure(e) ? s.failure(e.error) : s.isFailure(r) ? s.failure(r.error) : s.isFailure(u) ? s.failure(u.error) : s.isLoading(e) || s.isLoading(r) || s.isLoading(u) ? s.loading() : s.notAsked
380
+ map3: (e, u, r, i) => s.isSuccess(e) && s.isSuccess(u) && s.isSuccess(r) ? s.success(i(e.value, u.value, r.value)) : s.isFailure(e) ? s.failure(e.error) : s.isFailure(u) ? s.failure(u.error) : s.isFailure(r) ? s.failure(r.error) : s.isLoading(e) || s.isLoading(u) || s.isLoading(r) ? s.loading() : s.notAsked
375
381
  };
376
382
  export {
377
383
  s as AsyncResult
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempots/std",
3
- "version": "0.25.2",
3
+ "version": "0.26.0",
4
4
  "priority": 8,
5
5
  "description": "Std library for TypeScript. Natural complement to the Tempo libraries.",
6
6
  "keywords": [