@nlozgachev/pipelined 0.35.0 → 0.37.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
@@ -1,5 +1,5 @@
1
- import { M as Maybe, W as WithValue, c as WithLog, D as Deferred, R as Result, d as WithKind, e as WithError, f as RetryOptions, g as TimeoutOptions, h as WithTimeout, i as WithMinInterval, j as WithCooldown, k as WithConcurrency, l as WithSize, m as WithDuration, n as WithN, T as Task, o as WithErrors, p as WithFirst, q as WithSecond } from './Task-DXsuurnc.mjs';
2
- export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-DXsuurnc.mjs';
1
+ import { M as Maybe, q as WithValue, k as WithLog, D as Deferred, R as Result, j as WithKind, g as WithError, c as RetryOptions, d as TimeoutOptions, p as WithTimeout, l as WithMinInterval, e as WithCooldown, W as WithConcurrency, o as WithSize, f as WithDuration, m as WithN, T as Task, h as WithErrors, i as WithFirst, n as WithSecond } from './Task-fn1n--6H.mjs';
2
+ export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-fn1n--6H.mjs';
3
3
  import { Duration, NonEmptyList } from './types.mjs';
4
4
 
5
5
  /**
@@ -561,6 +561,27 @@ declare namespace Logged {
561
561
  * ```
562
562
  */
563
563
  const run: <W, A>(data: Logged<W, A>) => readonly [A, ReadonlyArray<W>];
564
+ /**
565
+ * Lifts a Logged value into an accumulator object.
566
+ *
567
+ * @example
568
+ * ```ts
569
+ * pipe(Logged.make<string, number>(42), Logged.bindTo("value")); // Logged({ value: 42 })
570
+ * ```
571
+ */
572
+ const bindTo: <K extends string>(key: K) => <W, A>(data: Logged<W, A>) => Logged<W, { [P in K]: A; }>;
573
+ /**
574
+ * Evaluates a new Logged using the current accumulator and attaches the output to a new key.
575
+ *
576
+ * @example
577
+ * ```ts
578
+ * pipe(
579
+ * Logged.make<string, { a: number }>({ a: 1 }),
580
+ * Logged.bind("b", ({ a }) => Logged.make<string, number>(a + 1))
581
+ * ); // Logged({ value: { a: 1, b: 2 } })
582
+ * ```
583
+ */
584
+ const bind: <K extends string, W, A, B>(key: K, f: (a: A) => Logged<W, B>) => (data: Logged<W, A>) => Logged<W, A & { [P in K]: B; }>;
564
585
  }
565
586
 
566
587
  type MaybeRetry<E, O> = O extends {
@@ -1091,18 +1112,18 @@ declare namespace Op {
1091
1112
  }) => (outcome: Outcome<E, A>) => B;
1092
1113
  /**
1093
1114
  * Eliminates an Outcome with positional handlers.
1094
- * Order: `onErr`, `onOk`, `onNil` — mirrors `Result.fold` for the first two.
1115
+ * Order: `onErr`, `onNil`, `onOk` — mirrors `Result.fold` for the first and last cases.
1095
1116
  *
1096
1117
  * @example
1097
1118
  * ```ts
1098
1119
  * Op.fold(
1099
1120
  * (e) => `error: ${e.message}`,
1100
- * (v) => `value: ${v}`,
1101
1121
  * () => "nothing",
1122
+ * (v) => `value: ${v}`,
1102
1123
  * )(outcome);
1103
1124
  * ```
1104
1125
  */
1105
- const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B, onNil: () => B) => (outcome: Outcome<E, A>) => B;
1126
+ const fold: <E, A, B>(onErr: (e: E) => B, onNil: () => B, onOk: (a: A) => B) => (outcome: Outcome<E, A>) => B;
1106
1127
  /**
1107
1128
  * Returns the success value, or the result of `defaultValue()` for `Err` or `Nil`.
1108
1129
  *
@@ -1715,6 +1736,27 @@ declare namespace Reader {
1715
1736
  * ```
1716
1737
  */
1717
1738
  const run: <R>(env: R) => <A>(data: Reader<R, A>) => A;
1739
+ /**
1740
+ * Lifts a Reader value into an accumulator object.
1741
+ *
1742
+ * @example
1743
+ * ```ts
1744
+ * pipe(Reader.resolve(42), Reader.bindTo("value")); // Reader({ value: 42 })
1745
+ * ```
1746
+ */
1747
+ const bindTo: <K extends string>(key: K) => <R, A>(data: Reader<R, A>) => Reader<R, { [P in K]: A; }>;
1748
+ /**
1749
+ * Evaluates a new Reader using the current accumulator and attaches the output to a new key.
1750
+ *
1751
+ * @example
1752
+ * ```ts
1753
+ * pipe(
1754
+ * Reader.resolve({ a: 1 }),
1755
+ * Reader.bind("b", ({ a }) => Reader.resolve(a + 1))
1756
+ * ); // Reader({ a: 1, b: 2 })
1757
+ * ```
1758
+ */
1759
+ const bind: <K extends string, R, A, B>(key: K, f: (a: A) => Reader<R, B>) => (data: Reader<R, A>) => Reader<R, A & { [P in K]: B; }>;
1718
1760
  }
1719
1761
 
1720
1762
  type NotAsked = WithKind<"NotAsked">;
@@ -1829,15 +1871,15 @@ declare namespace RemoteData {
1829
1871
  * pipe(
1830
1872
  * userData,
1831
1873
  * RemoteData.fold(
1874
+ * e => `Error: ${e}`,
1832
1875
  * () => "Not asked",
1833
1876
  * () => "Loading...",
1834
- * e => `Error: ${e}`,
1835
1877
  * value => `Got: ${value}`
1836
1878
  * )
1837
1879
  * );
1838
1880
  * ```
1839
1881
  */
1840
- const fold: <E, A, B>(onNotAsked: () => B, onLoading: () => B, onFailure: (e: E) => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
1882
+ const fold: <E, A, B>(onFailure: (e: E) => B, onNotAsked: () => B, onLoading: () => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
1841
1883
  /**
1842
1884
  * Pattern matches on a RemoteData, returning the result of the matching case.
1843
1885
  *
@@ -2092,6 +2134,28 @@ declare namespace TaskResult {
2092
2134
  * ```
2093
2135
  */
2094
2136
  const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Promise<Result<E, A>>;
2137
+ /**
2138
+ * Converts a TaskResult value into an object containing a single property.
2139
+ * Initiates the pipeline accumulator record.
2140
+ *
2141
+ * @example
2142
+ * ```ts
2143
+ * pipe(TaskResult.ok(42), TaskResult.bindTo("value")); // TaskResult({ value: 42 })
2144
+ * ```
2145
+ */
2146
+ const bindTo: <K extends string>(key: K) => <E, A>(data: TaskResult<E, A>) => TaskResult<E, { [P in K]: A; }>;
2147
+ /**
2148
+ * Evaluates a new TaskResult using the current accumulator and attaches the output to a new key.
2149
+ *
2150
+ * @example
2151
+ * ```ts
2152
+ * pipe(
2153
+ * TaskResult.ok({ a: 1 }),
2154
+ * TaskResult.bind("b", ({ a }) => TaskResult.ok(a + 1))
2155
+ * ); // TaskResult({ a: 1, b: 2 })
2156
+ * ```
2157
+ */
2158
+ const bind: <K extends string, E, A, B>(key: K, f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A & { [P in K]: B; }>;
2095
2159
  }
2096
2160
 
2097
2161
  /**
@@ -2379,6 +2443,27 @@ declare namespace State {
2379
2443
  * ```
2380
2444
  */
2381
2445
  const execute: <S>(initialState: S) => <A>(st: State<S, A>) => S;
2446
+ /**
2447
+ * Lifts a State value into an accumulator object.
2448
+ *
2449
+ * @example
2450
+ * ```ts
2451
+ * pipe(State.resolve(42), State.bindTo("value")); // State({ value: 42 })
2452
+ * ```
2453
+ */
2454
+ const bindTo: <K extends string>(key: K) => <S, A>(data: State<S, A>) => State<S, { [P in K]: A; }>;
2455
+ /**
2456
+ * Evaluates a new State using the current accumulator and attaches the output to a new key.
2457
+ *
2458
+ * @example
2459
+ * ```ts
2460
+ * pipe(
2461
+ * State.resolve({ a: 1 }),
2462
+ * State.bind("b", ({ a }) => State.resolve(a + 1))
2463
+ * ); // State({ a: 1, b: 2 })
2464
+ * ```
2465
+ */
2466
+ const bind: <K extends string, S, A, B>(key: K, f: (a: A) => State<S, B>) => (data: State<S, A>) => State<S, A & { [P in K]: B; }>;
2382
2467
  }
2383
2468
 
2384
2469
  /**
@@ -2508,6 +2593,27 @@ declare namespace TaskMaybe {
2508
2593
  * ```
2509
2594
  */
2510
2595
  const toTaskResult: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => TaskResult<E, A>;
2596
+ /**
2597
+ * Lifts a TaskMaybe value into an accumulator object.
2598
+ *
2599
+ * @example
2600
+ * ```ts
2601
+ * pipe(TaskMaybe.some(42), TaskMaybe.bindTo("value")); // TaskMaybe({ value: 42 })
2602
+ * ```
2603
+ */
2604
+ const bindTo: <K extends string>(key: K) => <A>(data: TaskMaybe<A>) => TaskMaybe<{ [P in K]: A; }>;
2605
+ /**
2606
+ * Evaluates a new TaskMaybe using the current accumulator and attaches the output to a new key.
2607
+ *
2608
+ * @example
2609
+ * ```ts
2610
+ * pipe(
2611
+ * TaskMaybe.some({ a: 1 }),
2612
+ * TaskMaybe.bind("b", ({ a }) => TaskMaybe.some(a + 1))
2613
+ * ); // TaskMaybe({ a: 1, b: 2 })
2614
+ * ```
2615
+ */
2616
+ const bind: <K extends string, A, B>(key: K, f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<A & { [P in K]: B; }>;
2511
2617
  }
2512
2618
 
2513
2619
  type Passed<A> = WithKind<"Passed"> & WithValue<A>;
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as Maybe, W as WithValue, c as WithLog, D as Deferred, R as Result, d as WithKind, e as WithError, f as RetryOptions, g as TimeoutOptions, h as WithTimeout, i as WithMinInterval, j as WithCooldown, k as WithConcurrency, l as WithSize, m as WithDuration, n as WithN, T as Task, o as WithErrors, p as WithFirst, q as WithSecond } from './Task-zAY4kSVB.js';
2
- export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-zAY4kSVB.js';
1
+ import { M as Maybe, q as WithValue, k as WithLog, D as Deferred, R as Result, j as WithKind, g as WithError, c as RetryOptions, d as TimeoutOptions, p as WithTimeout, l as WithMinInterval, e as WithCooldown, W as WithConcurrency, o as WithSize, f as WithDuration, m as WithN, T as Task, h as WithErrors, i as WithFirst, n as WithSecond } from './Task-DIgwvoIb.js';
2
+ export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-DIgwvoIb.js';
3
3
  import { Duration, NonEmptyList } from './types.js';
4
4
 
5
5
  /**
@@ -561,6 +561,27 @@ declare namespace Logged {
561
561
  * ```
562
562
  */
563
563
  const run: <W, A>(data: Logged<W, A>) => readonly [A, ReadonlyArray<W>];
564
+ /**
565
+ * Lifts a Logged value into an accumulator object.
566
+ *
567
+ * @example
568
+ * ```ts
569
+ * pipe(Logged.make<string, number>(42), Logged.bindTo("value")); // Logged({ value: 42 })
570
+ * ```
571
+ */
572
+ const bindTo: <K extends string>(key: K) => <W, A>(data: Logged<W, A>) => Logged<W, { [P in K]: A; }>;
573
+ /**
574
+ * Evaluates a new Logged using the current accumulator and attaches the output to a new key.
575
+ *
576
+ * @example
577
+ * ```ts
578
+ * pipe(
579
+ * Logged.make<string, { a: number }>({ a: 1 }),
580
+ * Logged.bind("b", ({ a }) => Logged.make<string, number>(a + 1))
581
+ * ); // Logged({ value: { a: 1, b: 2 } })
582
+ * ```
583
+ */
584
+ const bind: <K extends string, W, A, B>(key: K, f: (a: A) => Logged<W, B>) => (data: Logged<W, A>) => Logged<W, A & { [P in K]: B; }>;
564
585
  }
565
586
 
566
587
  type MaybeRetry<E, O> = O extends {
@@ -1091,18 +1112,18 @@ declare namespace Op {
1091
1112
  }) => (outcome: Outcome<E, A>) => B;
1092
1113
  /**
1093
1114
  * Eliminates an Outcome with positional handlers.
1094
- * Order: `onErr`, `onOk`, `onNil` — mirrors `Result.fold` for the first two.
1115
+ * Order: `onErr`, `onNil`, `onOk` — mirrors `Result.fold` for the first and last cases.
1095
1116
  *
1096
1117
  * @example
1097
1118
  * ```ts
1098
1119
  * Op.fold(
1099
1120
  * (e) => `error: ${e.message}`,
1100
- * (v) => `value: ${v}`,
1101
1121
  * () => "nothing",
1122
+ * (v) => `value: ${v}`,
1102
1123
  * )(outcome);
1103
1124
  * ```
1104
1125
  */
1105
- const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B, onNil: () => B) => (outcome: Outcome<E, A>) => B;
1126
+ const fold: <E, A, B>(onErr: (e: E) => B, onNil: () => B, onOk: (a: A) => B) => (outcome: Outcome<E, A>) => B;
1106
1127
  /**
1107
1128
  * Returns the success value, or the result of `defaultValue()` for `Err` or `Nil`.
1108
1129
  *
@@ -1715,6 +1736,27 @@ declare namespace Reader {
1715
1736
  * ```
1716
1737
  */
1717
1738
  const run: <R>(env: R) => <A>(data: Reader<R, A>) => A;
1739
+ /**
1740
+ * Lifts a Reader value into an accumulator object.
1741
+ *
1742
+ * @example
1743
+ * ```ts
1744
+ * pipe(Reader.resolve(42), Reader.bindTo("value")); // Reader({ value: 42 })
1745
+ * ```
1746
+ */
1747
+ const bindTo: <K extends string>(key: K) => <R, A>(data: Reader<R, A>) => Reader<R, { [P in K]: A; }>;
1748
+ /**
1749
+ * Evaluates a new Reader using the current accumulator and attaches the output to a new key.
1750
+ *
1751
+ * @example
1752
+ * ```ts
1753
+ * pipe(
1754
+ * Reader.resolve({ a: 1 }),
1755
+ * Reader.bind("b", ({ a }) => Reader.resolve(a + 1))
1756
+ * ); // Reader({ a: 1, b: 2 })
1757
+ * ```
1758
+ */
1759
+ const bind: <K extends string, R, A, B>(key: K, f: (a: A) => Reader<R, B>) => (data: Reader<R, A>) => Reader<R, A & { [P in K]: B; }>;
1718
1760
  }
1719
1761
 
1720
1762
  type NotAsked = WithKind<"NotAsked">;
@@ -1829,15 +1871,15 @@ declare namespace RemoteData {
1829
1871
  * pipe(
1830
1872
  * userData,
1831
1873
  * RemoteData.fold(
1874
+ * e => `Error: ${e}`,
1832
1875
  * () => "Not asked",
1833
1876
  * () => "Loading...",
1834
- * e => `Error: ${e}`,
1835
1877
  * value => `Got: ${value}`
1836
1878
  * )
1837
1879
  * );
1838
1880
  * ```
1839
1881
  */
1840
- const fold: <E, A, B>(onNotAsked: () => B, onLoading: () => B, onFailure: (e: E) => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
1882
+ const fold: <E, A, B>(onFailure: (e: E) => B, onNotAsked: () => B, onLoading: () => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
1841
1883
  /**
1842
1884
  * Pattern matches on a RemoteData, returning the result of the matching case.
1843
1885
  *
@@ -2092,6 +2134,28 @@ declare namespace TaskResult {
2092
2134
  * ```
2093
2135
  */
2094
2136
  const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Promise<Result<E, A>>;
2137
+ /**
2138
+ * Converts a TaskResult value into an object containing a single property.
2139
+ * Initiates the pipeline accumulator record.
2140
+ *
2141
+ * @example
2142
+ * ```ts
2143
+ * pipe(TaskResult.ok(42), TaskResult.bindTo("value")); // TaskResult({ value: 42 })
2144
+ * ```
2145
+ */
2146
+ const bindTo: <K extends string>(key: K) => <E, A>(data: TaskResult<E, A>) => TaskResult<E, { [P in K]: A; }>;
2147
+ /**
2148
+ * Evaluates a new TaskResult using the current accumulator and attaches the output to a new key.
2149
+ *
2150
+ * @example
2151
+ * ```ts
2152
+ * pipe(
2153
+ * TaskResult.ok({ a: 1 }),
2154
+ * TaskResult.bind("b", ({ a }) => TaskResult.ok(a + 1))
2155
+ * ); // TaskResult({ a: 1, b: 2 })
2156
+ * ```
2157
+ */
2158
+ const bind: <K extends string, E, A, B>(key: K, f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A & { [P in K]: B; }>;
2095
2159
  }
2096
2160
 
2097
2161
  /**
@@ -2379,6 +2443,27 @@ declare namespace State {
2379
2443
  * ```
2380
2444
  */
2381
2445
  const execute: <S>(initialState: S) => <A>(st: State<S, A>) => S;
2446
+ /**
2447
+ * Lifts a State value into an accumulator object.
2448
+ *
2449
+ * @example
2450
+ * ```ts
2451
+ * pipe(State.resolve(42), State.bindTo("value")); // State({ value: 42 })
2452
+ * ```
2453
+ */
2454
+ const bindTo: <K extends string>(key: K) => <S, A>(data: State<S, A>) => State<S, { [P in K]: A; }>;
2455
+ /**
2456
+ * Evaluates a new State using the current accumulator and attaches the output to a new key.
2457
+ *
2458
+ * @example
2459
+ * ```ts
2460
+ * pipe(
2461
+ * State.resolve({ a: 1 }),
2462
+ * State.bind("b", ({ a }) => State.resolve(a + 1))
2463
+ * ); // State({ a: 1, b: 2 })
2464
+ * ```
2465
+ */
2466
+ const bind: <K extends string, S, A, B>(key: K, f: (a: A) => State<S, B>) => (data: State<S, A>) => State<S, A & { [P in K]: B; }>;
2382
2467
  }
2383
2468
 
2384
2469
  /**
@@ -2508,6 +2593,27 @@ declare namespace TaskMaybe {
2508
2593
  * ```
2509
2594
  */
2510
2595
  const toTaskResult: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => TaskResult<E, A>;
2596
+ /**
2597
+ * Lifts a TaskMaybe value into an accumulator object.
2598
+ *
2599
+ * @example
2600
+ * ```ts
2601
+ * pipe(TaskMaybe.some(42), TaskMaybe.bindTo("value")); // TaskMaybe({ value: 42 })
2602
+ * ```
2603
+ */
2604
+ const bindTo: <K extends string>(key: K) => <A>(data: TaskMaybe<A>) => TaskMaybe<{ [P in K]: A; }>;
2605
+ /**
2606
+ * Evaluates a new TaskMaybe using the current accumulator and attaches the output to a new key.
2607
+ *
2608
+ * @example
2609
+ * ```ts
2610
+ * pipe(
2611
+ * TaskMaybe.some({ a: 1 }),
2612
+ * TaskMaybe.bind("b", ({ a }) => TaskMaybe.some(a + 1))
2613
+ * ); // TaskMaybe({ a: 1, b: 2 })
2614
+ * ```
2615
+ */
2616
+ const bind: <K extends string, A, B>(key: K, f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<A & { [P in K]: B; }>;
2511
2617
  }
2512
2618
 
2513
2619
  type Passed<A> = WithKind<"Passed"> & WithValue<A>;
package/dist/core.js CHANGED
@@ -93,6 +93,10 @@ var Result;
93
93
  Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
94
94
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
95
95
  Result2.ap = (arg) => (data) => (0, Result2.isOk)(data) && (0, Result2.isOk)(arg) ? (0, Result2.ok)(data.value(arg.value)) : (0, Result2.isErr)(data) ? data : arg;
96
+ Result2.bindTo = (key) => (data) => (0, Result2.map)((a) => ({ [key]: a }))(data);
97
+ Result2.bind = (key, f) => (data) => (0, Result2.chain)(
98
+ (a) => (0, Result2.map)((b) => ({ ...a, [key]: b }))(f(a))
99
+ )(data);
96
100
  })(Result || (Result = {}));
97
101
 
98
102
  // src/Core/Maybe.ts
@@ -123,6 +127,10 @@ var Maybe;
123
127
  Maybe2.filter = (predicate) => (data) => (0, Maybe2.isSome)(data) ? predicate(data.value) ? data : (0, Maybe2.none)() : data;
124
128
  Maybe2.recover = (fallback) => (data) => (0, Maybe2.isSome)(data) ? data : fallback();
125
129
  Maybe2.ap = (arg) => (data) => (0, Maybe2.isSome)(data) && (0, Maybe2.isSome)(arg) ? (0, Maybe2.some)(data.value(arg.value)) : (0, Maybe2.none)();
130
+ Maybe2.bindTo = (key) => (data) => (0, Maybe2.map)((a) => ({ [key]: a }))(data);
131
+ Maybe2.bind = (key, f) => (data) => (0, Maybe2.chain)(
132
+ (a) => (0, Maybe2.map)((b) => ({ ...a, [key]: b }))(f(a))
133
+ )(data);
126
134
  })(Maybe || (Maybe = {}));
127
135
 
128
136
  // src/Core/Combinable.ts
@@ -230,6 +238,10 @@ var Logged;
230
238
  return data;
231
239
  };
232
240
  Logged2.run = (data) => [data.value, data.log];
241
+ Logged2.bindTo = (key) => (data) => (0, Logged2.map)((a) => ({ [key]: a }))(data);
242
+ Logged2.bind = (key, f) => (data) => (0, Logged2.chain)(
243
+ (a) => (0, Logged2.map)((b) => ({ ...a, [key]: b }))(f(a))
244
+ )(data);
233
245
  })(Logged || (Logged = {}));
234
246
 
235
247
  // src/Types/Brand.ts
@@ -1244,7 +1256,7 @@ var Op;
1244
1256
  }
1245
1257
  return cases.nil();
1246
1258
  };
1247
- Op2.fold = (onErr, onOk, onNil) => (outcome) => {
1259
+ Op2.fold = (onErr, onNil, onOk) => (outcome) => {
1248
1260
  if (outcome.kind === "OpOk") {
1249
1261
  return onOk(outcome.value);
1250
1262
  }
@@ -1429,6 +1441,10 @@ var Reader;
1429
1441
  };
1430
1442
  Reader2.local = (f) => (data) => (env) => data(f(env));
1431
1443
  Reader2.run = (env) => (data) => data(env);
1444
+ Reader2.bindTo = (key) => (data) => (0, Reader2.map)((a) => ({ [key]: a }))(data);
1445
+ Reader2.bind = (key, f) => (data) => (0, Reader2.chain)(
1446
+ (a) => (0, Reader2.map)((b) => ({ ...a, [key]: b }))(f(a))
1447
+ )(data);
1432
1448
  })(Reader || (Reader = {}));
1433
1449
 
1434
1450
  // src/Core/Refinement.ts
@@ -1473,17 +1489,17 @@ var RemoteData;
1473
1489
  }
1474
1490
  return (0, RemoteData2.notAsked)();
1475
1491
  };
1476
- RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
1492
+ RemoteData2.fold = (onFailure, onNotAsked, onLoading, onSuccess) => (data) => {
1477
1493
  switch (data.kind) {
1494
+ case "Failure": {
1495
+ return onFailure(data.error);
1496
+ }
1478
1497
  case "NotAsked": {
1479
1498
  return onNotAsked();
1480
1499
  }
1481
1500
  case "Loading": {
1482
1501
  return onLoading();
1483
1502
  }
1484
- case "Failure": {
1485
- return onFailure(data.error);
1486
- }
1487
1503
  case "Success": {
1488
1504
  return onSuccess(data.value);
1489
1505
  }
@@ -1748,6 +1764,10 @@ var Task;
1748
1764
  return { task, abort };
1749
1765
  };
1750
1766
  Task2.run = (signal) => (task) => Deferred.toPromise(task(signal));
1767
+ Task2.bindTo = (key) => (data) => (0, Task2.map)((a) => ({ [key]: a }))(data);
1768
+ Task2.bind = (key, f) => (data) => (0, Task2.chain)(
1769
+ (a) => (0, Task2.map)((b) => ({ ...a, [key]: b }))(f(a))
1770
+ )(data);
1751
1771
  })(Task || (Task = {}));
1752
1772
 
1753
1773
  // src/Core/Resource.ts
@@ -1825,6 +1845,10 @@ var State;
1825
1845
  State2.run = (initialState) => (st) => st(initialState);
1826
1846
  State2.evaluate = (initialState) => (st) => st(initialState)[0];
1827
1847
  State2.execute = (initialState) => (st) => st(initialState)[1];
1848
+ State2.bindTo = (key) => (data) => (0, State2.map)((a) => ({ [key]: a }))(data);
1849
+ State2.bind = (key, f) => (data) => (0, State2.chain)(
1850
+ (a) => (0, State2.map)((b) => ({ ...a, [key]: b }))(f(a))
1851
+ )(data);
1828
1852
  })(State || (State = {}));
1829
1853
 
1830
1854
  // src/Core/TaskMaybe.ts
@@ -1850,6 +1874,10 @@ var TaskMaybe;
1850
1874
  TaskMaybe2.tap = (f) => (data) => Task.map(Maybe.tap(f))(data);
1851
1875
  TaskMaybe2.filter = (predicate) => (data) => Task.map(Maybe.filter(predicate))(data);
1852
1876
  TaskMaybe2.toTaskResult = (onNone) => (data) => Task.map(Maybe.toResult(onNone))(data);
1877
+ TaskMaybe2.bindTo = (key) => (data) => (0, TaskMaybe2.map)((a) => ({ [key]: a }))(data);
1878
+ TaskMaybe2.bind = (key, f) => (data) => (0, TaskMaybe2.chain)(
1879
+ (a) => (0, TaskMaybe2.map)((b) => ({ ...a, [key]: b }))(f(a))
1880
+ )(data);
1853
1881
  })(TaskMaybe || (TaskMaybe = {}));
1854
1882
 
1855
1883
  // src/Core/TaskResult.ts
@@ -1881,6 +1909,10 @@ var TaskResult;
1881
1909
  )
1882
1910
  );
1883
1911
  TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
1912
+ TaskResult2.bindTo = (key) => (data) => (0, TaskResult2.map)((a) => ({ [key]: a }))(data);
1913
+ TaskResult2.bind = (key, f) => (data) => (0, TaskResult2.chain)(
1914
+ (a) => (0, TaskResult2.map)((b) => ({ ...a, [key]: b }))(f(a))
1915
+ )(data);
1884
1916
  })(TaskResult || (TaskResult = {}));
1885
1917
 
1886
1918
  // src/Core/Validation.ts
package/dist/core.mjs CHANGED
@@ -19,13 +19,13 @@ import {
19
19
  These,
20
20
  Tuple,
21
21
  Validation
22
- } from "./chunk-5AWUAG7G.mjs";
22
+ } from "./chunk-SHO53CQC.mjs";
23
23
  import {
24
24
  Deferred,
25
25
  Maybe,
26
26
  Result,
27
27
  Task
28
- } from "./chunk-DLBHVYII.mjs";
28
+ } from "./chunk-PUMSVZB4.mjs";
29
29
  import "./chunk-VWVPHDZO.mjs";
30
30
  export {
31
31
  Combinable,
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
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
- 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';
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-fn1n--6H.mjs';
4
4
  export { Brand, Duration, NonEmptyList, isNonEmptyList } from './types.mjs';
5
5
  export { Arr, Dict, Num, Rec, Str, Uniq } from './utils.mjs';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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
- 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';
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-DIgwvoIb.js';
4
4
  export { Brand, Duration, NonEmptyList, isNonEmptyList } from './types.js';
5
5
  export { Arr, Dict, Num, Rec, Str, Uniq } from './utils.js';