@nlozgachev/pipelined 0.34.0 → 0.36.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.
@@ -32,6 +32,7 @@ __export(Composition_exports, {
32
32
  curry: () => curry,
33
33
  curry3: () => curry3,
34
34
  curry4: () => curry4,
35
+ defaultTo: () => defaultTo,
35
36
  flip: () => flip,
36
37
  flow: () => flow,
37
38
  identity: () => identity,
@@ -177,6 +178,53 @@ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
177
178
  }
178
179
  }
179
180
  }
181
+ var when = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
182
+ var unless = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
183
+ var either = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
184
+ var struct = (fields) => (a) => {
185
+ const result = {};
186
+ for (const key of Object.keys(fields)) {
187
+ result[key] = fields[key](a);
188
+ }
189
+ return result;
190
+ };
191
+ function safe(...fns) {
192
+ return (a) => {
193
+ let result = a;
194
+ if (result === null || result === void 0) {
195
+ return result;
196
+ }
197
+ for (const fn of fns) {
198
+ result = fn(result);
199
+ if (result === null || result === void 0) {
200
+ return result;
201
+ }
202
+ }
203
+ return result;
204
+ };
205
+ }
206
+ function async(...fns) {
207
+ return async (a) => {
208
+ let result = await a;
209
+ for (const fn of fns) {
210
+ result = await fn(result);
211
+ }
212
+ return result;
213
+ };
214
+ }
215
+ flow.when = when;
216
+ flow.unless = unless;
217
+ flow.either = either;
218
+ flow.struct = struct;
219
+ flow.safe = safe;
220
+ flow.async = async;
221
+ flow.try = (f, onError) => (a) => {
222
+ try {
223
+ return f(a);
224
+ } catch (error) {
225
+ return onError(error, a);
226
+ }
227
+ };
180
228
 
181
229
  // src/Composition/fn.ts
182
230
  var identity = (a) => a;
@@ -200,6 +248,7 @@ var once = (f) => {
200
248
  return result;
201
249
  };
202
250
  };
251
+ var defaultTo = (fallback) => (a) => a === null || a === void 0 ? fallback : a;
203
252
 
204
253
  // src/Composition/juxt.ts
205
254
  function juxt(fns) {
@@ -275,6 +324,49 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
275
324
  }
276
325
  }
277
326
  }
327
+ var when2 = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
328
+ var unless2 = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
329
+ var either2 = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
330
+ var struct2 = (fields) => (a) => {
331
+ const result = {};
332
+ for (const key of Object.keys(fields)) {
333
+ result[key] = fields[key](a);
334
+ }
335
+ return result;
336
+ };
337
+ function safe2(a, ...fns) {
338
+ let result = a;
339
+ if (result === null || result === void 0) {
340
+ return result;
341
+ }
342
+ for (const fn of fns) {
343
+ result = fn(result);
344
+ if (result === null || result === void 0) {
345
+ return result;
346
+ }
347
+ }
348
+ return result;
349
+ }
350
+ async function async2(a, ...fns) {
351
+ let result = await a;
352
+ for (const fn of fns) {
353
+ result = await fn(result);
354
+ }
355
+ return result;
356
+ }
357
+ pipe.when = when2;
358
+ pipe.unless = unless2;
359
+ pipe.either = either2;
360
+ pipe.struct = struct2;
361
+ pipe.safe = safe2;
362
+ pipe.async = async2;
363
+ pipe.try = (f, onError) => (a) => {
364
+ try {
365
+ return f(a);
366
+ } catch (error) {
367
+ return onError(error, a);
368
+ }
369
+ };
278
370
 
279
371
  // src/Composition/tap.ts
280
372
  var tap = (f) => (a) => {
@@ -305,6 +397,7 @@ var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
305
397
  curry,
306
398
  curry3,
307
399
  curry4,
400
+ defaultTo,
308
401
  flip,
309
402
  flow,
310
403
  identity,
@@ -11,6 +11,7 @@ import {
11
11
  curry,
12
12
  curry3,
13
13
  curry4,
14
+ defaultTo,
14
15
  flip,
15
16
  flow,
16
17
  identity,
@@ -26,7 +27,7 @@ import {
26
27
  uncurry,
27
28
  uncurry3,
28
29
  uncurry4
29
- } from "./chunk-AHEZFTMT.mjs";
30
+ } from "./chunk-3Q5UBRYB.mjs";
30
31
  export {
31
32
  and,
32
33
  compose,
@@ -40,6 +41,7 @@ export {
40
41
  curry,
41
42
  curry3,
42
43
  curry4,
44
+ defaultTo,
43
45
  flip,
44
46
  flow,
45
47
  identity,
package/dist/core.d.mts CHANGED
@@ -1091,18 +1091,18 @@ declare namespace Op {
1091
1091
  }) => (outcome: Outcome<E, A>) => B;
1092
1092
  /**
1093
1093
  * Eliminates an Outcome with positional handlers.
1094
- * Order: `onErr`, `onOk`, `onNil` — mirrors `Result.fold` for the first two.
1094
+ * Order: `onErr`, `onNil`, `onOk` — mirrors `Result.fold` for the first and last cases.
1095
1095
  *
1096
1096
  * @example
1097
1097
  * ```ts
1098
1098
  * Op.fold(
1099
1099
  * (e) => `error: ${e.message}`,
1100
- * (v) => `value: ${v}`,
1101
1100
  * () => "nothing",
1101
+ * (v) => `value: ${v}`,
1102
1102
  * )(outcome);
1103
1103
  * ```
1104
1104
  */
1105
- const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B, onNil: () => B) => (outcome: Outcome<E, A>) => B;
1105
+ const fold: <E, A, B>(onErr: (e: E) => B, onNil: () => B, onOk: (a: A) => B) => (outcome: Outcome<E, A>) => B;
1106
1106
  /**
1107
1107
  * Returns the success value, or the result of `defaultValue()` for `Err` or `Nil`.
1108
1108
  *
@@ -1829,15 +1829,15 @@ declare namespace RemoteData {
1829
1829
  * pipe(
1830
1830
  * userData,
1831
1831
  * RemoteData.fold(
1832
+ * e => `Error: ${e}`,
1832
1833
  * () => "Not asked",
1833
1834
  * () => "Loading...",
1834
- * e => `Error: ${e}`,
1835
1835
  * value => `Got: ${value}`
1836
1836
  * )
1837
1837
  * );
1838
1838
  * ```
1839
1839
  */
1840
- const fold: <E, A, B>(onNotAsked: () => B, onLoading: () => B, onFailure: (e: E) => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
1840
+ const fold: <E, A, B>(onFailure: (e: E) => B, onNotAsked: () => B, onLoading: () => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
1841
1841
  /**
1842
1842
  * Pattern matches on a RemoteData, returning the result of the matching case.
1843
1843
  *
package/dist/core.d.ts CHANGED
@@ -1091,18 +1091,18 @@ declare namespace Op {
1091
1091
  }) => (outcome: Outcome<E, A>) => B;
1092
1092
  /**
1093
1093
  * Eliminates an Outcome with positional handlers.
1094
- * Order: `onErr`, `onOk`, `onNil` — mirrors `Result.fold` for the first two.
1094
+ * Order: `onErr`, `onNil`, `onOk` — mirrors `Result.fold` for the first and last cases.
1095
1095
  *
1096
1096
  * @example
1097
1097
  * ```ts
1098
1098
  * Op.fold(
1099
1099
  * (e) => `error: ${e.message}`,
1100
- * (v) => `value: ${v}`,
1101
1100
  * () => "nothing",
1101
+ * (v) => `value: ${v}`,
1102
1102
  * )(outcome);
1103
1103
  * ```
1104
1104
  */
1105
- const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B, onNil: () => B) => (outcome: Outcome<E, A>) => B;
1105
+ const fold: <E, A, B>(onErr: (e: E) => B, onNil: () => B, onOk: (a: A) => B) => (outcome: Outcome<E, A>) => B;
1106
1106
  /**
1107
1107
  * Returns the success value, or the result of `defaultValue()` for `Err` or `Nil`.
1108
1108
  *
@@ -1829,15 +1829,15 @@ declare namespace RemoteData {
1829
1829
  * pipe(
1830
1830
  * userData,
1831
1831
  * RemoteData.fold(
1832
+ * e => `Error: ${e}`,
1832
1833
  * () => "Not asked",
1833
1834
  * () => "Loading...",
1834
- * e => `Error: ${e}`,
1835
1835
  * value => `Got: ${value}`
1836
1836
  * )
1837
1837
  * );
1838
1838
  * ```
1839
1839
  */
1840
- const fold: <E, A, B>(onNotAsked: () => B, onLoading: () => B, onFailure: (e: E) => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
1840
+ const fold: <E, A, B>(onFailure: (e: E) => B, onNotAsked: () => B, onLoading: () => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
1841
1841
  /**
1842
1842
  * Pattern matches on a RemoteData, returning the result of the matching case.
1843
1843
  *
package/dist/core.js CHANGED
@@ -1244,7 +1244,7 @@ var Op;
1244
1244
  }
1245
1245
  return cases.nil();
1246
1246
  };
1247
- Op2.fold = (onErr, onOk, onNil) => (outcome) => {
1247
+ Op2.fold = (onErr, onNil, onOk) => (outcome) => {
1248
1248
  if (outcome.kind === "OpOk") {
1249
1249
  return onOk(outcome.value);
1250
1250
  }
@@ -1473,17 +1473,17 @@ var RemoteData;
1473
1473
  }
1474
1474
  return (0, RemoteData2.notAsked)();
1475
1475
  };
1476
- RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
1476
+ RemoteData2.fold = (onFailure, onNotAsked, onLoading, onSuccess) => (data) => {
1477
1477
  switch (data.kind) {
1478
+ case "Failure": {
1479
+ return onFailure(data.error);
1480
+ }
1478
1481
  case "NotAsked": {
1479
1482
  return onNotAsked();
1480
1483
  }
1481
1484
  case "Loading": {
1482
1485
  return onLoading();
1483
1486
  }
1484
- case "Failure": {
1485
- return onFailure(data.error);
1486
- }
1487
1487
  case "Success": {
1488
1488
  return onSuccess(data.value);
1489
1489
  }
package/dist/core.mjs CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  These,
20
20
  Tuple,
21
21
  Validation
22
- } from "./chunk-5AWUAG7G.mjs";
22
+ } from "./chunk-4QMYKCWE.mjs";
23
23
  import {
24
24
  Deferred,
25
25
  Maybe,
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.mjs';
1
+ export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, defaultTo, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.mjs';
2
2
  export { Combinable, Failed, Failure, Lazy, Lens, Loading, Logged, NotAsked, Op, Optional, Passed, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Validation } from './core.mjs';
3
3
  export { D as Deferred, E as Equality, a as Err, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-DXsuurnc.mjs';
4
4
  export { Brand, Duration, NonEmptyList, isNonEmptyList } from './types.mjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.js';
1
+ export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, defaultTo, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.js';
2
2
  export { Combinable, Failed, Failure, Lazy, Lens, Loading, Logged, NotAsked, Op, Optional, Passed, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Validation } from './core.js';
3
3
  export { D as Deferred, E as Equality, a as Err, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-zAY4kSVB.js';
4
4
  export { Brand, Duration, NonEmptyList, isNonEmptyList } from './types.js';
package/dist/index.js CHANGED
@@ -64,6 +64,7 @@ __export(src_exports, {
64
64
  curry: () => curry,
65
65
  curry3: () => curry3,
66
66
  curry4: () => curry4,
67
+ defaultTo: () => defaultTo,
67
68
  flip: () => flip,
68
69
  flow: () => flow,
69
70
  identity: () => identity,
@@ -210,6 +211,53 @@ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
210
211
  }
211
212
  }
212
213
  }
214
+ var when = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
215
+ var unless = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
216
+ var either = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
217
+ var struct = (fields) => (a) => {
218
+ const result = {};
219
+ for (const key of Object.keys(fields)) {
220
+ result[key] = fields[key](a);
221
+ }
222
+ return result;
223
+ };
224
+ function safe(...fns) {
225
+ return (a) => {
226
+ let result = a;
227
+ if (result === null || result === void 0) {
228
+ return result;
229
+ }
230
+ for (const fn of fns) {
231
+ result = fn(result);
232
+ if (result === null || result === void 0) {
233
+ return result;
234
+ }
235
+ }
236
+ return result;
237
+ };
238
+ }
239
+ function async(...fns) {
240
+ return async (a) => {
241
+ let result = await a;
242
+ for (const fn of fns) {
243
+ result = await fn(result);
244
+ }
245
+ return result;
246
+ };
247
+ }
248
+ flow.when = when;
249
+ flow.unless = unless;
250
+ flow.either = either;
251
+ flow.struct = struct;
252
+ flow.safe = safe;
253
+ flow.async = async;
254
+ flow.try = (f, onError) => (a) => {
255
+ try {
256
+ return f(a);
257
+ } catch (error) {
258
+ return onError(error, a);
259
+ }
260
+ };
213
261
 
214
262
  // src/Composition/fn.ts
215
263
  var identity = (a) => a;
@@ -233,6 +281,7 @@ var once = (f) => {
233
281
  return result;
234
282
  };
235
283
  };
284
+ var defaultTo = (fallback) => (a) => a === null || a === void 0 ? fallback : a;
236
285
 
237
286
  // src/Composition/juxt.ts
238
287
  function juxt(fns) {
@@ -308,6 +357,49 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
308
357
  }
309
358
  }
310
359
  }
360
+ var when2 = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
361
+ var unless2 = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
362
+ var either2 = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
363
+ var struct2 = (fields) => (a) => {
364
+ const result = {};
365
+ for (const key of Object.keys(fields)) {
366
+ result[key] = fields[key](a);
367
+ }
368
+ return result;
369
+ };
370
+ function safe2(a, ...fns) {
371
+ let result = a;
372
+ if (result === null || result === void 0) {
373
+ return result;
374
+ }
375
+ for (const fn of fns) {
376
+ result = fn(result);
377
+ if (result === null || result === void 0) {
378
+ return result;
379
+ }
380
+ }
381
+ return result;
382
+ }
383
+ async function async2(a, ...fns) {
384
+ let result = await a;
385
+ for (const fn of fns) {
386
+ result = await fn(result);
387
+ }
388
+ return result;
389
+ }
390
+ pipe.when = when2;
391
+ pipe.unless = unless2;
392
+ pipe.either = either2;
393
+ pipe.struct = struct2;
394
+ pipe.safe = safe2;
395
+ pipe.async = async2;
396
+ pipe.try = (f, onError) => (a) => {
397
+ try {
398
+ return f(a);
399
+ } catch (error) {
400
+ return onError(error, a);
401
+ }
402
+ };
311
403
 
312
404
  // src/Composition/tap.ts
313
405
  var tap = (f) => (a) => {
@@ -1522,7 +1614,7 @@ var Op;
1522
1614
  }
1523
1615
  return cases.nil();
1524
1616
  };
1525
- Op2.fold = (onErr, onOk, onNil) => (outcome) => {
1617
+ Op2.fold = (onErr, onNil, onOk) => (outcome) => {
1526
1618
  if (outcome.kind === "OpOk") {
1527
1619
  return onOk(outcome.value);
1528
1620
  }
@@ -1751,17 +1843,17 @@ var RemoteData;
1751
1843
  }
1752
1844
  return (0, RemoteData2.notAsked)();
1753
1845
  };
1754
- RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
1846
+ RemoteData2.fold = (onFailure, onNotAsked, onLoading, onSuccess) => (data) => {
1755
1847
  switch (data.kind) {
1848
+ case "Failure": {
1849
+ return onFailure(data.error);
1850
+ }
1756
1851
  case "NotAsked": {
1757
1852
  return onNotAsked();
1758
1853
  }
1759
1854
  case "Loading": {
1760
1855
  return onLoading();
1761
1856
  }
1762
- case "Failure": {
1763
- return onFailure(data.error);
1764
- }
1765
1857
  case "Success": {
1766
1858
  return onSuccess(data.value);
1767
1859
  }
@@ -3239,6 +3331,7 @@ var Uniq;
3239
3331
  curry,
3240
3332
  curry3,
3241
3333
  curry4,
3334
+ defaultTo,
3242
3335
  flip,
3243
3336
  flow,
3244
3337
  identity,
package/dist/index.mjs CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  curry,
12
12
  curry3,
13
13
  curry4,
14
+ defaultTo,
14
15
  flip,
15
16
  flow,
16
17
  identity,
@@ -26,7 +27,7 @@ import {
26
27
  uncurry,
27
28
  uncurry3,
28
29
  uncurry4
29
- } from "./chunk-AHEZFTMT.mjs";
30
+ } from "./chunk-3Q5UBRYB.mjs";
30
31
  import {
31
32
  Combinable,
32
33
  Equality,
@@ -48,7 +49,7 @@ import {
48
49
  These,
49
50
  Tuple,
50
51
  Validation
51
- } from "./chunk-5AWUAG7G.mjs";
52
+ } from "./chunk-4QMYKCWE.mjs";
52
53
  import {
53
54
  Arr,
54
55
  Dict,
@@ -116,6 +117,7 @@ export {
116
117
  curry,
117
118
  curry3,
118
119
  curry4,
120
+ defaultTo,
119
121
  flip,
120
122
  flow,
121
123
  identity,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlozgachev/pipelined",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "description": "Opinionated functional abstractions for TypeScript",
5
5
  "license": "BSD-3-Clause",
6
6
  "homepage": "https://pipelined.lozgachev.dev",