@nlozgachev/pipelined 0.35.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.
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.35.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",