@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/README.md CHANGED
@@ -14,11 +14,11 @@ npm add @nlozgachev/pipelined
14
14
 
15
15
  ## Possibly maybe
16
16
 
17
- **pipelined** names every possible state and gives you operations that compose. `Maybe<A>` for
18
- values that may or may not be there. `Result<E, A>` for operations that succeed or fail with a typed
19
- error. `TaskResult<E, A>` for async operations that keep failures as typed values and propagate
20
- cancellation automatically. `Op<I, E, A>` for managing repeated async interactions — retry, timeout,
21
- and concurrency strategy in one place. And, of course, there is more than that.
17
+ In mainstream TypeScript, code is often burdened by implicit control flow: unchecked exceptions,
18
+ manual null propagation, and unhandled asynchronous failures. `pipelined` turns these complex
19
+ runtime states into simple, transparent data structures that compose. By representing optionality as
20
+ `Maybe`, failures as `Result`, lazy asynchronous pipelines as `TaskResult`, and repeated stateful
21
+ interactions as `Op`, the library helps disentangle business logic from control mechanics.
22
22
 
23
23
  ## Documentation
24
24
 
@@ -54,8 +54,10 @@ Every step that sees `None` is skipped. The fallback runs once, at the end.
54
54
 
55
55
  ## Example: typed async errors
56
56
 
57
- Unhandled rejections are invisible until they crash. `TaskResult<E, A>` keeps failures as typed
58
- values the error type is part of the signature, not a runtime surprise.
57
+ In JavaScript, asynchronous exceptions bypass the static type system, leaving unhandled rejections
58
+ as invisible runtime risks. `TaskResult<E, A>` represents fallible asynchronous computations as
59
+ lazy, infallible tasks that resolve to a typed `Result`. The error type is explicitly tracked in the
60
+ function signature, ensuring that failures are handled before compile time:
59
61
 
60
62
  ```ts
61
63
  import { pipe } from "@nlozgachev/pipelined/composition";
@@ -110,8 +112,10 @@ if (Result.isOk(result)) {
110
112
 
111
113
  ## Example: transforming data
112
114
 
113
- The utils modules wrap JavaScript's built-in types with data-last, curried operations that return
114
- `Maybe` wherever a value might be absent. They compose naturally with the core types:
115
+ Standard JavaScript arrays and records routinely return `undefined` on out-of-bounds access or
116
+ missing keys. The utility modules in `pipelined` wrap these operations with data-last, curried
117
+ helper functions that return `Maybe` when a value might be missing, allowing data transformation
118
+ steps to compose naturally with the core types:
115
119
 
116
120
  ```ts
117
121
  import { pipe } from "@nlozgachev/pipelined/composition";
@@ -148,7 +152,9 @@ the same way.
148
152
 
149
153
  ## Example: retry, timeout, and cancellation
150
154
 
151
- A careful, production-minded attempt at "fetch with retry, timeout, and cancellation":
155
+ Handling robust network interactions including retry attempts, backoff timing, timeouts, and
156
+ signal-driven cancellation — typically requires complex, stateful code that is highly prone to
157
+ subtle race conditions:
152
158
 
153
159
  ```ts
154
160
  type UserResult =
@@ -184,10 +190,6 @@ async function fetchUser(
184
190
  }
185
191
  ```
186
192
 
187
- The signal is forwarded by hand. The timeout needs its own controller. Timed-out aborts are
188
- distinguished from external cancellation by checking `signal?.aborted`. The retry is recursive to
189
- thread the attempt count.
190
-
191
193
  With **pipelined**:
192
194
 
193
195
  ```ts
@@ -228,13 +230,13 @@ if (Op.isOk(outcome)) {
228
230
  fetchUser.abort();
229
231
  ```
230
232
 
231
- ## Example: repeated interactions
232
-
233
- Real UIs make the same call many times — a search input fires on every keystroke, a submit button
234
- gets clicked twice, a polling loop needs to stop when something newer starts. Each scenario has a
235
- different answer to the same question: *what happens to the previous call when a new one arrives?*
233
+ ## Example: repeated UI interactions
236
234
 
237
- `Op` makes that question a one-word configuration choice.
235
+ User interfaces frequently trigger repeated asynchronous events: a search input firing on every
236
+ keystroke, a submit button clicked multiple times, or a polling loop that must terminate when a
237
+ newer request starts. Managing these concurrency scenarios traditionally requires complex, ad-hoc
238
+ state machines. `Op` simplifies this by allowing developers to declare the concurrency strategy as a
239
+ simple configuration choice:
238
240
 
239
241
  **Search — cancel the previous call when the user types:**
240
242
 
@@ -292,78 +294,53 @@ form.addEventListener("submit", (e) => {
292
294
  });
293
295
  ```
294
296
 
295
- `restartable`, `exclusive`, `debounced`, `throttled`, `queue`, `buffered`, `concurrent`, `keyed`,
296
- `once` each strategy is a complete, tested answer to one concurrency scenario. Swap the word, keep
297
- the rest of the code.
298
-
299
- ## What's included?
300
-
301
- The library covers the states you encounter in real applications: values that may be absent,
302
- operations that accumulate multiple errors, data that moves through
303
- `NotAsked >> Loading >> ( Success | Failure )`, async interactions with concurrency policies, nested
304
- immutable updates, and computations that share a common environment. Every type follows the same
305
- conventions — `map`, `chain`, `match`, `getOrElse` — so moving between them feels familiar.
306
-
307
- ### pipelined/core
308
-
309
- - **`Maybe<A>`** a value that may not exist; propagates absence without null checks.
310
- - **`Result<E, A>`** — an operation that succeeds or fails with a typed error.
311
- - **`Validation<E, A>`** — like `Result`, but accumulates every failure instead of stopping at the
312
- first.
313
- - **`Task<A>`** a lazy, infallible async operation; nothing runs until called.
314
- - **`TaskResult<E, A>`** a lazy async operation that can fail with a typed error.
315
- - **`TaskMaybe<A>`** a lazy async operation that may produce nothing.
316
- - **`TaskValidation<E, A>`** a lazy async operation that accumulates validation errors.
317
- - **`Op<I, E, A>`** — a managed async operation with a named concurrency strategy: `restartable`,
318
- `exclusive`, `debounced`, `throttled`, `queue`, `buffered`, `concurrent`, `keyed`, or `once`.
319
- Handles retry, timeout, cancellation, and state in one place.
320
- - **`RemoteData<E, A>`** — the four states of a data fetch: `NotAsked`, `Loading`, `Failure`,
321
- `Success`.
322
- - **`These<A, B>`** an inclusive OR: holds a first value, a second, or both at once.
323
- - **`Lens<S, A>`** focus on a required field in a nested structure. Read, set, and modify
324
- immutably.
325
- - **`Optional<S, A>`** — like `Lens`, but the target may be absent (nullable fields, array indices).
326
- - **`Reader<R, A>`** — a computation that depends on an environment `R`, supplied once at the
327
- boundary.
328
- - **`State<S, A>`** a computation that reads and updates a state value, threaded explicitly
329
- through the chain.
330
- - **`Logged<W, A>`** a computation that accumulates a log alongside its value; no console output,
331
- just data.
332
- - **`Predicate<A>`** — a typed boolean function, composable with `and`, `or`, `not`, and `using`.
333
- - **`Refinement<A, B>`** a type predicate that narrows `A` to `B` at runtime; composes with
334
- `Predicate`.
335
- - **`Resource<E, A>`** an acquire/release pair for safe resource management in `TaskResult`
336
- pipelines.
337
- - **`Deferred<A>`** — an infallible async value: a thenable that always resolves, never rejects.
338
- - **`Tuple<A, B>`** a typed pair with `first`, `second`, `map`, `swap`, and `fold`.
339
-
340
- ### pipelined/utils
341
-
342
- Everyday utilities for built-in JS types.
343
-
344
- - **`Arr`** — array utilities, data-last, returning `Maybe` instead of `undefined`.
345
- - **`Rec`** — record/object utilities, data-last, with `Maybe`-returning key lookup.
346
- - **`Dict`** — `ReadonlyMap<K, V>` utilities: `lookup`, `groupBy`, `upsert`, set operations.
347
- - **`Uniq`** — `ReadonlySet<A>` utilities: `insert`, `remove`, `union`, `intersection`,
348
- `difference`.
349
- - **`Num`** — number utilities: `range`, `clamp`, `between`, safe `parse`, and curried arithmetic.
350
- - **`Str`** — string utilities: `split`, `trim`, `words`, `lines`, and safe `parse.int` /
351
- `parse.float`.
352
-
353
- Every utility is benchmarked against its native equivalent. The data-last currying adds a function
354
- call; that is the expected cost of composability. Operations that exceeded a reasonable overhead
355
- have custom implementations that in several cases run faster than the native method they replace.
356
- See the [benchmarks page](https://pipelined.lozgachev.dev/appendix/benchmarks) for the methodology.
357
-
358
- ### pipelined/types
359
-
360
- - **`Brand<K, T>`** — nominal typing at compile time, zero runtime cost.
361
- - **`NonEmptyList<A>`** — an array guaranteed to have at least one element.
362
-
363
- ### pipelined/composition
364
-
365
- - **`pipe`**, **`flow`**, **`compose`** — function composition.
366
- - **`curry`** / **`uncurry`**, **`tap`**, **`memoize`**, and other function utilities.
297
+ The system supports a variety of built-in strategies — `restartable`, `exclusive`, `debounced`,
298
+ `throttled`, `queue`, `buffered`, `concurrent`, `keyed`, and `once` making the integration of
299
+ complex async scenarios highly predictable.
300
+
301
+ ## What is included
302
+
303
+ The library covers the full spectrum of state and control flow scenarios encountered in production
304
+ applications.
305
+
306
+ ### Core context containers
307
+
308
+ `Maybe` represents explicit optionality without null checks. `Result` handles synchronous, typed
309
+ success and failure, while `Validation` accumulates multiple errors. `RemoteData` tracks the four
310
+ states of an asynchronous data fetch (`NotAsked`, `Loading`, `Failure`, `Success`), and `These`
311
+ handles inclusive-OR scenarios containing a first value, a second, or both simultaneously.
312
+
313
+ ### Asynchronous operations
314
+
315
+ `Task` represents a lazy, infallible asynchronous computation. Fallible asynchronous workflows are
316
+ handled by `TaskResult`, `TaskMaybe`, and `TaskValidation`. For managing stateful, recurring
317
+ asynchronous operations with complex scheduling, `Op` implements named concurrency strategies such
318
+ as `restartable`, `exclusive`, `debounced`, `throttled`, and `queue`, handling retries, timeouts,
319
+ and signal propagation automatically.
320
+
321
+ ### Optics and environment state
322
+
323
+ `Lens` and `Optional` provide a simple concrete interface for safe, nested immutable data updates.
324
+ Environment-dependent calculations and explicit state threading are supported by the `Reader` and
325
+ `State` abstractions, while `Logged` enables side-effect-free data logging.
326
+
327
+ ### Optimized utilities
328
+
329
+ Custom, performance-optimized utility modules (`Arr`, `Rec`, `Dict`, `Uniq`, `Num`, `Str`) wrap
330
+ standard JavaScript types to return explicit types like `Maybe` and support data-last currying.
331
+ Functions are composed using `pipe` and `flow`, which are enriched with high-level composition
332
+ helpers like `when`, `unless`, `either`, `safe`, and `async` to support robust, expressive
333
+ pipelines.
334
+
335
+ ### Nominal branding and non-empty lists
336
+
337
+ Compile-time nominal typing with zero runtime overhead is provided by `Brand`, and `NonEmptyList`
338
+ guarantees that a list is never empty, eliminating defensive array length checks.
339
+
340
+ Every utility in the library is benchmarked against its native equivalent. The data-last currying
341
+ adds a small function call overhead, which is the expected cost of composability. For operations
342
+ where native overhead is significant, custom implementations are used that often run faster than
343
+ their native counterparts.
367
344
 
368
345
  ## License
369
346
 
@@ -125,6 +125,53 @@ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
125
125
  }
126
126
  }
127
127
  }
128
+ var when = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
129
+ var unless = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
130
+ var either = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
131
+ var struct = (fields) => (a) => {
132
+ const result = {};
133
+ for (const key of Object.keys(fields)) {
134
+ result[key] = fields[key](a);
135
+ }
136
+ return result;
137
+ };
138
+ function safe(...fns) {
139
+ return (a) => {
140
+ let result = a;
141
+ if (result === null || result === void 0) {
142
+ return result;
143
+ }
144
+ for (const fn of fns) {
145
+ result = fn(result);
146
+ if (result === null || result === void 0) {
147
+ return result;
148
+ }
149
+ }
150
+ return result;
151
+ };
152
+ }
153
+ function async(...fns) {
154
+ return async (a) => {
155
+ let result = await a;
156
+ for (const fn of fns) {
157
+ result = await fn(result);
158
+ }
159
+ return result;
160
+ };
161
+ }
162
+ flow.when = when;
163
+ flow.unless = unless;
164
+ flow.either = either;
165
+ flow.struct = struct;
166
+ flow.safe = safe;
167
+ flow.async = async;
168
+ flow.try = (f, onError) => (a) => {
169
+ try {
170
+ return f(a);
171
+ } catch (error) {
172
+ return onError(error, a);
173
+ }
174
+ };
128
175
 
129
176
  // src/Composition/fn.ts
130
177
  var identity = (a) => a;
@@ -148,6 +195,7 @@ var once = (f) => {
148
195
  return result;
149
196
  };
150
197
  };
198
+ var defaultTo = (fallback) => (a) => a === null || a === void 0 ? fallback : a;
151
199
 
152
200
  // src/Composition/juxt.ts
153
201
  function juxt(fns) {
@@ -223,6 +271,49 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
223
271
  }
224
272
  }
225
273
  }
274
+ var when2 = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
275
+ var unless2 = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
276
+ var either2 = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
277
+ var struct2 = (fields) => (a) => {
278
+ const result = {};
279
+ for (const key of Object.keys(fields)) {
280
+ result[key] = fields[key](a);
281
+ }
282
+ return result;
283
+ };
284
+ function safe2(a, ...fns) {
285
+ let result = a;
286
+ if (result === null || result === void 0) {
287
+ return result;
288
+ }
289
+ for (const fn of fns) {
290
+ result = fn(result);
291
+ if (result === null || result === void 0) {
292
+ return result;
293
+ }
294
+ }
295
+ return result;
296
+ }
297
+ async function async2(a, ...fns) {
298
+ let result = await a;
299
+ for (const fn of fns) {
300
+ result = await fn(result);
301
+ }
302
+ return result;
303
+ }
304
+ pipe.when = when2;
305
+ pipe.unless = unless2;
306
+ pipe.either = either2;
307
+ pipe.struct = struct2;
308
+ pipe.safe = safe2;
309
+ pipe.async = async2;
310
+ pipe.try = (f, onError) => (a) => {
311
+ try {
312
+ return f(a);
313
+ } catch (error) {
314
+ return onError(error, a);
315
+ }
316
+ };
226
317
 
227
318
  // src/Composition/tap.ts
228
319
  var tap = (f) => (a) => {
@@ -258,6 +349,7 @@ export {
258
349
  and,
259
350
  or,
260
351
  once,
352
+ defaultTo,
261
353
  juxt,
262
354
  memoize,
263
355
  memoizeWeak,
@@ -1092,7 +1092,7 @@ var Op;
1092
1092
  }
1093
1093
  return cases.nil();
1094
1094
  };
1095
- Op2.fold = (onErr, onOk, onNil) => (outcome) => {
1095
+ Op2.fold = (onErr, onNil, onOk) => (outcome) => {
1096
1096
  if (outcome.kind === "OpOk") {
1097
1097
  return onOk(outcome.value);
1098
1098
  }
@@ -1321,17 +1321,17 @@ var RemoteData;
1321
1321
  }
1322
1322
  return (0, RemoteData2.notAsked)();
1323
1323
  };
1324
- RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
1324
+ RemoteData2.fold = (onFailure, onNotAsked, onLoading, onSuccess) => (data) => {
1325
1325
  switch (data.kind) {
1326
+ case "Failure": {
1327
+ return onFailure(data.error);
1328
+ }
1326
1329
  case "NotAsked": {
1327
1330
  return onNotAsked();
1328
1331
  }
1329
1332
  case "Loading": {
1330
1333
  return onLoading();
1331
1334
  }
1332
- case "Failure": {
1333
- return onFailure(data.error);
1334
- }
1335
1335
  case "Success": {
1336
1336
  return onSuccess(data.value);
1337
1337
  }
@@ -120,6 +120,26 @@ declare const curry4: <A, B, C, D, E>(f: (a: A, b: B, c: C, d: D) => E) => (a: A
120
120
  */
121
121
  declare const flip: <A, B, C>(f: (a: A) => (b: B) => C) => (b: B) => (a: A) => C;
122
122
 
123
+ declare function safe$1<A, B>(ab: (a: NonNullable<A>) => B): (a: A) => B | Extract<A, null | undefined>;
124
+ declare function safe$1<A, B, C>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C): (a: A) => C | Extract<A | B, null | undefined>;
125
+ declare function safe$1<A, B, C, D>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D): (a: A) => D | Extract<A | B | C, null | undefined>;
126
+ declare function safe$1<A, B, C, D, E>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E): (a: A) => E | Extract<A | B | C | D, null | undefined>;
127
+ declare function safe$1<A, B, C, D, E, F>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F): (a: A) => F | Extract<A | B | C | D | E, null | undefined>;
128
+ declare function safe$1<A, B, C, D, E, F, G>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G): (a: A) => G | Extract<A | B | C | D | E | F, null | undefined>;
129
+ declare function safe$1<A, B, C, D, E, F, G, H>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H): (a: A) => H | Extract<A | B | C | D | E | F | G, null | undefined>;
130
+ declare function safe$1<A, B, C, D, E, F, G, H, I>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I): (a: A) => I | Extract<A | B | C | D | E | F | G | H, null | undefined>;
131
+ declare function safe$1<A, B, C, D, E, F, G, H, I, J>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I, ij: (i: NonNullable<I>) => J): (a: A) => J | Extract<A | B | C | D | E | F | G | H | I, null | undefined>;
132
+ declare function safe$1<A, B, C, D, E, F, G, H, I, J, K>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I, ij: (i: NonNullable<I>) => J, jk: (j: J) => K): (a: A) => K | Extract<A | B | C | D | E | F | G | H | I | J, null | undefined>;
133
+ declare function async$1<A, B>(ab: (a: A) => B | Promise<B>): (a: A | Promise<A>) => Promise<B>;
134
+ declare function async$1<A, B, C>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>): (a: A | Promise<A>) => Promise<C>;
135
+ declare function async$1<A, B, C, D>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>): (a: A | Promise<A>) => Promise<D>;
136
+ declare function async$1<A, B, C, D, E>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>): (a: A | Promise<A>) => Promise<E>;
137
+ declare function async$1<A, B, C, D, E, F>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>): (a: A | Promise<A>) => Promise<F>;
138
+ declare function async$1<A, B, C, D, E, F, G>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>): (a: A | Promise<A>) => Promise<G>;
139
+ declare function async$1<A, B, C, D, E, F, G, H>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>): (a: A | Promise<A>) => Promise<H>;
140
+ declare function async$1<A, B, C, D, E, F, G, H, I>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>): (a: A | Promise<A>) => Promise<I>;
141
+ declare function async$1<A, B, C, D, E, F, G, H, I, J>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>, ij: (i: I) => J): (a: A | Promise<A>) => Promise<J>;
142
+ declare function async$1<A, B, C, D, E, F, G, H, I, J, K>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>, ij: (i: I) => J | Promise<J>, jk: (j: J) => K | Promise<K>): (a: A | Promise<A>) => Promise<K>;
123
143
  /**
124
144
  * Composes functions from left to right, returning a new function.
125
145
  * Unlike `pipe`, `flow` doesn't take an initial value - it creates
@@ -170,6 +190,71 @@ declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H>(ab:
170
190
  declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): (...a: A) => I;
171
191
  declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): (...a: A) => J;
172
192
  declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K): (...a: A) => K;
193
+ declare namespace flow {
194
+ export var when: <A>(predicate: (a: A) => boolean, onTrue: (a: A) => A) => (a: A) => A;
195
+ export var unless: <A>(predicate: (a: A) => boolean, onFalse: (a: A) => A) => (a: A) => A;
196
+ export var either: <A, B>(predicate: (a: A) => boolean, onTrue: (a: A) => B, onFalse: (a: A) => B) => (a: A) => B;
197
+ export var struct: <A, R extends Record<string, unknown>>(fields: { [K in keyof R]: (a: A) => R[K]; }) => (a: A) => R;
198
+ export var safe: {
199
+ <A, B>(ab: (a: NonNullable<A>) => B): (a: A) => B | Extract<A, null | undefined>;
200
+ <A, B, C>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C): (a: A) => C | Extract<A | B, null | undefined>;
201
+ <A, B, C, D>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D): (a: A) => D | Extract<A | B | C, null | undefined>;
202
+ <A, B, C, D, E>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E): (a: A) => E | Extract<A | B | C | D, null | undefined>;
203
+ <A, B, C, D, E, F>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F): (a: A) => F | Extract<A | B | C | D | E, null | undefined>;
204
+ <A, B, C, D, E, F, G>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G): (a: A) => G | Extract<A | B | C | D | E | F, null | undefined>;
205
+ <A, B, C, D, E, F, G, H>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H): (a: A) => H | Extract<A | B | C | D | E | F | G, null | undefined>;
206
+ <A, B, C, D, E, F, G, H, I>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I): (a: A) => I | Extract<A | B | C | D | E | F | G | H, null | undefined>;
207
+ <A, B, C, D, E, F, G, H, I, J>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I, ij: (i: NonNullable<I>) => J): (a: A) => J | Extract<A | B | C | D | E | F | G | H | I, null | undefined>;
208
+ <A, B, C, D, E, F, G, H, I, J, K>(ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I, ij: (i: NonNullable<I>) => J, jk: (j: J) => K): (a: A) => K | Extract<A | B | C | D | E | F | G | H | I | J, null | undefined>;
209
+ };
210
+ export var async: {
211
+ <A, B>(ab: (a: A) => B | Promise<B>): (a: A | Promise<A>) => Promise<B>;
212
+ <A, B, C>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>): (a: A | Promise<A>) => Promise<C>;
213
+ <A, B, C, D>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>): (a: A | Promise<A>) => Promise<D>;
214
+ <A, B, C, D, E>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>): (a: A | Promise<A>) => Promise<E>;
215
+ <A, B, C, D, E, F>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>): (a: A | Promise<A>) => Promise<F>;
216
+ <A, B, C, D, E, F, G>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>): (a: A | Promise<A>) => Promise<G>;
217
+ <A, B, C, D, E, F, G, H>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>): (a: A | Promise<A>) => Promise<H>;
218
+ <A, B, C, D, E, F, G, H, I>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>): (a: A | Promise<A>) => Promise<I>;
219
+ <A, B, C, D, E, F, G, H, I, J>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>, ij: (i: I) => J): (a: A | Promise<A>) => Promise<J>;
220
+ <A, B, C, D, E, F, G, H, I, J, K>(ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>, ij: (i: I) => J | Promise<J>, jk: (j: J) => K | Promise<K>): (a: A | Promise<A>) => Promise<K>;
221
+ };
222
+ var _a: <A, B, C>(f: (a: A) => B, onError: (error: unknown, value: A) => C) => (a: A) => B | C;
223
+ export { _a as try };
224
+ }
225
+ interface flow {
226
+ /**
227
+ * Executes a function on the piped value if a predicate is met, otherwise returns the value unchanged.
228
+ */
229
+ readonly when: <A>(predicate: (a: A) => boolean, onTrue: (a: A) => A) => (a: A) => A;
230
+ /**
231
+ * Executes a function on the piped value if a predicate is NOT met, otherwise returns the value unchanged.
232
+ */
233
+ readonly unless: <A>(predicate: (a: A) => boolean, onFalse: (a: A) => A) => (a: A) => A;
234
+ /**
235
+ * Executes one of two functions based on a predicate, acting as a functional if-else/ternary helper.
236
+ */
237
+ readonly either: <A, B>(predicate: (a: A) => boolean, onTrue: (a: A) => B, onFalse: (a: A) => B) => (a: A) => B;
238
+ /**
239
+ * Creates a pipeline step that wraps a throwing function in a try/catch, returning a fallback value if an error occurs.
240
+ */
241
+ readonly try: <A, B, C>(f: (a: A) => B, onError: (error: unknown, value: A) => C) => (a: A) => B | C;
242
+ /**
243
+ * Builds an object by applying a record of field-level transformer functions to the piped input.
244
+ */
245
+ readonly struct: <A, R extends Record<string, unknown>>(fields: {
246
+ [K in keyof R]: (a: A) => R[K];
247
+ }) => (a: A) => R;
248
+ /**
249
+ * Pipes a value through a sequence of operations, short-circuiting and propagating
250
+ * null or undefined immediately if any intermediate step evaluates to nil.
251
+ */
252
+ readonly safe: typeof safe$1;
253
+ /**
254
+ * Pipes a value through a sequence of operations, supporting asynchronous transitions at any step.
255
+ */
256
+ readonly async: typeof async$1;
257
+ }
173
258
 
174
259
  /**
175
260
  * Returns the value unchanged. The identity function.
@@ -246,6 +331,20 @@ declare const or: <A extends ReadonlyArray<unknown>>(p1: (...args: A) => boolean
246
331
  * ```
247
332
  */
248
333
  declare const once: <A>(f: () => A) => () => A;
334
+ /**
335
+ * Returns a fallback value if the input is null or undefined; otherwise returns the input value.
336
+ * Highly useful as a data-last default value step inside pipelines.
337
+ *
338
+ * @example
339
+ * ```ts
340
+ * const getName = flow(
341
+ * (u: { name?: string | null }) => u.name,
342
+ * defaultTo("Guest"),
343
+ * name => name.toUpperCase()
344
+ * ); // returns string
345
+ * ```
346
+ */
347
+ declare const defaultTo: <B>(fallback: B) => <A>(a: A) => NonNullable<A> | B;
249
348
 
250
349
  /**
251
350
  * Applies an input to an array of functions and collects the results into a tuple.
@@ -350,6 +449,28 @@ declare const not: <A extends ReadonlyArray<unknown>>(predicate: (...args: A) =>
350
449
  */
351
450
  declare const on: <A, B, C>(f: (b1: B, b2: B) => C, g: (a: A) => B) => (a: A, b: A) => C;
352
451
 
452
+ declare function safe<A>(a: A): A;
453
+ declare function safe<A, B>(a: A, ab: (a: NonNullable<A>) => B): B | Extract<A, null | undefined>;
454
+ declare function safe<A, B, C>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C): C | Extract<A | B, null | undefined>;
455
+ declare function safe<A, B, C, D>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D): D | Extract<A | B | C, null | undefined>;
456
+ declare function safe<A, B, C, D, E>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E): E | Extract<A | B | C | D, null | undefined>;
457
+ declare function safe<A, B, C, D, E, F>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F): F | Extract<A | B | C | D | E, null | undefined>;
458
+ declare function safe<A, B, C, D, E, F, G>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G): G | Extract<A | B | C | D | E | F, null | undefined>;
459
+ declare function safe<A, B, C, D, E, F, G, H>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H): H | Extract<A | B | C | D | E | F | G, null | undefined>;
460
+ declare function safe<A, B, C, D, E, F, G, H, I>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I): I | Extract<A | B | C | D | E | F | G | H, null | undefined>;
461
+ declare function safe<A, B, C, D, E, F, G, H, I, J>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I, ij: (i: NonNullable<I>) => J): J | Extract<A | B | C | D | E | F | G | H | I, null | undefined>;
462
+ declare function safe<A, B, C, D, E, F, G, H, I, J, K>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I, ij: (i: NonNullable<I>) => J, jk: (j: J) => K): K | Extract<A | B | C | D | E | F | G | H | I | J, null | undefined>;
463
+ declare function async<A>(a: A | Promise<A>): Promise<A>;
464
+ declare function async<A, B>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>): Promise<B>;
465
+ declare function async<A, B, C>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>): Promise<C>;
466
+ declare function async<A, B, C, D>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>): Promise<D>;
467
+ declare function async<A, B, C, D, E>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>): Promise<E>;
468
+ declare function async<A, B, C, D, E, F>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>): Promise<F>;
469
+ declare function async<A, B, C, D, E, F, G>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>): Promise<G>;
470
+ declare function async<A, B, C, D, E, F, G, H>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>): Promise<H>;
471
+ declare function async<A, B, C, D, E, F, G, H, I>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>): Promise<I>;
472
+ declare function async<A, B, C, D, E, F, G, H, I, J>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>, ij: (i: I) => J): Promise<J>;
473
+ declare function async<A, B, C, D, E, F, G, H, I, J, K>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>, ij: (i: I) => J | Promise<J>, jk: (j: J) => K | Promise<K>): Promise<K>;
353
474
  /**
354
475
  * Pipes a value through a series of functions from left to right.
355
476
  * Each function receives the output of the previous function.
@@ -399,6 +520,73 @@ declare function pipe<A, B, C, D, E, F, G, H>(a: A, ab: (a: A) => B, bc: (b: B)
399
520
  declare function pipe<A, B, C, D, E, F, G, H, I>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): I;
400
521
  declare function pipe<A, B, C, D, E, F, G, H, I, J>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): J;
401
522
  declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K): K;
523
+ declare namespace pipe {
524
+ export var when: <A>(predicate: (a: A) => boolean, onTrue: (a: A) => A) => (a: A) => A;
525
+ export var unless: <A>(predicate: (a: A) => boolean, onFalse: (a: A) => A) => (a: A) => A;
526
+ export var either: <A, B>(predicate: (a: A) => boolean, onTrue: (a: A) => B, onFalse: (a: A) => B) => (a: A) => B;
527
+ export var struct: <A, R extends Record<string, unknown>>(fields: { [K in keyof R]: (a: A) => R[K]; }) => (a: A) => R;
528
+ export var safe: {
529
+ <A>(a: A): A;
530
+ <A, B>(a: A, ab: (a: NonNullable<A>) => B): B | Extract<A, null | undefined>;
531
+ <A, B, C>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C): C | Extract<A | B, null | undefined>;
532
+ <A, B, C, D>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D): D | Extract<A | B | C, null | undefined>;
533
+ <A, B, C, D, E>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E): E | Extract<A | B | C | D, null | undefined>;
534
+ <A, B, C, D, E, F>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F): F | Extract<A | B | C | D | E, null | undefined>;
535
+ <A, B, C, D, E, F, G>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G): G | Extract<A | B | C | D | E | F, null | undefined>;
536
+ <A, B, C, D, E, F, G, H>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H): H | Extract<A | B | C | D | E | F | G, null | undefined>;
537
+ <A, B, C, D, E, F, G, H, I>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I): I | Extract<A | B | C | D | E | F | G | H, null | undefined>;
538
+ <A, B, C, D, E, F, G, H, I, J>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I, ij: (i: NonNullable<I>) => J): J | Extract<A | B | C | D | E | F | G | H | I, null | undefined>;
539
+ <A, B, C, D, E, F, G, H, I, J, K>(a: A, ab: (a: NonNullable<A>) => B, bc: (b: NonNullable<B>) => C, cd: (c: NonNullable<C>) => D, de: (d: NonNullable<D>) => E, ef: (e: NonNullable<E>) => F, fg: (f: NonNullable<F>) => G, gh: (g: NonNullable<G>) => H, hi: (h: NonNullable<H>) => I, ij: (i: NonNullable<I>) => J, jk: (j: J) => K): K | Extract<A | B | C | D | E | F | G | H | I | J, null | undefined>;
540
+ };
541
+ export var async: {
542
+ <A>(a: A | Promise<A>): Promise<A>;
543
+ <A, B>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>): Promise<B>;
544
+ <A, B, C>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>): Promise<C>;
545
+ <A, B, C, D>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>): Promise<D>;
546
+ <A, B, C, D, E>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>): Promise<E>;
547
+ <A, B, C, D, E, F>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>): Promise<F>;
548
+ <A, B, C, D, E, F, G>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>): Promise<G>;
549
+ <A, B, C, D, E, F, G, H>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>): Promise<H>;
550
+ <A, B, C, D, E, F, G, H, I>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>): Promise<I>;
551
+ <A, B, C, D, E, F, G, H, I, J>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>, ij: (i: I) => J): Promise<J>;
552
+ <A, B, C, D, E, F, G, H, I, J, K>(a: A | Promise<A>, ab: (a: A) => B | Promise<B>, bc: (b: B) => C | Promise<C>, cd: (c: C) => D | Promise<D>, de: (d: D) => E | Promise<E>, ef: (e: E) => F | Promise<F>, fg: (f: F) => G | Promise<G>, gh: (g: G) => H | Promise<H>, hi: (h: H) => I | Promise<I>, ij: (i: I) => J | Promise<J>, jk: (j: J) => K | Promise<K>): Promise<K>;
553
+ };
554
+ var _a: <A, B, C>(f: (a: A) => B, onError: (error: unknown, value: A) => C) => (a: A) => B | C;
555
+ export { _a as try };
556
+ }
557
+ interface pipe {
558
+ /**
559
+ * Executes a function on the piped value if a predicate is met, otherwise returns the value unchanged.
560
+ */
561
+ readonly when: <A>(predicate: (a: A) => boolean, onTrue: (a: A) => A) => (a: A) => A;
562
+ /**
563
+ * Executes a function on the piped value if a predicate is NOT met, otherwise returns the value unchanged.
564
+ */
565
+ readonly unless: <A>(predicate: (a: A) => boolean, onFalse: (a: A) => A) => (a: A) => A;
566
+ /**
567
+ * Executes one of two functions based on a predicate, acting as a functional if-else/ternary helper.
568
+ */
569
+ readonly either: <A, B>(predicate: (a: A) => boolean, onTrue: (a: A) => B, onFalse: (a: A) => B) => (a: A) => B;
570
+ /**
571
+ * Creates a pipeline step that wraps a throwing function in a try/catch, returning a fallback value if an error occurs.
572
+ */
573
+ readonly try: <A, B, C>(f: (a: A) => B, onError: (error: unknown, value: A) => C) => (a: A) => B | C;
574
+ /**
575
+ * Builds an object by applying a record of field-level transformer functions to the piped input.
576
+ */
577
+ readonly struct: <A, R extends Record<string, unknown>>(fields: {
578
+ [K in keyof R]: (a: A) => R[K];
579
+ }) => (a: A) => R;
580
+ /**
581
+ * Pipes a value through a sequence of operations, short-circuiting and propagating
582
+ * null or undefined immediately if any intermediate step evaluates to nil.
583
+ */
584
+ readonly safe: typeof safe;
585
+ /**
586
+ * Pipes a value through a sequence of operations, supporting asynchronous transitions at any step.
587
+ */
588
+ readonly async: typeof async;
589
+ }
402
590
 
403
591
  /**
404
592
  * Executes a side effect function and returns the original value unchanged.
@@ -485,4 +673,4 @@ declare const uncurry3: <A, B, C, D>(f: (a: A) => (b: B) => (c: C) => D) => (a:
485
673
  */
486
674
  declare const uncurry4: <A, B, C, D, E>(f: (a: A) => (b: B) => (c: C) => (d: D) => E) => (a: A, b: B, c: C, d: D) => E;
487
675
 
488
- 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 };
676
+ 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 };