@onrails/result
Version:
Tagged Result / ResultAsync for railway-oriented TypeScript — pure tagged unions, neverthrow-shaped compat shim, FL-friendly
29 lines (27 loc) • 1.96 kB
text/typescript
/**
* Variadic point-free composition — chains up to nine unary fns left-to-right
* into one reusable function. The first fn may take multiple arguments; the
* rest are unary. Use {@link pipe} from `@onrails/result` when you already
* have a starting value; use {@link flow} to define a reusable composed
* function with no value yet.
*
* @example
* ```ts
* const parseUserName = flow(
* (raw: string) => parseConfig(raw),
* map((cfg) => cfg.user),
* flatMap((u) => (u.name ? ok(u.name) : err({ kind: "missing" as const }))),
* );
*
* parseUserName(raw); // Result<string, ParseError | { kind: "missing" }>
* ```
*/
declare function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;
declare function flow<A extends readonly unknown[], B, C>(ab: (...a: A) => B, bc: (b: B) => C): (...a: A) => C;
declare function flow<A extends readonly unknown[], B, C, D>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D;
declare function flow<A extends readonly unknown[], B, C, D, E>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): (...a: A) => E;
declare function flow<A extends readonly unknown[], B, C, D, E, F>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): (...a: A) => F;
declare function flow<A extends readonly unknown[], B, C, D, E, F, G>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): (...a: A) => G;
declare function flow<A extends readonly unknown[], B, C, D, E, F, G, H>(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): (...a: A) => H;
declare function flow<A extends readonly 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;
export { flow };