@nlozgachev/pipelined 0.25.0 → 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.
@@ -249,6 +249,20 @@ declare namespace Result {
249
249
  * ```
250
250
  */
251
251
  const tap: <E, A>(f: (a: A) => void) => (data: Result<E, A>) => Result<E, A>;
252
+ /**
253
+ * Executes a side effect on the error value without changing the Result.
254
+ * Useful for logging or reporting errors.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * pipe(
259
+ * Result.err("not found"),
260
+ * Result.tapError(e => console.error("validation failed:", e)),
261
+ * Result.chain(save),
262
+ * )
263
+ * ```
264
+ */
265
+ const tapError: <E, A>(f: (e: E) => void) => (data: Result<E, A>) => Result<E, A>;
252
266
  /**
253
267
  * Recovers from an error by providing a fallback Result.
254
268
  * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
@@ -346,6 +360,20 @@ declare namespace Maybe {
346
360
  * Returns None if undefined, Some otherwise.
347
361
  */
348
362
  const fromUndefined: <A>(value: A | undefined) => Maybe<A>;
363
+ /**
364
+ * Creates a Maybe from a predicate applied to a value.
365
+ * Returns Some if the predicate passes, None otherwise.
366
+ *
367
+ * @example
368
+ * ```ts
369
+ * Maybe.fromPredicate((n: number) => n >= 18)(21); // Some(21)
370
+ * Maybe.fromPredicate((n: number) => n >= 18)(15); // None
371
+ *
372
+ * pipe("hello", Maybe.fromPredicate((s: string) => s.length > 0)); // Some("hello")
373
+ * pipe("", Maybe.fromPredicate((s: string) => s.length > 0)); // None
374
+ * ```
375
+ */
376
+ const fromPredicate: <A>(pred: (a: A) => boolean) => (a: A) => Maybe<A>;
349
377
  /**
350
378
  * Converts an Maybe to a Result.
351
379
  * Some becomes Ok, None becomes Err with the provided error.
@@ -249,6 +249,20 @@ declare namespace Result {
249
249
  * ```
250
250
  */
251
251
  const tap: <E, A>(f: (a: A) => void) => (data: Result<E, A>) => Result<E, A>;
252
+ /**
253
+ * Executes a side effect on the error value without changing the Result.
254
+ * Useful for logging or reporting errors.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * pipe(
259
+ * Result.err("not found"),
260
+ * Result.tapError(e => console.error("validation failed:", e)),
261
+ * Result.chain(save),
262
+ * )
263
+ * ```
264
+ */
265
+ const tapError: <E, A>(f: (e: E) => void) => (data: Result<E, A>) => Result<E, A>;
252
266
  /**
253
267
  * Recovers from an error by providing a fallback Result.
254
268
  * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
@@ -346,6 +360,20 @@ declare namespace Maybe {
346
360
  * Returns None if undefined, Some otherwise.
347
361
  */
348
362
  const fromUndefined: <A>(value: A | undefined) => Maybe<A>;
363
+ /**
364
+ * Creates a Maybe from a predicate applied to a value.
365
+ * Returns Some if the predicate passes, None otherwise.
366
+ *
367
+ * @example
368
+ * ```ts
369
+ * Maybe.fromPredicate((n: number) => n >= 18)(21); // Some(21)
370
+ * Maybe.fromPredicate((n: number) => n >= 18)(15); // None
371
+ *
372
+ * pipe("hello", Maybe.fromPredicate((s: string) => s.length > 0)); // Some("hello")
373
+ * pipe("", Maybe.fromPredicate((s: string) => s.length > 0)); // None
374
+ * ```
375
+ */
376
+ const fromPredicate: <A>(pred: (a: A) => boolean) => (a: A) => Maybe<A>;
349
377
  /**
350
378
  * Converts an Maybe to a Result.
351
379
  * Some becomes Ok, None becomes Err with the provided error.
@@ -3,7 +3,7 @@ import {
3
3
  Maybe,
4
4
  Result,
5
5
  Task
6
- } from "./chunk-2DPG2RDB.mjs";
6
+ } from "./chunk-Z3DYYR43.mjs";
7
7
  import {
8
8
  isNonEmptyList
9
9
  } from "./chunk-DBIC62UV.mjs";
@@ -43,6 +43,14 @@ var Arr;
43
43
  }
44
44
  return result;
45
45
  };
46
+ Arr2.filterMap = (f) => (data) => {
47
+ const result = [];
48
+ for (let i = 0; i < data.length; i++) {
49
+ const mapped = f(data[i]);
50
+ if (mapped.kind === "Some") result.push(mapped.value);
51
+ }
52
+ return result;
53
+ };
46
54
  Arr2.partition = (predicate) => (data) => {
47
55
  const pass = [];
48
56
  const fail = [];
@@ -471,6 +479,8 @@ var Str;
471
479
  Str2.split = (separator) => (s) => s.split(separator);
472
480
  Str2.trim = (s) => s.trim();
473
481
  Str2.includes = (substring) => (s) => s.includes(substring);
482
+ Str2.replace = (pattern, replacement) => (s) => s.replace(pattern, replacement);
483
+ Str2.replaceAll = (pattern, replacement) => (s) => s.replaceAll(pattern, replacement);
474
484
  Str2.startsWith = (prefix) => (s) => s.startsWith(prefix);
475
485
  Str2.endsWith = (suffix) => (s) => s.endsWith(suffix);
476
486
  Str2.toUpperCase = (s) => s.toUpperCase();
@@ -3,7 +3,7 @@ import {
3
3
  Maybe,
4
4
  Result,
5
5
  Task
6
- } from "./chunk-2DPG2RDB.mjs";
6
+ } from "./chunk-Z3DYYR43.mjs";
7
7
 
8
8
  // src/Core/Lens.ts
9
9
  var Lens;
@@ -1092,6 +1092,7 @@ var RemoteData;
1092
1092
  RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
1093
1093
  RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
1094
1094
  RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
1095
+ RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
1095
1096
  })(RemoteData || (RemoteData = {}));
1096
1097
 
1097
1098
  // src/Core/Resource.ts
@@ -1205,6 +1206,7 @@ var TaskResult;
1205
1206
  )(data);
1206
1207
  TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
1207
1208
  TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
1209
+ TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
1208
1210
  })(TaskResult || (TaskResult = {}));
1209
1211
 
1210
1212
  // src/Core/Validation.ts
@@ -20,6 +20,7 @@ var Maybe;
20
20
  Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
21
21
  Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
22
22
  Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
23
+ Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
23
24
  Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
24
25
  Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
25
26
  Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
@@ -60,6 +61,10 @@ var Result;
60
61
  if ((0, Result2.isOk)(data)) f(data.value);
61
62
  return data;
62
63
  };
64
+ Result2.tapError = (f) => (data) => {
65
+ if ((0, Result2.isErr)(data)) f(data.error);
66
+ return data;
67
+ };
63
68
  Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
64
69
  Result2.recoverUnless = (blockedErr, fallback) => (data) => (0, Result2.isErr)(data) && data.error !== blockedErr ? fallback() : data;
65
70
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
package/dist/core.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-C7M6gLYu.mjs';
2
- export { E as Err, N as None, O as Ok, S as Some } from './Task-C7M6gLYu.mjs';
1
+ import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-BoqaFsUR.mjs';
2
+ export { E as Err, N as None, O as Ok, S as Some } from './Task-BoqaFsUR.mjs';
3
3
  import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
4
4
 
5
5
  /** Keys of T for which undefined is assignable (i.e. optional fields). */
@@ -1644,6 +1644,17 @@ declare namespace RemoteData {
1644
1644
  * ```
1645
1645
  */
1646
1646
  const toResult: <E>(onNotReady: () => E) => <A>(data: RemoteData<E, A>) => Result<E, A>;
1647
+ /**
1648
+ * Converts a Result to a RemoteData.
1649
+ * Ok becomes Success, Err becomes Failure.
1650
+ *
1651
+ * @example
1652
+ * ```ts
1653
+ * const result = await TaskResult.tryCatch(fetchUser, String)();
1654
+ * setState(RemoteData.fromResult(result)); // Success(user) or Failure(msg)
1655
+ * ```
1656
+ */
1657
+ const fromResult: <E, A>(data: Result<E, A>) => RemoteData<E, A>;
1647
1658
  }
1648
1659
 
1649
1660
  /**
@@ -1723,6 +1734,20 @@ declare namespace TaskResult {
1723
1734
  * Useful for logging or debugging.
1724
1735
  */
1725
1736
  const tap: <E, A>(f: (a: A) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
1737
+ /**
1738
+ * Executes a side effect on the error value without changing the TaskResult.
1739
+ * Useful for logging or reporting async errors.
1740
+ *
1741
+ * @example
1742
+ * ```ts
1743
+ * pipe(
1744
+ * fetchUser(id),
1745
+ * TaskResult.tapError(e => console.error("fetch failed:", e)),
1746
+ * TaskResult.chain(saveToCache),
1747
+ * )
1748
+ * ```
1749
+ */
1750
+ const tapError: <E, A>(f: (e: E) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
1726
1751
  }
1727
1752
 
1728
1753
  /**
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-BbTMuIby.js';
2
- export { E as Err, N as None, O as Ok, S as Some } from './Task-BbTMuIby.js';
1
+ import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-7brqoQrb.js';
2
+ export { E as Err, N as None, O as Ok, S as Some } from './Task-7brqoQrb.js';
3
3
  import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.js';
4
4
 
5
5
  /** Keys of T for which undefined is assignable (i.e. optional fields). */
@@ -1644,6 +1644,17 @@ declare namespace RemoteData {
1644
1644
  * ```
1645
1645
  */
1646
1646
  const toResult: <E>(onNotReady: () => E) => <A>(data: RemoteData<E, A>) => Result<E, A>;
1647
+ /**
1648
+ * Converts a Result to a RemoteData.
1649
+ * Ok becomes Success, Err becomes Failure.
1650
+ *
1651
+ * @example
1652
+ * ```ts
1653
+ * const result = await TaskResult.tryCatch(fetchUser, String)();
1654
+ * setState(RemoteData.fromResult(result)); // Success(user) or Failure(msg)
1655
+ * ```
1656
+ */
1657
+ const fromResult: <E, A>(data: Result<E, A>) => RemoteData<E, A>;
1647
1658
  }
1648
1659
 
1649
1660
  /**
@@ -1723,6 +1734,20 @@ declare namespace TaskResult {
1723
1734
  * Useful for logging or debugging.
1724
1735
  */
1725
1736
  const tap: <E, A>(f: (a: A) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
1737
+ /**
1738
+ * Executes a side effect on the error value without changing the TaskResult.
1739
+ * Useful for logging or reporting async errors.
1740
+ *
1741
+ * @example
1742
+ * ```ts
1743
+ * pipe(
1744
+ * fetchUser(id),
1745
+ * TaskResult.tapError(e => console.error("fetch failed:", e)),
1746
+ * TaskResult.chain(saveToCache),
1747
+ * )
1748
+ * ```
1749
+ */
1750
+ const tapError: <E, A>(f: (e: E) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
1726
1751
  }
1727
1752
 
1728
1753
  /**
package/dist/core.js CHANGED
@@ -126,6 +126,10 @@ var Result;
126
126
  if ((0, Result2.isOk)(data)) f(data.value);
127
127
  return data;
128
128
  };
129
+ Result2.tapError = (f) => (data) => {
130
+ if ((0, Result2.isErr)(data)) f(data.error);
131
+ return data;
132
+ };
129
133
  Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
130
134
  Result2.recoverUnless = (blockedErr, fallback) => (data) => (0, Result2.isErr)(data) && data.error !== blockedErr ? fallback() : data;
131
135
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
@@ -144,6 +148,7 @@ var Maybe;
144
148
  Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
145
149
  Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
146
150
  Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
151
+ Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
147
152
  Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
148
153
  Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
149
154
  Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
@@ -1198,6 +1203,7 @@ var RemoteData;
1198
1203
  RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
1199
1204
  RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
1200
1205
  RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
1206
+ RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
1201
1207
  })(RemoteData || (RemoteData = {}));
1202
1208
 
1203
1209
  // src/Core/Task.ts
@@ -1407,6 +1413,7 @@ var TaskResult;
1407
1413
  )(data);
1408
1414
  TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
1409
1415
  TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
1416
+ TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
1410
1417
  })(TaskResult || (TaskResult = {}));
1411
1418
 
1412
1419
  // src/Core/Validation.ts
package/dist/core.mjs CHANGED
@@ -15,13 +15,13 @@ import {
15
15
  These,
16
16
  Tuple,
17
17
  Validation
18
- } from "./chunk-UFQE2J63.mjs";
18
+ } from "./chunk-NTISCH7Z.mjs";
19
19
  import {
20
20
  Deferred,
21
21
  Maybe,
22
22
  Result,
23
23
  Task
24
- } from "./chunk-2DPG2RDB.mjs";
24
+ } from "./chunk-Z3DYYR43.mjs";
25
25
  export {
26
26
  Deferred,
27
27
  Lens,
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
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';
2
- export { D as Deferred, E as Err, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-C7M6gLYu.mjs';
2
+ export { D as Deferred, E as Err, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-BoqaFsUR.mjs';
3
3
  export { Failure, Invalid, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Valid, Validation } from './core.mjs';
4
4
  export { Brand } from './types.mjs';
5
5
  export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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';
2
- export { D as Deferred, E as Err, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-BbTMuIby.js';
2
+ export { D as Deferred, E as Err, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-7brqoQrb.js';
3
3
  export { Failure, Invalid, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Valid, Validation } from './core.js';
4
4
  export { Brand } from './types.js';
5
5
  export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.js';
package/dist/index.js CHANGED
@@ -371,6 +371,10 @@ var Result;
371
371
  if ((0, Result2.isOk)(data)) f(data.value);
372
372
  return data;
373
373
  };
374
+ Result2.tapError = (f) => (data) => {
375
+ if ((0, Result2.isErr)(data)) f(data.error);
376
+ return data;
377
+ };
374
378
  Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
375
379
  Result2.recoverUnless = (blockedErr, fallback) => (data) => (0, Result2.isErr)(data) && data.error !== blockedErr ? fallback() : data;
376
380
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
@@ -389,6 +393,7 @@ var Maybe;
389
393
  Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
390
394
  Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
391
395
  Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
396
+ Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
392
397
  Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
393
398
  Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
394
399
  Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
@@ -1443,6 +1448,7 @@ var RemoteData;
1443
1448
  RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
1444
1449
  RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
1445
1450
  RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
1451
+ RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
1446
1452
  })(RemoteData || (RemoteData = {}));
1447
1453
 
1448
1454
  // src/Core/Task.ts
@@ -1652,6 +1658,7 @@ var TaskResult;
1652
1658
  )(data);
1653
1659
  TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
1654
1660
  TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
1661
+ TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
1655
1662
  })(TaskResult || (TaskResult = {}));
1656
1663
 
1657
1664
  // src/Core/Validation.ts
@@ -1870,6 +1877,14 @@ var Arr;
1870
1877
  }
1871
1878
  return result;
1872
1879
  };
1880
+ Arr2.filterMap = (f) => (data) => {
1881
+ const result = [];
1882
+ for (let i = 0; i < data.length; i++) {
1883
+ const mapped = f(data[i]);
1884
+ if (mapped.kind === "Some") result.push(mapped.value);
1885
+ }
1886
+ return result;
1887
+ };
1873
1888
  Arr2.partition = (predicate) => (data) => {
1874
1889
  const pass = [];
1875
1890
  const fail = [];
@@ -2298,6 +2313,8 @@ var Str;
2298
2313
  Str2.split = (separator) => (s) => s.split(separator);
2299
2314
  Str2.trim = (s) => s.trim();
2300
2315
  Str2.includes = (substring) => (s) => s.includes(substring);
2316
+ Str2.replace = (pattern, replacement) => (s) => s.replace(pattern, replacement);
2317
+ Str2.replaceAll = (pattern, replacement) => (s) => s.replaceAll(pattern, replacement);
2301
2318
  Str2.startsWith = (prefix) => (s) => s.startsWith(prefix);
2302
2319
  Str2.endsWith = (suffix) => (s) => s.endsWith(suffix);
2303
2320
  Str2.toUpperCase = (s) => s.toUpperCase();
package/dist/index.mjs CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  These,
45
45
  Tuple,
46
46
  Validation
47
- } from "./chunk-UFQE2J63.mjs";
47
+ } from "./chunk-NTISCH7Z.mjs";
48
48
  import {
49
49
  Arr,
50
50
  Dict,
@@ -52,13 +52,13 @@ import {
52
52
  Rec,
53
53
  Str,
54
54
  Uniq
55
- } from "./chunk-C3Z56PCR.mjs";
55
+ } from "./chunk-6H373E63.mjs";
56
56
  import {
57
57
  Deferred,
58
58
  Maybe,
59
59
  Result,
60
60
  Task
61
- } from "./chunk-2DPG2RDB.mjs";
61
+ } from "./chunk-Z3DYYR43.mjs";
62
62
  import {
63
63
  Brand
64
64
  } from "./chunk-BYWKZLHM.mjs";
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as Maybe, R as Result, T as Task } from './Task-C7M6gLYu.mjs';
1
+ import { M as Maybe, R as Result, T as Task } from './Task-BoqaFsUR.mjs';
2
2
  import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
3
3
 
4
4
  /**
@@ -102,6 +102,21 @@ declare namespace Arr {
102
102
  * ```
103
103
  */
104
104
  const filter: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly A[];
105
+ /**
106
+ * Maps each element to a Maybe and collects only the Some values.
107
+ * Combines map and filter in a single pass.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const parseNum = (s: string): Maybe<number> => {
112
+ * const n = Number(s);
113
+ * return isNaN(n) ? Maybe.none() : Maybe.some(n);
114
+ * };
115
+ *
116
+ * pipe(["1", "abc", "3"], Arr.filterMap(parseNum)); // [1, 3]
117
+ * ```
118
+ */
119
+ const filterMap: <A, B>(f: (a: A) => Maybe<B>) => (data: readonly A[]) => readonly B[];
105
120
  /**
106
121
  * Splits an array into two groups based on a predicate.
107
122
  * First group contains elements that satisfy the predicate,
@@ -1041,6 +1056,26 @@ declare namespace Str {
1041
1056
  * ```
1042
1057
  */
1043
1058
  const includes: (substring: string) => (s: string) => boolean;
1059
+ /**
1060
+ * Replaces the first occurrence of a pattern in a string. Data-last: use in `pipe`.
1061
+ *
1062
+ * @example
1063
+ * ```ts
1064
+ * pipe("foo foo foo", Str.replace("foo", "bar")); // "bar foo foo"
1065
+ * pipe("Hello World", Str.replace(/world/i, "Earth")); // "Hello Earth"
1066
+ * ```
1067
+ */
1068
+ const replace: (pattern: string | RegExp, replacement: string) => (s: string) => string;
1069
+ /**
1070
+ * Replaces all occurrences of a pattern in a string. Data-last: use in `pipe`.
1071
+ *
1072
+ * @example
1073
+ * ```ts
1074
+ * pipe("foo foo foo", Str.replaceAll("foo", "bar")); // "bar bar bar"
1075
+ * pipe("aAbBaA", Str.replaceAll(/a/gi, "x")); // "xxBBxx"
1076
+ * ```
1077
+ */
1078
+ const replaceAll: (pattern: string | RegExp, replacement: string) => (s: string) => string;
1044
1079
  /**
1045
1080
  * Returns `true` when the string starts with the given prefix.
1046
1081
  *
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as Maybe, R as Result, T as Task } from './Task-BbTMuIby.js';
1
+ import { M as Maybe, R as Result, T as Task } from './Task-7brqoQrb.js';
2
2
  import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.js';
3
3
 
4
4
  /**
@@ -102,6 +102,21 @@ declare namespace Arr {
102
102
  * ```
103
103
  */
104
104
  const filter: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly A[];
105
+ /**
106
+ * Maps each element to a Maybe and collects only the Some values.
107
+ * Combines map and filter in a single pass.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const parseNum = (s: string): Maybe<number> => {
112
+ * const n = Number(s);
113
+ * return isNaN(n) ? Maybe.none() : Maybe.some(n);
114
+ * };
115
+ *
116
+ * pipe(["1", "abc", "3"], Arr.filterMap(parseNum)); // [1, 3]
117
+ * ```
118
+ */
119
+ const filterMap: <A, B>(f: (a: A) => Maybe<B>) => (data: readonly A[]) => readonly B[];
105
120
  /**
106
121
  * Splits an array into two groups based on a predicate.
107
122
  * First group contains elements that satisfy the predicate,
@@ -1041,6 +1056,26 @@ declare namespace Str {
1041
1056
  * ```
1042
1057
  */
1043
1058
  const includes: (substring: string) => (s: string) => boolean;
1059
+ /**
1060
+ * Replaces the first occurrence of a pattern in a string. Data-last: use in `pipe`.
1061
+ *
1062
+ * @example
1063
+ * ```ts
1064
+ * pipe("foo foo foo", Str.replace("foo", "bar")); // "bar foo foo"
1065
+ * pipe("Hello World", Str.replace(/world/i, "Earth")); // "Hello Earth"
1066
+ * ```
1067
+ */
1068
+ const replace: (pattern: string | RegExp, replacement: string) => (s: string) => string;
1069
+ /**
1070
+ * Replaces all occurrences of a pattern in a string. Data-last: use in `pipe`.
1071
+ *
1072
+ * @example
1073
+ * ```ts
1074
+ * pipe("foo foo foo", Str.replaceAll("foo", "bar")); // "bar bar bar"
1075
+ * pipe("aAbBaA", Str.replaceAll(/a/gi, "x")); // "xxBBxx"
1076
+ * ```
1077
+ */
1078
+ const replaceAll: (pattern: string | RegExp, replacement: string) => (s: string) => string;
1044
1079
  /**
1045
1080
  * Returns `true` when the string starts with the given prefix.
1046
1081
  *
package/dist/utils.js CHANGED
@@ -63,6 +63,10 @@ var Result;
63
63
  if ((0, Result2.isOk)(data)) f(data.value);
64
64
  return data;
65
65
  };
66
+ Result2.tapError = (f) => (data) => {
67
+ if ((0, Result2.isErr)(data)) f(data.error);
68
+ return data;
69
+ };
66
70
  Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
67
71
  Result2.recoverUnless = (blockedErr, fallback) => (data) => (0, Result2.isErr)(data) && data.error !== blockedErr ? fallback() : data;
68
72
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
@@ -81,6 +85,7 @@ var Maybe;
81
85
  Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
82
86
  Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
83
87
  Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
88
+ Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
84
89
  Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
85
90
  Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
86
91
  Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
@@ -231,6 +236,14 @@ var Arr;
231
236
  }
232
237
  return result;
233
238
  };
239
+ Arr2.filterMap = (f) => (data) => {
240
+ const result = [];
241
+ for (let i = 0; i < data.length; i++) {
242
+ const mapped = f(data[i]);
243
+ if (mapped.kind === "Some") result.push(mapped.value);
244
+ }
245
+ return result;
246
+ };
234
247
  Arr2.partition = (predicate) => (data) => {
235
248
  const pass = [];
236
249
  const fail = [];
@@ -659,6 +672,8 @@ var Str;
659
672
  Str2.split = (separator) => (s) => s.split(separator);
660
673
  Str2.trim = (s) => s.trim();
661
674
  Str2.includes = (substring) => (s) => s.includes(substring);
675
+ Str2.replace = (pattern, replacement) => (s) => s.replace(pattern, replacement);
676
+ Str2.replaceAll = (pattern, replacement) => (s) => s.replaceAll(pattern, replacement);
662
677
  Str2.startsWith = (prefix) => (s) => s.startsWith(prefix);
663
678
  Str2.endsWith = (suffix) => (s) => s.endsWith(suffix);
664
679
  Str2.toUpperCase = (s) => s.toUpperCase();
package/dist/utils.mjs CHANGED
@@ -5,8 +5,8 @@ import {
5
5
  Rec,
6
6
  Str,
7
7
  Uniq
8
- } from "./chunk-C3Z56PCR.mjs";
9
- import "./chunk-2DPG2RDB.mjs";
8
+ } from "./chunk-6H373E63.mjs";
9
+ import "./chunk-Z3DYYR43.mjs";
10
10
  import "./chunk-DBIC62UV.mjs";
11
11
  export {
12
12
  Arr,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlozgachev/pipelined",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Opinionated functional abstractions for TypeScript",
5
5
  "license": "BSD-3-Clause",
6
6
  "homepage": "https://pipelined.lozgachev.dev",