@onrails/result 0.3.1 → 0.4.1

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.
Files changed (73) hide show
  1. package/DESIGN.md +4 -3
  2. package/README.md +166 -13
  3. package/RECIPES.md +6 -4
  4. package/dist/async-fns.cjs +52 -0
  5. package/dist/async-fns.cjs.map +1 -0
  6. package/dist/async-fns.d.cts +143 -0
  7. package/dist/async-fns.d.ts +143 -0
  8. package/dist/async-fns.js +42 -0
  9. package/dist/async-fns.js.map +1 -0
  10. package/dist/async-lift.d.cts +109 -0
  11. package/dist/async-lift.d.ts +109 -0
  12. package/dist/{async-Ci6WSL5-.d.ts → async.d.cts} +42 -58
  13. package/dist/{async-DcXR7k9K.d.cts → async.d.ts} +42 -58
  14. package/dist/collections.d.cts +105 -0
  15. package/dist/collections.d.ts +105 -0
  16. package/dist/compat/neverthrow.cjs +57 -45
  17. package/dist/compat/neverthrow.cjs.map +1 -1
  18. package/dist/compat/neverthrow.d.cts +21 -24
  19. package/dist/compat/neverthrow.d.ts +21 -24
  20. package/dist/compat/neverthrow.js +56 -44
  21. package/dist/compat/neverthrow.js.map +1 -1
  22. package/dist/extra.cjs +3 -1
  23. package/dist/extra.cjs.map +1 -1
  24. package/dist/extra.d.cts +11 -14
  25. package/dist/extra.d.ts +11 -14
  26. package/dist/extra.js +3 -1
  27. package/dist/extra.js.map +1 -1
  28. package/dist/fluent.cjs +15 -28
  29. package/dist/fluent.cjs.map +1 -1
  30. package/dist/fluent.d.cts +4 -34
  31. package/dist/fluent.d.ts +4 -34
  32. package/dist/fluent.js +16 -28
  33. package/dist/fluent.js.map +1 -1
  34. package/dist/index.cjs +77 -52
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +28 -490
  37. package/dist/index.d.ts +28 -490
  38. package/dist/index.js +77 -53
  39. package/dist/index.js.map +1 -1
  40. package/dist/internal/ctor.d.cts +12 -0
  41. package/dist/internal/ctor.d.ts +12 -0
  42. package/dist/internal/dual.d.cts +42 -0
  43. package/dist/internal/dual.d.ts +42 -0
  44. package/dist/internal/infer.d.cts +40 -0
  45. package/dist/internal/infer.d.ts +40 -0
  46. package/dist/internal/lock.d.cts +16 -0
  47. package/dist/internal/lock.d.ts +16 -0
  48. package/dist/internal/to-error.d.cts +2 -0
  49. package/dist/internal/to-error.d.ts +2 -0
  50. package/dist/pipe.cjs +8 -0
  51. package/dist/pipe.cjs.map +1 -1
  52. package/dist/pipe.d.cts +58 -11
  53. package/dist/pipe.d.ts +58 -11
  54. package/dist/pipe.js +8 -1
  55. package/dist/pipe.js.map +1 -1
  56. package/dist/railway.cjs +87 -63
  57. package/dist/railway.cjs.map +1 -1
  58. package/dist/railway.d.cts +49 -19
  59. package/dist/railway.d.ts +49 -19
  60. package/dist/railway.js +87 -63
  61. package/dist/railway.js.map +1 -1
  62. package/dist/result.d.cts +315 -0
  63. package/dist/result.d.ts +315 -0
  64. package/dist/try-gen.cjs +3 -3
  65. package/dist/try-gen.cjs.map +1 -1
  66. package/dist/try-gen.d.cts +4 -7
  67. package/dist/try-gen.d.ts +4 -7
  68. package/dist/try-gen.js +3 -3
  69. package/dist/try-gen.js.map +1 -1
  70. package/dist/{types-BQ9vv0nD.d.cts → types.d.cts} +6 -8
  71. package/dist/{types-BQ9vv0nD.d.ts → types.d.ts} +6 -8
  72. package/package.json +69 -24
  73. package/skills/railway-do-notation/SKILL.md +9 -9
@@ -0,0 +1,12 @@
1
+ import type { Result } from "../types.js";
2
+ /**
3
+ * Unlocked `Ok` constructor for library internals.
4
+ *
5
+ * The public {@link ok} takes a `const` type parameter so caller literals stay
6
+ * narrow. That is wrong inside a generic transform, where the payload type is
7
+ * an unresolved type parameter and the resulting `Locked<T>` would never reduce
8
+ * back to `T`. Internals build results through this constructor instead.
9
+ */
10
+ export declare const mkOk: <T, E = never>(value: T) => Result<T, E>;
11
+ /** Unlocked `Err` constructor for library internals. Mirror of {@link mkOk}. */
12
+ export declare const mkErr: <T = never, E = unknown>(error: E) => Result<T, E>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @onrails/result internal — owning module for the **dual-form idiom**.
3
+ *
4
+ * Every dual-form transform in this package (`map`, `flatMap`, `match`, …)
5
+ * accepts either shape:
6
+ *
7
+ * data-first: `map(result, fn)` — full arity, runs immediately
8
+ * curried: `map(fn)(result)` — arity minus the leading `self`, returns
9
+ * a unary function awaiting the data
10
+ *
11
+ * {@link dual} is the single arity dispatcher those transforms derive from;
12
+ * hand-rolled `args.length` checks are not allowed elsewhere.
13
+ *
14
+ * NOTE: a twin copy of this module lives at `packages/maybe/src/internal/dual.ts`
15
+ * — keep the two in sync when editing.
16
+ *
17
+ * Internal only: not listed in package.json `exports` or tsup entries.
18
+ */
19
+ /**
20
+ * Derive a dual-form (data-first / curried) function from a single
21
+ * data-first `body`.
22
+ *
23
+ * When called with `args.length >= arity` the wrapper runs `body(...args)`
24
+ * (data-first). With fewer arguments it returns `(self) => body(self, ...args)`
25
+ * — the curried, data-last-`self` form used with `pipe`/`flow`.
26
+ *
27
+ * The public type is supplied entirely by the caller: annotate the exported
28
+ * const with the exact overload set and let `F` be inferred from it.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * export const map: {
33
+ * <T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
34
+ * <T, U>(fn: (value: T) => U): <E>(result: Result<T, E>) => Result<U, E>;
35
+ * } = dual(
36
+ * 2,
37
+ * <T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E> =>
38
+ * isOk(result) ? ok(fn(result.value)) : err(result.error),
39
+ * );
40
+ * ```
41
+ */
42
+ export declare const dual: <F>(arity: number, body: (...args: never[]) => unknown) => F;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @onrails/result internal — owning module for the **dual-form idiom**.
3
+ *
4
+ * Every dual-form transform in this package (`map`, `flatMap`, `match`, …)
5
+ * accepts either shape:
6
+ *
7
+ * data-first: `map(result, fn)` — full arity, runs immediately
8
+ * curried: `map(fn)(result)` — arity minus the leading `self`, returns
9
+ * a unary function awaiting the data
10
+ *
11
+ * {@link dual} is the single arity dispatcher those transforms derive from;
12
+ * hand-rolled `args.length` checks are not allowed elsewhere.
13
+ *
14
+ * NOTE: a twin copy of this module lives at `packages/maybe/src/internal/dual.ts`
15
+ * — keep the two in sync when editing.
16
+ *
17
+ * Internal only: not listed in package.json `exports` or tsup entries.
18
+ */
19
+ /**
20
+ * Derive a dual-form (data-first / curried) function from a single
21
+ * data-first `body`.
22
+ *
23
+ * When called with `args.length >= arity` the wrapper runs `body(...args)`
24
+ * (data-first). With fewer arguments it returns `(self) => body(self, ...args)`
25
+ * — the curried, data-last-`self` form used with `pipe`/`flow`.
26
+ *
27
+ * The public type is supplied entirely by the caller: annotate the exported
28
+ * const with the exact overload set and let `F` be inferred from it.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * export const map: {
33
+ * <T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
34
+ * <T, U>(fn: (value: T) => U): <E>(result: Result<T, E>) => Result<U, E>;
35
+ * } = dual(
36
+ * 2,
37
+ * <T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E> =>
38
+ * isOk(result) ? ok(fn(result.value)) : err(result.error),
39
+ * );
40
+ * ```
41
+ */
42
+ export declare const dual: <F>(arity: number, body: (...args: never[]) => unknown) => F;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @onrails/result internal — the single payload-extraction pair.
3
+ *
4
+ * `InferOk` / `InferErr` pull the success/error type out of a {@link Result}
5
+ * (tagged union) or a {@link ResultAsync} (class carrier), resolving to
6
+ * `never` for anything else. Every module that needs to extract a payload
7
+ * type imports from here; do not redeclare local copies.
8
+ *
9
+ * Internal only: not listed in package.json `exports` or tsup entries.
10
+ * The package index re-exports the pair under the same names.
11
+ */
12
+ import type { ResultAsync } from "../async.js";
13
+ /**
14
+ * Extracts the `Ok` value type from a {@link Result} or {@link ResultAsync},
15
+ * resolving to `never` for any other type.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * type T = InferOk<Result<number, string>>; // number
20
+ * type U = InferOk<ResultAsync<User, AppError>>; // User
21
+ * ```
22
+ */
23
+ export type InferOk<R> = R extends {
24
+ _tag: "Ok";
25
+ readonly value: infer T;
26
+ } ? T : R extends ResultAsync<infer T, unknown> ? T : never;
27
+ /**
28
+ * Extracts the `Err` error type from a {@link Result} or {@link ResultAsync},
29
+ * resolving to `never` for any other type. Mirror of {@link InferOk}.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * type E = InferErr<Result<number, string>>; // string
34
+ * type F = InferErr<ResultAsync<User, AppError>>; // AppError
35
+ * ```
36
+ */
37
+ export type InferErr<R> = R extends {
38
+ _tag: "Err";
39
+ readonly error: infer E;
40
+ } ? E : R extends ResultAsync<unknown, infer E> ? E : never;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @onrails/result internal — the single payload-extraction pair.
3
+ *
4
+ * `InferOk` / `InferErr` pull the success/error type out of a {@link Result}
5
+ * (tagged union) or a {@link ResultAsync} (class carrier), resolving to
6
+ * `never` for anything else. Every module that needs to extract a payload
7
+ * type imports from here; do not redeclare local copies.
8
+ *
9
+ * Internal only: not listed in package.json `exports` or tsup entries.
10
+ * The package index re-exports the pair under the same names.
11
+ */
12
+ import type { ResultAsync } from "../async.js";
13
+ /**
14
+ * Extracts the `Ok` value type from a {@link Result} or {@link ResultAsync},
15
+ * resolving to `never` for any other type.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * type T = InferOk<Result<number, string>>; // number
20
+ * type U = InferOk<ResultAsync<User, AppError>>; // User
21
+ * ```
22
+ */
23
+ export type InferOk<R> = R extends {
24
+ _tag: "Ok";
25
+ readonly value: infer T;
26
+ } ? T : R extends ResultAsync<infer T, unknown> ? T : never;
27
+ /**
28
+ * Extracts the `Err` error type from a {@link Result} or {@link ResultAsync},
29
+ * resolving to `never` for any other type. Mirror of {@link InferOk}.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * type E = InferErr<Result<number, string>>; // string
34
+ * type F = InferErr<ResultAsync<User, AppError>>; // AppError
35
+ * ```
36
+ */
37
+ export type InferErr<R> = R extends {
38
+ _tag: "Err";
39
+ readonly error: infer E;
40
+ } ? E : R extends ResultAsync<unknown, infer E> ? E : never;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Payload type produced by the literal-locking constructors (`ok` / `err` and
3
+ * their async twins). Those take a `const` type parameter, so an inline literal
4
+ * keeps its narrow type instead of widening (`"a"` stays `"a"`, not `string`).
5
+ *
6
+ * `const` inference also turns every array literal into a `readonly` tuple,
7
+ * which would stop `ok([1, 2])` from satisfying `Result<number[], E>`. This
8
+ * type undoes exactly that side effect and nothing else:
9
+ *
10
+ * • tuple (fixed length) → same positions, `readonly` dropped, elements locked
11
+ * • unbounded array → left as authored (a `readonly T[]` input stays readonly)
12
+ * • anything else → untouched (objects keep their deep-readonly literal shape)
13
+ */
14
+ export type Locked<T> = T extends readonly unknown[] ? number extends T["length"] ? T : {
15
+ -readonly [K in keyof T]: Locked<T[K]>;
16
+ } : T;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Payload type produced by the literal-locking constructors (`ok` / `err` and
3
+ * their async twins). Those take a `const` type parameter, so an inline literal
4
+ * keeps its narrow type instead of widening (`"a"` stays `"a"`, not `string`).
5
+ *
6
+ * `const` inference also turns every array literal into a `readonly` tuple,
7
+ * which would stop `ok([1, 2])` from satisfying `Result<number[], E>`. This
8
+ * type undoes exactly that side effect and nothing else:
9
+ *
10
+ * • tuple (fixed length) → same positions, `readonly` dropped, elements locked
11
+ * • unbounded array → left as authored (a `readonly T[]` input stays readonly)
12
+ * • anything else → untouched (objects keep their deep-readonly literal shape)
13
+ */
14
+ export type Locked<T> = T extends readonly unknown[] ? number extends T["length"] ? T : {
15
+ -readonly [K in keyof T]: Locked<T[K]>;
16
+ } : T;
@@ -0,0 +1,2 @@
1
+ /** Normalizes an unknown thrown/rejected value into an `Error`. */
2
+ export declare const toError: (error: unknown) => Error;
@@ -0,0 +1,2 @@
1
+ /** Normalizes an unknown thrown/rejected value into an `Error`. */
2
+ export declare const toError: (error: unknown) => Error;
package/dist/pipe.cjs CHANGED
@@ -1,6 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  // src/pipe.ts
4
+ function pipe(value, ...fns) {
5
+ let acc = value;
6
+ for (const fn of fns) {
7
+ acc = fn(acc);
8
+ }
9
+ return acc;
10
+ }
4
11
  function flow(first, ...rest) {
5
12
  return (...args) => {
6
13
  let acc = first(...args);
@@ -12,5 +19,6 @@ function flow(first, ...rest) {
12
19
  }
13
20
 
14
21
  exports.flow = flow;
22
+ exports.pipe = pipe;
15
23
  //# sourceMappingURL=pipe.cjs.map
16
24
  //# sourceMappingURL=pipe.cjs.map
package/dist/pipe.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pipe.ts"],"names":[],"mappings":";;;AAoEO,SAAS,IAAA,CACd,UACG,IAAA,EAC8B;AACjC,EAAA,OAAO,IAAI,IAAA,KAAoB;AAC7B,IAAA,IAAI,GAAA,GAAM,KAAA,CAAM,GAAG,IAAI,CAAA;AACvB,IAAA,KAAA,MAAW,MAAM,IAAA,EAAM;AACrB,MAAA,GAAA,GAAM,GAAG,GAAG,CAAA;AAAA,IACd;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF","file":"pipe.cjs","sourcesContent":["/**\n * Variadic point-free composition — chains up to nine unary fns left-to-right\n * into one reusable function. The first fn may take multiple arguments; the\n * rest are unary. Use {@link pipe} from `@onrails/result` when you already\n * have a starting value; use {@link flow} to define a reusable composed\n * function with no value yet.\n *\n * @example\n * ```ts\n * const parseUserName = flow(\n * (raw: string) => parseConfig(raw),\n * map((cfg) => cfg.user),\n * flatMap((u) => (u.name ? ok(u.name) : err({ kind: \"missing\" as const }))),\n * );\n *\n * parseUserName(raw); // Result<string, ParseError | { kind: \"missing\" }>\n * ```\n */\nexport function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;\nexport function flow<A extends readonly unknown[], B, C>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n): (...a: A) => C;\nexport function flow<A extends readonly unknown[], B, C, D>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n): (...a: A) => D;\nexport function flow<A extends readonly unknown[], B, C, D, E>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n): (...a: A) => E;\nexport function flow<A extends readonly unknown[], B, C, D, E, F>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n): (...a: A) => F;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n): (...a: A) => G;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n): (...a: A) => H;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n): (...a: A) => I;\nexport function flow(\n first: (...args: unknown[]) => unknown,\n ...rest: ReadonlyArray<(x: unknown) => unknown>\n): (...args: unknown[]) => unknown {\n return (...args: unknown[]) => {\n let acc = first(...args);\n for (const fn of rest) {\n acc = fn(acc);\n }\n return acc;\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/pipe.ts"],"names":[],"mappings":";;;AAyIO,SAAS,IAAA,CAAK,UAAmB,GAAA,EAAsD;AAC5F,EAAA,IAAI,GAAA,GAAM,KAAA;AACV,EAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,IAAA,GAAA,GAAM,GAAG,GAAG,CAAA;AAAA,EACd;AACA,EAAA,OAAO,GAAA;AACT;AAwHO,SAAS,IAAA,CACd,UACG,IAAA,EAC8B;AACjC,EAAA,OAAO,IAAI,IAAA,KAAoB;AAC7B,IAAA,IAAI,GAAA,GAAM,KAAA,CAAM,GAAG,IAAI,CAAA;AACvB,IAAA,KAAA,MAAW,MAAM,IAAA,EAAM;AACrB,MAAA,GAAA,GAAM,GAAG,GAAG,CAAA;AAAA,IACd;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF","file":"pipe.cjs","sourcesContent":["/**\n * `@onrails/result/pipe` — the two composition entry points.\n *\n * {@link pipe} threads a starting value left-to-right through unary steps.\n * {@link flow} composes the steps into a reusable function with no value yet;\n * its first step may take multiple arguments.\n *\n * Both are hand-written overload towers rather than one recursive variadic\n * signature. That is deliberate: a variadic `...fns: F` cannot give each step a\n * contextual type from the previous step's output, so lambda parameters degrade\n * to `unknown` (`map((cfg) => cfg.user)` stops inferring). The tower costs lines\n * and caps the chain length; the alternative costs inference everywhere.\n *\n * The cap is {@link MAX_STEPS} steps. Longer chains nest — `pipe(pipe(v, ...), ...)`\n * — or factor a segment into a named `flow`.\n */\n\n/** Documented step cap for {@link pipe} and {@link flow}. */\nexport type MAX_STEPS = 12;\n\n/**\n * Variadic value-first pipe — threads `value` through up to twelve unary fns,\n * left-to-right. Use {@link pipe} when you already have a starting value; use\n * {@link flow} to define a reusable composed function with no value yet.\n *\n * @example\n * ```ts\n * pipe(\n * parseConfig(raw),\n * map((cfg) => cfg.user),\n * flatMap((u) => (u.name ? ok(u.name) : err({ kind: \"missing\" as const }))),\n * );\n * ```\n */\nexport function pipe<A>(value: A): A;\nexport function pipe<A, B>(value: A, ab: (a: A) => B): B;\nexport function pipe<A, B, C>(value: A, ab: (a: A) => B, bc: (b: B) => C): C;\nexport function pipe<A, B, C, D>(value: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;\nexport function pipe<A, B, C, D, E>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n): E;\nexport function pipe<A, B, C, D, E, F>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n): F;\nexport function pipe<A, B, C, D, E, F, G>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n): G;\nexport function pipe<A, B, C, D, E, F, G, H>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n): H;\nexport function pipe<A, B, C, D, E, F, G, H, I>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n): I;\nexport function pipe<A, B, C, D, E, F, G, H, I, J>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n): J;\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n): K;\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n): L;\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n): M;\nexport function pipe(value: unknown, ...fns: ReadonlyArray<(x: unknown) => unknown>): unknown {\n let acc = value;\n for (const fn of fns) {\n acc = fn(acc);\n }\n return acc;\n}\n\n/**\n * Variadic point-free composition — chains up to twelve unary fns left-to-right\n * into one reusable function. The first fn may take multiple arguments; the\n * rest are unary. Use {@link pipe} from `@onrails/result` when you already\n * have a starting value; use {@link flow} to define a reusable composed\n * function with no value yet.\n *\n * @example\n * ```ts\n * const parseUserName = flow(\n * (raw: string) => parseConfig(raw),\n * map((cfg) => cfg.user),\n * flatMap((u) => (u.name ? ok(u.name) : err({ kind: \"missing\" as const }))),\n * );\n *\n * parseUserName(raw); // Result<string, ParseError | { kind: \"missing\" }>\n * ```\n */\nexport function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;\nexport function flow<A extends readonly unknown[], B, C>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n): (...a: A) => C;\nexport function flow<A extends readonly unknown[], B, C, D>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n): (...a: A) => D;\nexport function flow<A extends readonly unknown[], B, C, D, E>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n): (...a: A) => E;\nexport function flow<A extends readonly unknown[], B, C, D, E, F>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n): (...a: A) => F;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n): (...a: A) => G;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n): (...a: A) => H;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n): (...a: A) => I;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n): (...a: A) => J;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n): (...a: A) => K;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K, L>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n): (...a: A) => L;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K, L, M>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n): (...a: A) => M;\nexport function flow(\n first: (...args: unknown[]) => unknown,\n ...rest: ReadonlyArray<(x: unknown) => unknown>\n): (...args: unknown[]) => unknown {\n return (...args: unknown[]) => {\n let acc = first(...args);\n for (const fn of rest) {\n acc = fn(acc);\n }\n return acc;\n };\n}\n"]}
package/dist/pipe.d.cts CHANGED
@@ -1,5 +1,50 @@
1
1
  /**
2
- * Variadic point-free composition — chains up to nine unary fns left-to-right
2
+ * `@onrails/result/pipe` — the two composition entry points.
3
+ *
4
+ * {@link pipe} threads a starting value left-to-right through unary steps.
5
+ * {@link flow} composes the steps into a reusable function with no value yet;
6
+ * its first step may take multiple arguments.
7
+ *
8
+ * Both are hand-written overload towers rather than one recursive variadic
9
+ * signature. That is deliberate: a variadic `...fns: F` cannot give each step a
10
+ * contextual type from the previous step's output, so lambda parameters degrade
11
+ * to `unknown` (`map((cfg) => cfg.user)` stops inferring). The tower costs lines
12
+ * and caps the chain length; the alternative costs inference everywhere.
13
+ *
14
+ * The cap is {@link MAX_STEPS} steps. Longer chains nest — `pipe(pipe(v, ...), ...)`
15
+ * — or factor a segment into a named `flow`.
16
+ */
17
+ /** Documented step cap for {@link pipe} and {@link flow}. */
18
+ export type MAX_STEPS = 12;
19
+ /**
20
+ * Variadic value-first pipe — threads `value` through up to twelve unary fns,
21
+ * left-to-right. Use {@link pipe} when you already have a starting value; use
22
+ * {@link flow} to define a reusable composed function with no value yet.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * pipe(
27
+ * parseConfig(raw),
28
+ * map((cfg) => cfg.user),
29
+ * flatMap((u) => (u.name ? ok(u.name) : err({ kind: "missing" as const }))),
30
+ * );
31
+ * ```
32
+ */
33
+ export declare function pipe<A>(value: A): A;
34
+ export declare function pipe<A, B>(value: A, ab: (a: A) => B): B;
35
+ export declare function pipe<A, B, C>(value: A, ab: (a: A) => B, bc: (b: B) => C): C;
36
+ export declare function pipe<A, B, C, D>(value: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;
37
+ export declare function pipe<A, B, C, D, E>(value: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E;
38
+ export declare function pipe<A, B, C, D, E, F>(value: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F;
39
+ export declare function pipe<A, B, C, D, E, F, G>(value: 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): G;
40
+ export declare function pipe<A, B, C, D, E, F, G, H>(value: 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): H;
41
+ export declare function pipe<A, B, C, D, E, F, G, H, I>(value: 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;
42
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J>(value: 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;
43
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(value: 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;
44
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(value: 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, kl: (k: K) => L): L;
45
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(value: 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, kl: (k: K) => L, lm: (l: L) => M): M;
46
+ /**
47
+ * Variadic point-free composition — chains up to twelve unary fns left-to-right
3
48
  * into one reusable function. The first fn may take multiple arguments; the
4
49
  * rest are unary. Use {@link pipe} from `@onrails/result` when you already
5
50
  * have a starting value; use {@link flow} to define a reusable composed
@@ -16,13 +61,15 @@
16
61
  * parseUserName(raw); // Result<string, ParseError | { kind: "missing" }>
17
62
  * ```
18
63
  */
19
- declare function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;
20
- declare function flow<A extends readonly unknown[], B, C>(ab: (...a: A) => B, bc: (b: B) => C): (...a: A) => C;
21
- 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;
22
- 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;
23
- 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;
24
- 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;
25
- 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;
26
- 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;
27
-
28
- export { flow };
64
+ export declare function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;
65
+ export declare function flow<A extends readonly unknown[], B, C>(ab: (...a: A) => B, bc: (b: B) => C): (...a: A) => C;
66
+ export 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;
67
+ export 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;
68
+ export 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;
69
+ export 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;
70
+ export 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;
71
+ export 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;
72
+ export declare function flow<A extends readonly 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;
73
+ export declare function flow<A extends readonly 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;
74
+ export declare function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K, L>(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, kl: (k: K) => L): (...a: A) => L;
75
+ export declare function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K, L, M>(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, kl: (k: K) => L, lm: (l: L) => M): (...a: A) => M;
package/dist/pipe.d.ts CHANGED
@@ -1,5 +1,50 @@
1
1
  /**
2
- * Variadic point-free composition — chains up to nine unary fns left-to-right
2
+ * `@onrails/result/pipe` — the two composition entry points.
3
+ *
4
+ * {@link pipe} threads a starting value left-to-right through unary steps.
5
+ * {@link flow} composes the steps into a reusable function with no value yet;
6
+ * its first step may take multiple arguments.
7
+ *
8
+ * Both are hand-written overload towers rather than one recursive variadic
9
+ * signature. That is deliberate: a variadic `...fns: F` cannot give each step a
10
+ * contextual type from the previous step's output, so lambda parameters degrade
11
+ * to `unknown` (`map((cfg) => cfg.user)` stops inferring). The tower costs lines
12
+ * and caps the chain length; the alternative costs inference everywhere.
13
+ *
14
+ * The cap is {@link MAX_STEPS} steps. Longer chains nest — `pipe(pipe(v, ...), ...)`
15
+ * — or factor a segment into a named `flow`.
16
+ */
17
+ /** Documented step cap for {@link pipe} and {@link flow}. */
18
+ export type MAX_STEPS = 12;
19
+ /**
20
+ * Variadic value-first pipe — threads `value` through up to twelve unary fns,
21
+ * left-to-right. Use {@link pipe} when you already have a starting value; use
22
+ * {@link flow} to define a reusable composed function with no value yet.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * pipe(
27
+ * parseConfig(raw),
28
+ * map((cfg) => cfg.user),
29
+ * flatMap((u) => (u.name ? ok(u.name) : err({ kind: "missing" as const }))),
30
+ * );
31
+ * ```
32
+ */
33
+ export declare function pipe<A>(value: A): A;
34
+ export declare function pipe<A, B>(value: A, ab: (a: A) => B): B;
35
+ export declare function pipe<A, B, C>(value: A, ab: (a: A) => B, bc: (b: B) => C): C;
36
+ export declare function pipe<A, B, C, D>(value: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;
37
+ export declare function pipe<A, B, C, D, E>(value: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E;
38
+ export declare function pipe<A, B, C, D, E, F>(value: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F;
39
+ export declare function pipe<A, B, C, D, E, F, G>(value: 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): G;
40
+ export declare function pipe<A, B, C, D, E, F, G, H>(value: 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): H;
41
+ export declare function pipe<A, B, C, D, E, F, G, H, I>(value: 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;
42
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J>(value: 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;
43
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(value: 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;
44
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(value: 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, kl: (k: K) => L): L;
45
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(value: 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, kl: (k: K) => L, lm: (l: L) => M): M;
46
+ /**
47
+ * Variadic point-free composition — chains up to twelve unary fns left-to-right
3
48
  * into one reusable function. The first fn may take multiple arguments; the
4
49
  * rest are unary. Use {@link pipe} from `@onrails/result` when you already
5
50
  * have a starting value; use {@link flow} to define a reusable composed
@@ -16,13 +61,15 @@
16
61
  * parseUserName(raw); // Result<string, ParseError | { kind: "missing" }>
17
62
  * ```
18
63
  */
19
- declare function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;
20
- declare function flow<A extends readonly unknown[], B, C>(ab: (...a: A) => B, bc: (b: B) => C): (...a: A) => C;
21
- 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;
22
- 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;
23
- 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;
24
- 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;
25
- 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;
26
- 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;
27
-
28
- export { flow };
64
+ export declare function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;
65
+ export declare function flow<A extends readonly unknown[], B, C>(ab: (...a: A) => B, bc: (b: B) => C): (...a: A) => C;
66
+ export 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;
67
+ export 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;
68
+ export 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;
69
+ export 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;
70
+ export 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;
71
+ export 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;
72
+ export declare function flow<A extends readonly 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;
73
+ export declare function flow<A extends readonly 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;
74
+ export declare function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K, L>(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, kl: (k: K) => L): (...a: A) => L;
75
+ export declare function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K, L, M>(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, kl: (k: K) => L, lm: (l: L) => M): (...a: A) => M;
package/dist/pipe.js CHANGED
@@ -1,4 +1,11 @@
1
1
  // src/pipe.ts
2
+ function pipe(value, ...fns) {
3
+ let acc = value;
4
+ for (const fn of fns) {
5
+ acc = fn(acc);
6
+ }
7
+ return acc;
8
+ }
2
9
  function flow(first, ...rest) {
3
10
  return (...args) => {
4
11
  let acc = first(...args);
@@ -9,6 +16,6 @@ function flow(first, ...rest) {
9
16
  };
10
17
  }
11
18
 
12
- export { flow };
19
+ export { flow, pipe };
13
20
  //# sourceMappingURL=pipe.js.map
14
21
  //# sourceMappingURL=pipe.js.map
package/dist/pipe.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pipe.ts"],"names":[],"mappings":";AAoEO,SAAS,IAAA,CACd,UACG,IAAA,EAC8B;AACjC,EAAA,OAAO,IAAI,IAAA,KAAoB;AAC7B,IAAA,IAAI,GAAA,GAAM,KAAA,CAAM,GAAG,IAAI,CAAA;AACvB,IAAA,KAAA,MAAW,MAAM,IAAA,EAAM;AACrB,MAAA,GAAA,GAAM,GAAG,GAAG,CAAA;AAAA,IACd;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF","file":"pipe.js","sourcesContent":["/**\n * Variadic point-free composition — chains up to nine unary fns left-to-right\n * into one reusable function. The first fn may take multiple arguments; the\n * rest are unary. Use {@link pipe} from `@onrails/result` when you already\n * have a starting value; use {@link flow} to define a reusable composed\n * function with no value yet.\n *\n * @example\n * ```ts\n * const parseUserName = flow(\n * (raw: string) => parseConfig(raw),\n * map((cfg) => cfg.user),\n * flatMap((u) => (u.name ? ok(u.name) : err({ kind: \"missing\" as const }))),\n * );\n *\n * parseUserName(raw); // Result<string, ParseError | { kind: \"missing\" }>\n * ```\n */\nexport function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;\nexport function flow<A extends readonly unknown[], B, C>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n): (...a: A) => C;\nexport function flow<A extends readonly unknown[], B, C, D>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n): (...a: A) => D;\nexport function flow<A extends readonly unknown[], B, C, D, E>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n): (...a: A) => E;\nexport function flow<A extends readonly unknown[], B, C, D, E, F>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n): (...a: A) => F;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n): (...a: A) => G;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n): (...a: A) => H;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n): (...a: A) => I;\nexport function flow(\n first: (...args: unknown[]) => unknown,\n ...rest: ReadonlyArray<(x: unknown) => unknown>\n): (...args: unknown[]) => unknown {\n return (...args: unknown[]) => {\n let acc = first(...args);\n for (const fn of rest) {\n acc = fn(acc);\n }\n return acc;\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/pipe.ts"],"names":[],"mappings":";AAyIO,SAAS,IAAA,CAAK,UAAmB,GAAA,EAAsD;AAC5F,EAAA,IAAI,GAAA,GAAM,KAAA;AACV,EAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,IAAA,GAAA,GAAM,GAAG,GAAG,CAAA;AAAA,EACd;AACA,EAAA,OAAO,GAAA;AACT;AAwHO,SAAS,IAAA,CACd,UACG,IAAA,EAC8B;AACjC,EAAA,OAAO,IAAI,IAAA,KAAoB;AAC7B,IAAA,IAAI,GAAA,GAAM,KAAA,CAAM,GAAG,IAAI,CAAA;AACvB,IAAA,KAAA,MAAW,MAAM,IAAA,EAAM;AACrB,MAAA,GAAA,GAAM,GAAG,GAAG,CAAA;AAAA,IACd;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF","file":"pipe.js","sourcesContent":["/**\n * `@onrails/result/pipe` — the two composition entry points.\n *\n * {@link pipe} threads a starting value left-to-right through unary steps.\n * {@link flow} composes the steps into a reusable function with no value yet;\n * its first step may take multiple arguments.\n *\n * Both are hand-written overload towers rather than one recursive variadic\n * signature. That is deliberate: a variadic `...fns: F` cannot give each step a\n * contextual type from the previous step's output, so lambda parameters degrade\n * to `unknown` (`map((cfg) => cfg.user)` stops inferring). The tower costs lines\n * and caps the chain length; the alternative costs inference everywhere.\n *\n * The cap is {@link MAX_STEPS} steps. Longer chains nest — `pipe(pipe(v, ...), ...)`\n * — or factor a segment into a named `flow`.\n */\n\n/** Documented step cap for {@link pipe} and {@link flow}. */\nexport type MAX_STEPS = 12;\n\n/**\n * Variadic value-first pipe — threads `value` through up to twelve unary fns,\n * left-to-right. Use {@link pipe} when you already have a starting value; use\n * {@link flow} to define a reusable composed function with no value yet.\n *\n * @example\n * ```ts\n * pipe(\n * parseConfig(raw),\n * map((cfg) => cfg.user),\n * flatMap((u) => (u.name ? ok(u.name) : err({ kind: \"missing\" as const }))),\n * );\n * ```\n */\nexport function pipe<A>(value: A): A;\nexport function pipe<A, B>(value: A, ab: (a: A) => B): B;\nexport function pipe<A, B, C>(value: A, ab: (a: A) => B, bc: (b: B) => C): C;\nexport function pipe<A, B, C, D>(value: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;\nexport function pipe<A, B, C, D, E>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n): E;\nexport function pipe<A, B, C, D, E, F>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n): F;\nexport function pipe<A, B, C, D, E, F, G>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n): G;\nexport function pipe<A, B, C, D, E, F, G, H>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n): H;\nexport function pipe<A, B, C, D, E, F, G, H, I>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n): I;\nexport function pipe<A, B, C, D, E, F, G, H, I, J>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n): J;\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n): K;\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n): L;\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(\n value: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n): M;\nexport function pipe(value: unknown, ...fns: ReadonlyArray<(x: unknown) => unknown>): unknown {\n let acc = value;\n for (const fn of fns) {\n acc = fn(acc);\n }\n return acc;\n}\n\n/**\n * Variadic point-free composition — chains up to twelve unary fns left-to-right\n * into one reusable function. The first fn may take multiple arguments; the\n * rest are unary. Use {@link pipe} from `@onrails/result` when you already\n * have a starting value; use {@link flow} to define a reusable composed\n * function with no value yet.\n *\n * @example\n * ```ts\n * const parseUserName = flow(\n * (raw: string) => parseConfig(raw),\n * map((cfg) => cfg.user),\n * flatMap((u) => (u.name ? ok(u.name) : err({ kind: \"missing\" as const }))),\n * );\n *\n * parseUserName(raw); // Result<string, ParseError | { kind: \"missing\" }>\n * ```\n */\nexport function flow<A extends readonly unknown[], B>(ab: (...a: A) => B): (...a: A) => B;\nexport function flow<A extends readonly unknown[], B, C>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n): (...a: A) => C;\nexport function flow<A extends readonly unknown[], B, C, D>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n): (...a: A) => D;\nexport function flow<A extends readonly unknown[], B, C, D, E>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n): (...a: A) => E;\nexport function flow<A extends readonly unknown[], B, C, D, E, F>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n): (...a: A) => F;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n): (...a: A) => G;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n): (...a: A) => H;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n): (...a: A) => I;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n): (...a: A) => J;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n): (...a: A) => K;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K, L>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n): (...a: A) => L;\nexport function flow<A extends readonly unknown[], B, C, D, E, F, G, H, I, J, K, L, M>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n): (...a: A) => M;\nexport function flow(\n first: (...args: unknown[]) => unknown,\n ...rest: ReadonlyArray<(x: unknown) => unknown>\n): (...args: unknown[]) => unknown {\n return (...args: unknown[]) => {\n let acc = first(...args);\n for (const fn of rest) {\n acc = fn(acc);\n }\n return acc;\n };\n}\n"]}