@railway-ts/pipelines 0.1.30 → 0.2.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 +4 -4
- package/dist/composition/index.d.mts +367 -0
- package/dist/composition/index.mjs +37 -59
- package/dist/composition/index.mjs.map +1 -1
- package/dist/{result/index.d.cts → index-DDkNG41b.d.mts} +63 -139
- package/dist/option/index.d.mts +7 -0
- package/dist/option/index.mjs +1 -114
- package/dist/option-BQCaaEBP.mjs +909 -0
- package/dist/option-BQCaaEBP.mjs.map +1 -0
- package/dist/result/index.d.mts +7 -0
- package/dist/result/index.mjs +1 -185
- package/dist/schema/{index.d.cts → index.d.mts} +227 -259
- package/dist/schema/index.mjs +1646 -978
- package/dist/schema/index.mjs.map +1 -1
- package/docs/GETTING_STARTED.md +1 -1
- package/docs/RECIPES.md +3 -3
- package/package.json +21 -70
- package/dist/composition/index.cjs +0 -94
- package/dist/composition/index.cjs.map +0 -1
- package/dist/composition/index.d.cts +0 -373
- package/dist/composition/index.d.ts +0 -373
- package/dist/option/index.cjs +0 -137
- package/dist/option/index.cjs.map +0 -1
- package/dist/option/index.d.cts +0 -1
- package/dist/option/index.d.ts +0 -1
- package/dist/option/index.mjs.map +0 -1
- package/dist/result/index.cjs +0 -219
- package/dist/result/index.cjs.map +0 -1
- package/dist/result/index.d.ts +0 -1063
- package/dist/result/index.mjs.map +0 -1
- package/dist/schema/index.cjs +0 -1165
- package/dist/schema/index.cjs.map +0 -1
- package/dist/schema/index.d.ts +0 -1266
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/composition/pipe.ts","../../src/composition/flow.ts","../../src/composition/pipe-async.ts","../../src/composition/flow-async.ts","../../src/composition/curry.ts","../../src/composition/uncurry.ts","../../src/composition/tupled.ts","../../src/composition/untupled.ts"],"names":[],"mappings":";AA8GO,SAAS,IAAA,CAAK,UAAmB,GAAA,EAAiC;AACvE,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,IAAA,MAAA,GAAS,GAAG,MAAM,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,MAAA;AACT;;;ACkBO,SAAS,QAAQ,GAAA,EAA+D;AACrF,EAAA,IAAI,GAAA,CAAI,WAAW,CAAA,EAAG;AACpB,IAAA,OAAO,IAAI,CAAC,CAAA;AAAA,EACd;AAEA,EAAA,MAAM,CAAC,KAAA,EAAO,GAAG,IAAI,CAAA,GAAI,GAAA;AACzB,EAAA,OAAO,IAAI,IAAA,KAA6B;AACtC,IAAA,IAAI,MAAA,GAAS,KAAA,CAAM,GAAG,IAAI,CAAA;AAC1B,IAAA,KAAA,MAAW,MAAM,IAAA,EAAM;AACrB,MAAA,MAAA,GAAS,GAAG,MAAM,CAAA;AAAA,IACpB;AACA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF;;;AC5CA,eAAsB,SAAA,CAAU,MAAe,GAAA,EAA0C;AACvF,EAAA,IAAI,SAAS,MAAM,CAAA;AACnB,EAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,IAAA,MAAA,GAAS,MAAM,GAAG,MAAM,CAAA;AAAA,EAC1B;AACA,EAAA,OAAO,MAAA;AACT;;;ACHO,SAAS,SAAA,CACd,UACG,GAAA,EACuC;AAC1C,EAAA,OAAO,UAAU,IAAA,KAAoB;AACnC,IAAA,IAAI,MAAA,GAAS,MAAM,KAAA,CAAM,GAAG,IAAI,CAAA;AAChC,IAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,MAAA,MAAA,GAAS,MAAM,GAAG,MAAM,CAAA;AAAA,IAC1B;AACA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF;;;AChEO,SAAS,MAAiC,EAAA,EAAwB;AACvE,EAAA,MAAM,QAAQ,EAAA,CAAG,MAAA;AAEjB,EAAA,OAAO,SAAS,WAAW,IAAA,EAA0B;AACnD,IAAA,IAAI,IAAA,CAAK,UAAU,KAAA,EAAO;AACxB,MAAA,OAAQ,EAAA,CAAuB,GAAG,IAAI,CAAA;AAAA,IACxC;AAEA,IAAA,OAAO,YAAa,QAAA,EAA8B;AAChD,MAAA,OAAO,OAAA,CAAQ,GAAG,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,IACrC,CAAA;AAAA,EACF,CAAA;AACF;;;ACPO,SAAS,QAAQ,EAAA,EAAsB;AAC5C,EAAA,OAAO,SAAS,aAAa,IAAA,EAA0B;AAErD,IAAA,IAAI,MAAA,GAAS,EAAA;AAEb,IAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACtB,MAAA,MAAA,GAAU,OAA2B,GAAG,CAAA;AAAA,IAC1C;AAEA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF;;;ACbO,SAAS,OAAkC,EAAA,EAAqC;AACrF,EAAA,OAAO,SAAS,SAAS,IAAA,EAA0B;AACjD,IAAA,OAAO,EAAA,CAAG,GAAG,IAAI,CAAA;AAAA,EACnB,CAAA;AACF;;;ACPO,SAAS,SAAoC,EAAA,EAAwB;AAC1E,EAAA,OAAO,SAAS,cAAc,IAAA,EAA0B;AACtD,IAAA,OAAO,GAAG,IAAI,CAAA;AAAA,EAChB,CAAA;AACF","file":"index.mjs","sourcesContent":["import type { UnknownFunction } from './types';\n\n/**\n * Pipes a value through a series of functions, from left to right.\n * Each function receives the output of the previous function.\n * Unlike flow, pipe immediately executes the functions with the provided initial value.\n *\n * @example\n * // Basic usage\n * const result = pipe(\n * 5,\n * (n) => n * 2, // 10\n * (n) => n + 1, // 11\n * (n) => n.toString() // \"11\"\n * );\n * // result: \"11\"\n *\n * @example\n * // With Option\n * import { some, mapOption } from \"@railway-ts/pipelines/option\";\n *\n * const optionResult = pipe(\n * some(5),\n * (o) => mapOption(o, (n) => n * 2),\n * (o) => mapOption(o, (n) => n.toString())\n * );\n * // optionResult: Option<string> containing \"10\"\n *\n * @example\n * // With Result\n * import { ok, mapResult } from \"@railway-ts/pipelines/result\";\n *\n * const resultValue = pipe(\n * ok(5),\n * (r) => mapResult(r, (n) => n * 2),\n * (r) => mapResult(r, (n) => n.toString())\n * );\n * // resultValue: Result<string, never> containing \"10\"\n *\n * @param a - The initial value to pipe through the functions\n * @param ab - The first function to apply to the initial value\n * @param functions - Additional functions to apply in sequence\n * @returns The final result after applying all functions\n */\n\nexport function pipe<A, B>(a: A, ab: (this: void, a: A) => B): B;\nexport function pipe<A, B, C>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C): C;\nexport function pipe<A, B, C, D>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n): D;\nexport function pipe<A, B, C, D, E>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n): E;\nexport function pipe<A, B, C, D, E, F>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n): F;\nexport function pipe<A, B, C, D, E, F, G>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n): G;\nexport function pipe<A, B, C, D, E, F, G, H>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n): H;\nexport function pipe<A, B, C, D, E, F, G, H, I>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n): I;\nexport function pipe<A, B, C, D, E, F, G, H, I, J>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n ij: (this: void, i: I) => J,\n): J;\nexport function pipe(value: unknown, ...fns: UnknownFunction[]): unknown {\n let result = value;\n for (const fn of fns) {\n result = fn(result);\n }\n return result;\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Creates a new function that is the composition of the provided functions, applied from left to right.\n * Unlike pipe, flow doesn't immediately execute the functions but returns a new function that,\n * when called, will run the composed functions in sequence.\n *\n * @example\n * // Basic usage\n * const processNumber = flow(\n * (n: number) => n * 2,\n * (n) => n + 1,\n * (n) => n.toString()\n * );\n *\n * const result = processNumber(5); // \"11\"\n *\n * @example\n * // With multiple arguments\n * const formatName = flow(\n * (first: string, last: string) => `${first} ${last}`,\n * (name) => name.toUpperCase()\n * );\n *\n * const name = formatName(\"John\", \"Doe\"); // \"JOHN DOE\"\n *\n * @example\n * // With Option type\n * import { some, none, mapOption, flatMapOption, type Option } from \"@railway-ts/pipelines/option\";\n *\n * const safeParseInt = (radix: number) => (str: string): Option<number> => {\n * const n = Number.parseInt(str, radix);\n * return Number.isNaN(n) ? none() : some(n);\n * };\n *\n * const processString = flow(\n * (s: string) => some(s),\n * (o) => mapOption(o, (s) => s + \"0\"),\n * (o) => flatMapOption(o, safeParseInt(10))\n * );\n *\n * const option = processString(\"42\"); // Option<number> containing 420\n *\n * @example\n * // With Result type\n * import { ok, err, flatMapResult } from \"@railway-ts/pipelines/result\";\n *\n * const validatePositive = (n: number) => (n > 0 ? ok(n) : err(\"Not positive\"));\n *\n * const validateNumber = flow(\n * (n: number) => ok(n),\n * (r) => flatMapResult(r, validatePositive),\n * (r) => flatMapResult(r, (n) => ok(n * 2))\n * );\n *\n * const result = validateNumber(5); // Result<number, string> containing 10\n *\n * @param ab - The first function in the composition\n * @param functions - Additional functions to compose in sequence\n * @returns A new function that applies all the composed functions in sequence\n */\nexport function flow<A extends unknown[], B>(ab: (this: void, ...a: A) => B): (...a: A) => B;\nexport function flow<A extends unknown[], B, C>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n): (...a: A) => C;\nexport function flow<A extends unknown[], B, C, D>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n): (...a: A) => D;\nexport function flow<A extends unknown[], B, C, D, E>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n): (...a: A) => E;\nexport function flow<A extends unknown[], B, C, D, E, F>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n): (...a: A) => F;\nexport function flow<A extends unknown[], B, C, D, E, F, G>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n): (...a: A) => G;\nexport function flow<A extends unknown[], B, C, D, E, F, G, H>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n): (...a: A) => H;\nexport function flow<A extends unknown[], B, C, D, E, F, G, H, I>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n): (...a: A) => I;\nexport function flow<A extends unknown[], B, C, D, E, F, G, H, I, J>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n ij: (this: void, i: I) => J,\n): (...a: A) => J;\nexport function flow<A extends unknown[], B, C, D, E, F, G, H, I, J, K>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n ij: (this: void, i: I) => J,\n jk: (this: void, j: J) => K,\n): (...a: A) => K;\nexport function flow(...fns: [UnknownFunction, ...UnknownFunction[]]): UnknownFunction {\n if (fns.length === 1) {\n return fns[0];\n }\n\n const [first, ...rest] = fns;\n return (...args: unknown[]): unknown => {\n let result = first(...args);\n for (const fn of rest) {\n result = fn(result);\n }\n return result;\n };\n}\n","import type { MaybeAsync, UnknownFunction } from './types';\n\n/**\n * Pipes a value through a series of potentially async functions, from left to right.\n * Each function receives the awaited output of the previous function.\n * Unlike pipe, pipeAsync awaits between each step, enabling async composition.\n *\n * @example\n * // Basic async usage\n * const result = await pipeAsync(\n * 5,\n * async (n) => n * 2, // 10\n * (n) => n + 1, // 11\n * async (n) => n.toString() // \"11\"\n * );\n * // result: \"11\"\n *\n * @example\n * // With Result and curried helpers\n * import { ok, flatMapWith, mapWith } from \"@railway-ts/pipelines/result\";\n *\n * const result = await pipeAsync(\n * ok(5),\n * flatMapWith(async (n) => ok(n * 2)),\n * mapWith((n) => n.toString())\n * );\n * // result: Result<string, never> containing \"10\"\n *\n * @param a - The initial value (or Promise) to pipe through the functions\n * @param ab - The first function to apply to the initial value\n * @param functions - Additional functions to apply in sequence\n * @returns A Promise of the final result after applying all functions\n */\n\nexport function pipeAsync<A, B>(a: MaybeAsync<A>, ab: (this: void, a: A) => MaybeAsync<B>): Promise<B>;\nexport function pipeAsync<A, B, C>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n): Promise<C>;\nexport function pipeAsync<A, B, C, D>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n): Promise<D>;\nexport function pipeAsync<A, B, C, D, E>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n): Promise<E>;\nexport function pipeAsync<A, B, C, D, E, F>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n): Promise<F>;\nexport function pipeAsync<A, B, C, D, E, F, G>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n): Promise<G>;\nexport function pipeAsync<A, B, C, D, E, F, G, H>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n): Promise<H>;\nexport function pipeAsync<A, B, C, D, E, F, G, H, I>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n): Promise<I>;\nexport function pipeAsync<A, B, C, D, E, F, G, H, I, J>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n ij: (this: void, i: I) => MaybeAsync<J>,\n): Promise<J>;\nexport async function pipeAsync(a: unknown, ...fns: UnknownFunction[]): Promise<unknown> {\n let result = await a;\n for (const fn of fns) {\n result = await fn(result);\n }\n return result;\n}\n","import type { MaybeAsync, UnknownFunction } from './types';\n\n/**\n * Creates a new function that is the async composition of the provided functions, applied from left to right.\n * Unlike flow, flowAsync awaits between each step, enabling async composition.\n * The returned function always returns a Promise.\n *\n * @example\n * // Basic async usage\n * const processNumber = flowAsync(\n * async (n: number) => n * 2,\n * (n) => n + 1,\n * async (n) => n.toString()\n * );\n *\n * const result = await processNumber(5); // \"11\"\n *\n * @example\n * // With Result and curried helpers\n * import { ok, flatMapWith, mapWith } from \"@railway-ts/pipelines/result\";\n *\n * const process = flowAsync(\n * (n: number) => ok(n),\n * flatMapWith(async (n) => ok(n * 2)),\n * mapWith((n) => n.toString())\n * );\n *\n * const result = await process(5); // Result<string, never> containing \"10\"\n *\n * @param ab - The first function in the composition\n * @param functions - Additional functions to compose in sequence\n * @returns A new function that applies all the composed functions in sequence, returning a Promise\n */\nexport function flowAsync<A extends unknown[], B>(ab: (this: void, ...a: A) => MaybeAsync<B>): (...a: A) => Promise<B>;\nexport function flowAsync<A extends unknown[], B, C>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n): (...a: A) => Promise<C>;\nexport function flowAsync<A extends unknown[], B, C, D>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n): (...a: A) => Promise<D>;\nexport function flowAsync<A extends unknown[], B, C, D, E>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n): (...a: A) => Promise<E>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n): (...a: A) => Promise<F>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n): (...a: A) => Promise<G>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G, H>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n): (...a: A) => Promise<H>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G, H, I>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n): (...a: A) => Promise<I>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G, H, I, J>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n ij: (this: void, i: I) => MaybeAsync<J>,\n): (...a: A) => Promise<J>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G, H, I, J, K>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n ij: (this: void, i: I) => MaybeAsync<J>,\n jk: (this: void, j: J) => MaybeAsync<K>,\n): (...a: A) => Promise<K>;\nexport function flowAsync(\n first: (...args: unknown[]) => unknown,\n ...fns: UnknownFunction[]\n): (...args: unknown[]) => Promise<unknown> {\n return async (...args: unknown[]) => {\n let result = await first(...args);\n for (const fn of fns) {\n result = await fn(result);\n }\n return result;\n };\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Curries a multi-parameter function into a sequence of unary functions.\n * Enables partial application at any depth and composes cleanly with `pipe`.\n *\n * Note: This curry is unary-only at each step to ensure compatibility with `pipe` and `flow`.\n *\n * @example\n * // Basic (2-arity)\n * const add = (a: number, b: number) => a + b;\n * const add5 = curry(add)(5);\n * add5(3); // 8\n *\n * @example\n * // 3-arity and partial application\n * const multiply = (a: number, b: number, c: number) => a * b * c;\n * const curriedMultiply = curry(multiply);\n * curriedMultiply(2)(3)(4); // 24\n *\n * @example\n * // With pipe\n * import { pipe } from \"@/utils\";\n * const divide = (divisor: number, dividend: number) => dividend / divisor;\n * const result = pipe(100, curry(divide)(2), (n) => n + 1); // 51\n *\n * @example\n * // With Result validators\n * import { ok, err, flatMap, type Result } from \"@/result\";\n * const between = (min: number, max: number, n: number): Result<number, string> =>\n * n >= min && n <= max ? ok(n) : err(`Value must be between ${min} and ${max}`);\n * const validateAge = curry(between)(0)(120);\n * pipe(ok(25), (r) => flatMap(r, validateAge)); // ok(25)\n *\n * @param fn - The multi-argument function to transform into a unary curried chain\n * @returns A curried function that takes one argument at each application step\n */\n\n// 2-arity\nexport function curry<A, B, R>(fn: (a: A, b: B) => R): (a: A) => (b: B) => R;\n\n// 3-arity\nexport function curry<A, B, C, R>(fn: (a: A, b: B, c: C) => R): (a: A) => (b: B) => (c: C) => R;\n\n// 4-arity\nexport function curry<A, B, C, D, R>(fn: (a: A, b: B, c: C, d: D) => R): (a: A) => (b: B) => (c: C) => (d: D) => R;\n\n// 5-arity\nexport function curry<A, B, C, D, E, R>(\n fn: (a: A, b: B, c: C, d: D, e: E) => R,\n): (a: A) => (b: B) => (c: C) => (d: D) => (e: E) => R;\n\n// Implementation\nexport function curry<T extends UnknownFunction>(fn: T): UnknownFunction {\n const arity = fn.length;\n\n return function curried(...args: unknown[]): unknown {\n if (args.length >= arity) {\n return (fn as UnknownFunction)(...args);\n }\n\n return function (...nextArgs: unknown[]): unknown {\n return curried(...args, ...nextArgs);\n };\n };\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Uncurries a curried unary function chain back into a multi-argument function.\n * Inverse of `curry`. Useful when calling curried APIs with positional arguments.\n *\n * Note: Expects strictly unary nesting (the shape produced by `curry`).\n *\n * @example\n * // 2-arity\n * const addCurried = (a: number) => (b: number) => a + b;\n * const add = uncurry(addCurried);\n * add(5, 3); // 8\n *\n * @example\n * // 3-arity\n * const multiplyCurried = (a: number) => (b: number) => (c: number) => a * b * c;\n * const multiply = uncurry(multiplyCurried);\n * multiply(2, 3, 4); // 24\n *\n * @example\n * // Round-trip with curry\n * import { curry } from \"@railway-ts/pipelines\";\n * const divide = (divisor: number, dividend: number) => dividend / divisor;\n * const divideCurried = curry(divide);\n * const divideUncurried = uncurry(divideCurried);\n * divideUncurried(2, 100); // 50\n *\n * @param fn - A curried unary function chain (e.g., a => b => c => r)\n * @returns A multi-argument function equivalent to applying the curried chain in sequence\n */\n\n// Overloads ordered from most specific (5-arity) to least specific (2-arity)\n// This ensures TypeScript matches the correct overload\n\n// 5-arity\nexport function uncurry<A, B, C, D, E, R>(\n fn: (a: A) => (b: B) => (c: C) => (d: D) => (e: E) => R,\n): (a: A, b: B, c: C, d: D, e: E) => R;\n\n// 5-arity\nexport function uncurry<A, B, C, D, E, R>(\n fn: (a: A) => (b: B) => (c: C) => (d: D) => (e: E) => R,\n): (a: A, b: B, c: C, d: D, e: E) => R;\n\n// 4-arity\nexport function uncurry<A, B, C, D, R>(fn: (a: A) => (b: B) => (c: C) => (d: D) => R): (a: A, b: B, c: C, d: D) => R;\n\n// 3-arity\nexport function uncurry<A, B, C, R>(fn: (a: A) => (b: B) => (c: C) => R): (a: A, b: B, c: C) => R;\n\n// 2-arity\nexport function uncurry<A, B, R>(fn: (a: A) => (b: B) => R): (a: A, b: B) => R;\n\n// 1-arity (identity - technically not curried, but allows for consistent API)\nexport function uncurry<A, R>(fn: (a: A) => R): (a: A) => R;\n\n// Implementation - looser types allow overloads to work correctly\nexport function uncurry(fn: unknown): unknown {\n return function uncurried(...args: unknown[]): unknown {\n // Apply arguments sequentially to the curried function chain\n let result = fn;\n\n for (const arg of args) {\n result = (result as UnknownFunction)(arg);\n }\n\n return result;\n };\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Transforms a multi-argument function into one that accepts a single tuple argument.\n * This makes multi-arg functions composable in `pipe`/`flow` when your data is a tuple.\n *\n * @example\n * // Basic\n * const add = (a: number, b: number) => a + b;\n * const tupledAdd = tupled(add);\n * tupledAdd([5, 3]); // 8\n *\n * @example\n * // With pipe (tuple input)\n * import { pipe } from \"@/utils\";\n * const distance = (x: number, y: number) => Math.hypot(x, y);\n * pipe([3, 4] as [number, number], tupled(distance)); // 5\n *\n * @example\n * // With Result\n * import { ok, err, flatMapResult, mapResult, type Result } from \"@railway-ts/pipelines/result\";\n * const divide = (dividend: number, divisor: number): Result<number, string> =>\n * divisor === 0 ? err(\"Division by zero\") : ok(dividend / divisor);\n * const tupledDivide = tupled(divide);\n * pipe(ok<[number, number], string>([10, 2]),\n * (r) => flatMapResult(r, tupledDivide),\n * (r) => mapResult(r, (n) => n * 2)\n * ); // ok(10)\n *\n * @example\n * // With Option\n * import { some, none, flatMapOption, type Option } from \"@railway-ts/pipelines/option\";\n * const safeParse = (str: string, radix: number): Option<number> => {\n * const n = Number.parseInt(str, radix);\n * return Number.isNaN(n) ? none() : some(n);\n * };\n * const tupledParse = tupled(safeParse);\n * flatMapOption(some([\"FF\", 16] as [string, number]), tupledParse); // some(255)\n *\n * @param fn - A function taking positional arguments to be adapted to a single tuple argument\n * @returns A function that takes a tuple and applies it to `fn` as positional args\n */\n\n// 2-arity\nexport function tupled<A, B, R>(fn: (a: A, b: B) => R): (args: [A, B]) => R;\n\n// 3-arity\nexport function tupled<A, B, C, R>(fn: (a: A, b: B, c: C) => R): (args: [A, B, C]) => R;\n\n// 4-arity\nexport function tupled<A, B, C, D, R>(fn: (a: A, b: B, c: C, d: D) => R): (args: [A, B, C, D]) => R;\n\n// 5-arity\nexport function tupled<A, B, C, D, E, R>(fn: (a: A, b: B, c: C, d: D, e: E) => R): (args: [A, B, C, D, E]) => R;\n\n// Implementation\nexport function tupled<T extends UnknownFunction>(fn: T): (args: unknown[]) => unknown {\n return function tupledFn(args: unknown[]): unknown {\n return fn(...args);\n };\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Transforms a function that accepts a tuple into a multi-argument function.\n * Inverse of `tupled`. Useful when callers have positional arguments but your core API uses tuples.\n *\n * @example\n * // Basic\n * const tupledAdd = ([a, b]: [number, number]) => a + b;\n * const add = untupled(tupledAdd);\n * add(5, 3); // 8\n *\n * @example\n * // 3-arity\n * const sum3Tupled = ([a, b, c]: [number, number, number]) => a + b + c;\n * const sum3 = untupled(sum3Tupled);\n * sum3(1, 2, 3); // 6\n *\n * @example\n * // With Result\n * import { ok, err, flatMapResult, type Result } from \"@railway-ts/pipelines/result\";\n * const validateRange = ([min, max, value]: [number, number, number]): Result<number, string> =>\n * value >= min && value <= max ? ok(value) : err(`Value ${value} not between ${min} and ${max}`);\n * const validate = untupled(validateRange);\n * flatMapResult(ok(50), (n) => validate(0, 100, n)); // ok(50)\n *\n * @example\n * // With Option\n * import { some, none, type Option } from \"@railway-ts/pipelines/option\";\n * const parsePair = ([x, y]: [string, string]): Option<number> => {\n * const a = Number(x), b = Number(y);\n * return Number.isNaN(a) || Number.isNaN(b) ? none() : some(a + b);\n * };\n * const parse = untupled(parsePair);\n * parse(\"2\", \"3\"); // some(5)\n *\n * @param fn - A function that accepts a tuple of arguments\n * @returns A function that accepts the same arguments positionally\n */\n\n// 2-arity\nexport function untupled<A, B, R>(fn: (args: [A, B]) => R): (a: A, b: B) => R;\n\n// 3-arity\nexport function untupled<A, B, C, R>(fn: (args: [A, B, C]) => R): (a: A, b: B, c: C) => R;\n\n// 4-arity\nexport function untupled<A, B, C, D, R>(fn: (args: [A, B, C, D]) => R): (a: A, b: B, c: C, d: D) => R;\n\n// 5-arity\nexport function untupled<A, B, C, D, E, R>(fn: (args: [A, B, C, D, E]) => R): (a: A, b: B, c: C, d: D, e: E) => R;\n\n// Implementation\nexport function untupled<T extends UnknownFunction>(fn: T): UnknownFunction {\n return function untupledFn(...args: unknown[]): unknown {\n return fn(args);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/composition/pipe.ts","../../src/composition/flow.ts","../../src/composition/pipe-async.ts","../../src/composition/flow-async.ts","../../src/composition/curry.ts","../../src/composition/uncurry.ts","../../src/composition/tupled.ts","../../src/composition/untupled.ts"],"sourcesContent":["import type { UnknownFunction } from './types';\n\n/**\n * Pipes a value through a series of functions, from left to right.\n * Each function receives the output of the previous function.\n * Unlike flow, pipe immediately executes the functions with the provided initial value.\n *\n * @example\n * // Basic usage\n * const result = pipe(\n * 5,\n * (n) => n * 2, // 10\n * (n) => n + 1, // 11\n * (n) => n.toString() // \"11\"\n * );\n * // result: \"11\"\n *\n * @example\n * // With Option\n * import { some, mapOption } from \"@railway-ts/pipelines/option\";\n *\n * const optionResult = pipe(\n * some(5),\n * (o) => mapOption(o, (n) => n * 2),\n * (o) => mapOption(o, (n) => n.toString())\n * );\n * // optionResult: Option<string> containing \"10\"\n *\n * @example\n * // With Result\n * import { ok, mapResult } from \"@railway-ts/pipelines/result\";\n *\n * const resultValue = pipe(\n * ok(5),\n * (r) => mapResult(r, (n) => n * 2),\n * (r) => mapResult(r, (n) => n.toString())\n * );\n * // resultValue: Result<string, never> containing \"10\"\n *\n * @param a - The initial value to pipe through the functions\n * @param ab - The first function to apply to the initial value\n * @param functions - Additional functions to apply in sequence\n * @returns The final result after applying all functions\n */\n\nexport function pipe<A, B>(a: A, ab: (this: void, a: A) => B): B;\nexport function pipe<A, B, C>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C): C;\nexport function pipe<A, B, C, D>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n): D;\nexport function pipe<A, B, C, D, E>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n): E;\nexport function pipe<A, B, C, D, E, F>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n): F;\nexport function pipe<A, B, C, D, E, F, G>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n): G;\nexport function pipe<A, B, C, D, E, F, G, H>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n): H;\nexport function pipe<A, B, C, D, E, F, G, H, I>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n): I;\nexport function pipe<A, B, C, D, E, F, G, H, I, J>(\n a: A,\n ab: (this: void, a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n ij: (this: void, i: I) => J,\n): J;\nexport function pipe(value: unknown, ...fns: UnknownFunction[]): unknown {\n let result = value;\n for (const fn of fns) {\n result = fn(result);\n }\n return result;\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Creates a new function that is the composition of the provided functions, applied from left to right.\n * Unlike pipe, flow doesn't immediately execute the functions but returns a new function that,\n * when called, will run the composed functions in sequence.\n *\n * @example\n * // Basic usage\n * const processNumber = flow(\n * (n: number) => n * 2,\n * (n) => n + 1,\n * (n) => n.toString()\n * );\n *\n * const result = processNumber(5); // \"11\"\n *\n * @example\n * // With multiple arguments\n * const formatName = flow(\n * (first: string, last: string) => `${first} ${last}`,\n * (name) => name.toUpperCase()\n * );\n *\n * const name = formatName(\"John\", \"Doe\"); // \"JOHN DOE\"\n *\n * @example\n * // With Option type\n * import { some, none, mapOption, flatMapOption, type Option } from \"@railway-ts/pipelines/option\";\n *\n * const safeParseInt = (radix: number) => (str: string): Option<number> => {\n * const n = Number.parseInt(str, radix);\n * return Number.isNaN(n) ? none() : some(n);\n * };\n *\n * const processString = flow(\n * (s: string) => some(s),\n * (o) => mapOption(o, (s) => s + \"0\"),\n * (o) => flatMapOption(o, safeParseInt(10))\n * );\n *\n * const option = processString(\"42\"); // Option<number> containing 420\n *\n * @example\n * // With Result type\n * import { ok, err, flatMapResult } from \"@railway-ts/pipelines/result\";\n *\n * const validatePositive = (n: number) => (n > 0 ? ok(n) : err(\"Not positive\"));\n *\n * const validateNumber = flow(\n * (n: number) => ok(n),\n * (r) => flatMapResult(r, validatePositive),\n * (r) => flatMapResult(r, (n) => ok(n * 2))\n * );\n *\n * const result = validateNumber(5); // Result<number, string> containing 10\n *\n * @param ab - The first function in the composition\n * @param functions - Additional functions to compose in sequence\n * @returns A new function that applies all the composed functions in sequence\n */\nexport function flow<A extends unknown[], B>(ab: (this: void, ...a: A) => B): (...a: A) => B;\nexport function flow<A extends unknown[], B, C>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n): (...a: A) => C;\nexport function flow<A extends unknown[], B, C, D>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n): (...a: A) => D;\nexport function flow<A extends unknown[], B, C, D, E>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n): (...a: A) => E;\nexport function flow<A extends unknown[], B, C, D, E, F>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n): (...a: A) => F;\nexport function flow<A extends unknown[], B, C, D, E, F, G>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n): (...a: A) => G;\nexport function flow<A extends unknown[], B, C, D, E, F, G, H>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n): (...a: A) => H;\nexport function flow<A extends unknown[], B, C, D, E, F, G, H, I>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n): (...a: A) => I;\nexport function flow<A extends unknown[], B, C, D, E, F, G, H, I, J>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n ij: (this: void, i: I) => J,\n): (...a: A) => J;\nexport function flow<A extends unknown[], B, C, D, E, F, G, H, I, J, K>(\n ab: (this: void, ...a: A) => B,\n bc: (this: void, b: B) => C,\n cd: (this: void, c: C) => D,\n de: (this: void, d: D) => E,\n ef: (this: void, e: E) => F,\n fg: (this: void, f: F) => G,\n gh: (this: void, g: G) => H,\n hi: (this: void, h: H) => I,\n ij: (this: void, i: I) => J,\n jk: (this: void, j: J) => K,\n): (...a: A) => K;\nexport function flow(...fns: [UnknownFunction, ...UnknownFunction[]]): UnknownFunction {\n if (fns.length === 1) {\n return fns[0];\n }\n\n const [first, ...rest] = fns;\n return (...args: unknown[]): unknown => {\n let result = first(...args);\n for (const fn of rest) {\n result = fn(result);\n }\n return result;\n };\n}\n","import type { MaybeAsync, UnknownFunction } from './types';\n\n/**\n * Pipes a value through a series of potentially async functions, from left to right.\n * Each function receives the awaited output of the previous function.\n * Unlike pipe, pipeAsync awaits between each step, enabling async composition.\n *\n * @example\n * // Basic async usage\n * const result = await pipeAsync(\n * 5,\n * async (n) => n * 2, // 10\n * (n) => n + 1, // 11\n * async (n) => n.toString() // \"11\"\n * );\n * // result: \"11\"\n *\n * @example\n * // With Result and curried helpers\n * import { ok, flatMapWith, mapWith } from \"@railway-ts/pipelines/result\";\n *\n * const result = await pipeAsync(\n * ok(5),\n * flatMapWith(async (n) => ok(n * 2)),\n * mapWith((n) => n.toString())\n * );\n * // result: Result<string, never> containing \"10\"\n *\n * @param a - The initial value (or Promise) to pipe through the functions\n * @param ab - The first function to apply to the initial value\n * @param functions - Additional functions to apply in sequence\n * @returns A Promise of the final result after applying all functions\n */\n\nexport function pipeAsync<A, B>(a: MaybeAsync<A>, ab: (this: void, a: A) => MaybeAsync<B>): Promise<B>;\nexport function pipeAsync<A, B, C>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n): Promise<C>;\nexport function pipeAsync<A, B, C, D>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n): Promise<D>;\nexport function pipeAsync<A, B, C, D, E>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n): Promise<E>;\nexport function pipeAsync<A, B, C, D, E, F>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n): Promise<F>;\nexport function pipeAsync<A, B, C, D, E, F, G>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n): Promise<G>;\nexport function pipeAsync<A, B, C, D, E, F, G, H>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n): Promise<H>;\nexport function pipeAsync<A, B, C, D, E, F, G, H, I>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n): Promise<I>;\nexport function pipeAsync<A, B, C, D, E, F, G, H, I, J>(\n a: MaybeAsync<A>,\n ab: (this: void, a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n ij: (this: void, i: I) => MaybeAsync<J>,\n): Promise<J>;\nexport async function pipeAsync(a: unknown, ...fns: UnknownFunction[]): Promise<unknown> {\n let result = await a;\n for (const fn of fns) {\n result = await fn(result);\n }\n return result;\n}\n","import type { MaybeAsync, UnknownFunction } from './types';\n\n/**\n * Creates a new function that is the async composition of the provided functions, applied from left to right.\n * Unlike flow, flowAsync awaits between each step, enabling async composition.\n * The returned function always returns a Promise.\n *\n * @example\n * // Basic async usage\n * const processNumber = flowAsync(\n * async (n: number) => n * 2,\n * (n) => n + 1,\n * async (n) => n.toString()\n * );\n *\n * const result = await processNumber(5); // \"11\"\n *\n * @example\n * // With Result and curried helpers\n * import { ok, flatMapWith, mapWith } from \"@railway-ts/pipelines/result\";\n *\n * const process = flowAsync(\n * (n: number) => ok(n),\n * flatMapWith(async (n) => ok(n * 2)),\n * mapWith((n) => n.toString())\n * );\n *\n * const result = await process(5); // Result<string, never> containing \"10\"\n *\n * @param ab - The first function in the composition\n * @param functions - Additional functions to compose in sequence\n * @returns A new function that applies all the composed functions in sequence, returning a Promise\n */\nexport function flowAsync<A extends unknown[], B>(ab: (this: void, ...a: A) => MaybeAsync<B>): (...a: A) => Promise<B>;\nexport function flowAsync<A extends unknown[], B, C>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n): (...a: A) => Promise<C>;\nexport function flowAsync<A extends unknown[], B, C, D>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n): (...a: A) => Promise<D>;\nexport function flowAsync<A extends unknown[], B, C, D, E>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n): (...a: A) => Promise<E>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n): (...a: A) => Promise<F>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n): (...a: A) => Promise<G>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G, H>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n): (...a: A) => Promise<H>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G, H, I>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n): (...a: A) => Promise<I>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G, H, I, J>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n ij: (this: void, i: I) => MaybeAsync<J>,\n): (...a: A) => Promise<J>;\nexport function flowAsync<A extends unknown[], B, C, D, E, F, G, H, I, J, K>(\n ab: (this: void, ...a: A) => MaybeAsync<B>,\n bc: (this: void, b: B) => MaybeAsync<C>,\n cd: (this: void, c: C) => MaybeAsync<D>,\n de: (this: void, d: D) => MaybeAsync<E>,\n ef: (this: void, e: E) => MaybeAsync<F>,\n fg: (this: void, f: F) => MaybeAsync<G>,\n gh: (this: void, g: G) => MaybeAsync<H>,\n hi: (this: void, h: H) => MaybeAsync<I>,\n ij: (this: void, i: I) => MaybeAsync<J>,\n jk: (this: void, j: J) => MaybeAsync<K>,\n): (...a: A) => Promise<K>;\nexport function flowAsync(\n first: (...args: unknown[]) => unknown,\n ...fns: UnknownFunction[]\n): (...args: unknown[]) => Promise<unknown> {\n return async (...args: unknown[]) => {\n let result = await first(...args);\n for (const fn of fns) {\n result = await fn(result);\n }\n return result;\n };\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Curries a multi-parameter function into a sequence of unary functions.\n * Enables partial application at any depth and composes cleanly with `pipe`.\n *\n * Note: This curry is unary-only at each step to ensure compatibility with `pipe` and `flow`.\n *\n * @example\n * // Basic (2-arity)\n * const add = (a: number, b: number) => a + b;\n * const add5 = curry(add)(5);\n * add5(3); // 8\n *\n * @example\n * // 3-arity and partial application\n * const multiply = (a: number, b: number, c: number) => a * b * c;\n * const curriedMultiply = curry(multiply);\n * curriedMultiply(2)(3)(4); // 24\n *\n * @example\n * // With pipe\n * import { pipe } from \"@/utils\";\n * const divide = (divisor: number, dividend: number) => dividend / divisor;\n * const result = pipe(100, curry(divide)(2), (n) => n + 1); // 51\n *\n * @example\n * // With Result validators\n * import { ok, err, flatMap, type Result } from \"@/result\";\n * const between = (min: number, max: number, n: number): Result<number, string> =>\n * n >= min && n <= max ? ok(n) : err(`Value must be between ${min} and ${max}`);\n * const validateAge = curry(between)(0)(120);\n * pipe(ok(25), (r) => flatMap(r, validateAge)); // ok(25)\n *\n * @param fn - The multi-argument function to transform into a unary curried chain\n * @returns A curried function that takes one argument at each application step\n */\n\n// 2-arity\nexport function curry<A, B, R>(fn: (a: A, b: B) => R): (a: A) => (b: B) => R;\n\n// 3-arity\nexport function curry<A, B, C, R>(fn: (a: A, b: B, c: C) => R): (a: A) => (b: B) => (c: C) => R;\n\n// 4-arity\nexport function curry<A, B, C, D, R>(fn: (a: A, b: B, c: C, d: D) => R): (a: A) => (b: B) => (c: C) => (d: D) => R;\n\n// 5-arity\nexport function curry<A, B, C, D, E, R>(\n fn: (a: A, b: B, c: C, d: D, e: E) => R,\n): (a: A) => (b: B) => (c: C) => (d: D) => (e: E) => R;\n\n// Implementation\nexport function curry<T extends UnknownFunction>(fn: T): UnknownFunction {\n const arity = fn.length;\n\n return function curried(...args: unknown[]): unknown {\n if (args.length >= arity) {\n return (fn as UnknownFunction)(...args);\n }\n\n return function (...nextArgs: unknown[]): unknown {\n return curried(...args, ...nextArgs);\n };\n };\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Uncurries a curried unary function chain back into a multi-argument function.\n * Inverse of `curry`. Useful when calling curried APIs with positional arguments.\n *\n * Note: Expects strictly unary nesting (the shape produced by `curry`).\n *\n * @example\n * // 2-arity\n * const addCurried = (a: number) => (b: number) => a + b;\n * const add = uncurry(addCurried);\n * add(5, 3); // 8\n *\n * @example\n * // 3-arity\n * const multiplyCurried = (a: number) => (b: number) => (c: number) => a * b * c;\n * const multiply = uncurry(multiplyCurried);\n * multiply(2, 3, 4); // 24\n *\n * @example\n * // Round-trip with curry\n * import { curry } from \"@railway-ts/pipelines\";\n * const divide = (divisor: number, dividend: number) => dividend / divisor;\n * const divideCurried = curry(divide);\n * const divideUncurried = uncurry(divideCurried);\n * divideUncurried(2, 100); // 50\n *\n * @param fn - A curried unary function chain (e.g., a => b => c => r)\n * @returns A multi-argument function equivalent to applying the curried chain in sequence\n */\n\n// Overloads ordered from most specific (5-arity) to least specific (2-arity)\n// This ensures TypeScript matches the correct overload\n\n// 5-arity\nexport function uncurry<A, B, C, D, E, R>(\n fn: (a: A) => (b: B) => (c: C) => (d: D) => (e: E) => R,\n): (a: A, b: B, c: C, d: D, e: E) => R;\n\n// 5-arity\nexport function uncurry<A, B, C, D, E, R>(\n fn: (a: A) => (b: B) => (c: C) => (d: D) => (e: E) => R,\n): (a: A, b: B, c: C, d: D, e: E) => R;\n\n// 4-arity\nexport function uncurry<A, B, C, D, R>(fn: (a: A) => (b: B) => (c: C) => (d: D) => R): (a: A, b: B, c: C, d: D) => R;\n\n// 3-arity\nexport function uncurry<A, B, C, R>(fn: (a: A) => (b: B) => (c: C) => R): (a: A, b: B, c: C) => R;\n\n// 2-arity\nexport function uncurry<A, B, R>(fn: (a: A) => (b: B) => R): (a: A, b: B) => R;\n\n// 1-arity (identity - technically not curried, but allows for consistent API)\nexport function uncurry<A, R>(fn: (a: A) => R): (a: A) => R;\n\n// Implementation - looser types allow overloads to work correctly\nexport function uncurry(fn: unknown): unknown {\n return function uncurried(...args: unknown[]): unknown {\n // Apply arguments sequentially to the curried function chain\n let result = fn;\n\n for (const arg of args) {\n result = (result as UnknownFunction)(arg);\n }\n\n return result;\n };\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Transforms a multi-argument function into one that accepts a single tuple argument.\n * This makes multi-arg functions composable in `pipe`/`flow` when your data is a tuple.\n *\n * @example\n * // Basic\n * const add = (a: number, b: number) => a + b;\n * const tupledAdd = tupled(add);\n * tupledAdd([5, 3]); // 8\n *\n * @example\n * // With pipe (tuple input)\n * import { pipe } from \"@/utils\";\n * const distance = (x: number, y: number) => Math.hypot(x, y);\n * pipe([3, 4] as [number, number], tupled(distance)); // 5\n *\n * @example\n * // With Result\n * import { ok, err, flatMapResult, mapResult, type Result } from \"@railway-ts/pipelines/result\";\n * const divide = (dividend: number, divisor: number): Result<number, string> =>\n * divisor === 0 ? err(\"Division by zero\") : ok(dividend / divisor);\n * const tupledDivide = tupled(divide);\n * pipe(ok<[number, number], string>([10, 2]),\n * (r) => flatMapResult(r, tupledDivide),\n * (r) => mapResult(r, (n) => n * 2)\n * ); // ok(10)\n *\n * @example\n * // With Option\n * import { some, none, flatMapOption, type Option } from \"@railway-ts/pipelines/option\";\n * const safeParse = (str: string, radix: number): Option<number> => {\n * const n = Number.parseInt(str, radix);\n * return Number.isNaN(n) ? none() : some(n);\n * };\n * const tupledParse = tupled(safeParse);\n * flatMapOption(some([\"FF\", 16] as [string, number]), tupledParse); // some(255)\n *\n * @param fn - A function taking positional arguments to be adapted to a single tuple argument\n * @returns A function that takes a tuple and applies it to `fn` as positional args\n */\n\n// 2-arity\nexport function tupled<A, B, R>(fn: (a: A, b: B) => R): (args: [A, B]) => R;\n\n// 3-arity\nexport function tupled<A, B, C, R>(fn: (a: A, b: B, c: C) => R): (args: [A, B, C]) => R;\n\n// 4-arity\nexport function tupled<A, B, C, D, R>(fn: (a: A, b: B, c: C, d: D) => R): (args: [A, B, C, D]) => R;\n\n// 5-arity\nexport function tupled<A, B, C, D, E, R>(fn: (a: A, b: B, c: C, d: D, e: E) => R): (args: [A, B, C, D, E]) => R;\n\n// Implementation\nexport function tupled<T extends UnknownFunction>(fn: T): (args: unknown[]) => unknown {\n return function tupledFn(args: unknown[]): unknown {\n return fn(...args);\n };\n}\n","import type { UnknownFunction } from './types';\n\n/**\n * Transforms a function that accepts a tuple into a multi-argument function.\n * Inverse of `tupled`. Useful when callers have positional arguments but your core API uses tuples.\n *\n * @example\n * // Basic\n * const tupledAdd = ([a, b]: [number, number]) => a + b;\n * const add = untupled(tupledAdd);\n * add(5, 3); // 8\n *\n * @example\n * // 3-arity\n * const sum3Tupled = ([a, b, c]: [number, number, number]) => a + b + c;\n * const sum3 = untupled(sum3Tupled);\n * sum3(1, 2, 3); // 6\n *\n * @example\n * // With Result\n * import { ok, err, flatMapResult, type Result } from \"@railway-ts/pipelines/result\";\n * const validateRange = ([min, max, value]: [number, number, number]): Result<number, string> =>\n * value >= min && value <= max ? ok(value) : err(`Value ${value} not between ${min} and ${max}`);\n * const validate = untupled(validateRange);\n * flatMapResult(ok(50), (n) => validate(0, 100, n)); // ok(50)\n *\n * @example\n * // With Option\n * import { some, none, type Option } from \"@railway-ts/pipelines/option\";\n * const parsePair = ([x, y]: [string, string]): Option<number> => {\n * const a = Number(x), b = Number(y);\n * return Number.isNaN(a) || Number.isNaN(b) ? none() : some(a + b);\n * };\n * const parse = untupled(parsePair);\n * parse(\"2\", \"3\"); // some(5)\n *\n * @param fn - A function that accepts a tuple of arguments\n * @returns A function that accepts the same arguments positionally\n */\n\n// 2-arity\nexport function untupled<A, B, R>(fn: (args: [A, B]) => R): (a: A, b: B) => R;\n\n// 3-arity\nexport function untupled<A, B, C, R>(fn: (args: [A, B, C]) => R): (a: A, b: B, c: C) => R;\n\n// 4-arity\nexport function untupled<A, B, C, D, R>(fn: (args: [A, B, C, D]) => R): (a: A, b: B, c: C, d: D) => R;\n\n// 5-arity\nexport function untupled<A, B, C, D, E, R>(fn: (args: [A, B, C, D, E]) => R): (a: A, b: B, c: C, d: D, e: E) => R;\n\n// Implementation\nexport function untupled<T extends UnknownFunction>(fn: T): UnknownFunction {\n return function untupledFn(...args: unknown[]): unknown {\n return fn(args);\n };\n}\n"],"mappings":";AA8GA,SAAgB,KAAK,OAAgB,GAAG,KAAiC;CACvE,IAAI,SAAS;CACb,KAAK,MAAM,MAAM,KACf,SAAS,GAAG,MAAM;CAEpB,OAAO;AACT;;ACkBA,SAAgB,KAAK,GAAG,KAA+D;CACrF,IAAI,IAAI,WAAW,GACjB,OAAO,IAAI;CAGb,MAAM,CAAC,OAAO,GAAG,QAAQ;CACzB,QAAQ,GAAG,SAA6B;EACtC,IAAI,SAAS,MAAM,GAAG,IAAI;EAC1B,KAAK,MAAM,MAAM,MACf,SAAS,GAAG,MAAM;EAEpB,OAAO;CACT;AACF;;AC5CA,eAAsB,UAAU,GAAY,GAAG,KAA0C;CACvF,IAAI,SAAS,MAAM;CACnB,KAAK,MAAM,MAAM,KACf,SAAS,MAAM,GAAG,MAAM;CAE1B,OAAO;AACT;;ACHA,SAAgB,UACd,OACA,GAAG,KACuC;CAC1C,OAAO,OAAO,GAAG,SAAoB;EACnC,IAAI,SAAS,MAAM,MAAM,GAAG,IAAI;EAChC,KAAK,MAAM,MAAM,KACf,SAAS,MAAM,GAAG,MAAM;EAE1B,OAAO;CACT;AACF;;AChEA,SAAgB,MAAiC,IAAwB;CACvE,MAAM,QAAQ,GAAG;CAEjB,OAAO,SAAS,QAAQ,GAAG,MAA0B;EACnD,IAAI,KAAK,UAAU,OACjB,OAAQ,GAAuB,GAAG,IAAI;EAGxC,OAAO,SAAU,GAAG,UAA8B;GAChD,OAAO,QAAQ,GAAG,MAAM,GAAG,QAAQ;EACrC;CACF;AACF;;ACPA,SAAgB,QAAQ,IAAsB;CAC5C,OAAO,SAAS,UAAU,GAAG,MAA0B;EAErD,IAAI,SAAS;EAEb,KAAK,MAAM,OAAO,MAChB,SAAU,OAA2B,GAAG;EAG1C,OAAO;CACT;AACF;;ACbA,SAAgB,OAAkC,IAAqC;CACrF,OAAO,SAAS,SAAS,MAA0B;EACjD,OAAO,GAAG,GAAG,IAAI;CACnB;AACF;;ACPA,SAAgB,SAAoC,IAAwB;CAC1E,OAAO,SAAS,WAAW,GAAG,MAA0B;EACtD,OAAO,GAAG,IAAI;CAChB;AACF"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol used to identify Result objects.
|
|
3
|
+
*
|
|
4
|
+
* Not meant to be used directly, but it must stay in the published type
|
|
5
|
+
* declarations: `Result` refers to it, and without it a plain
|
|
6
|
+
* `{ ok: true, value }` object would type-check as a `Result`.
|
|
7
|
+
*
|
|
8
|
+
* `Symbol.for` makes every copy of this module (each entry point, or a second
|
|
9
|
+
* installed copy of the package) share one symbol, so Results compare equal no
|
|
10
|
+
* matter which copy created them.
|
|
11
|
+
*/
|
|
12
|
+
declare const RESULT_BRAND: unique symbol;
|
|
1
13
|
/**
|
|
2
14
|
* Represents a Result type.
|
|
3
15
|
*
|
|
@@ -10,13 +22,13 @@
|
|
|
10
22
|
* @returns A Result containing a value or an error
|
|
11
23
|
*/
|
|
12
24
|
type Result<T, E> = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
readonly ok: true;
|
|
26
|
+
readonly value: T;
|
|
27
|
+
readonly [RESULT_BRAND]: "ok";
|
|
16
28
|
} | {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
readonly ok: false;
|
|
30
|
+
readonly error: E;
|
|
31
|
+
readonly [RESULT_BRAND]: "error";
|
|
20
32
|
};
|
|
21
33
|
/**
|
|
22
34
|
* Creates a Result containing a value.
|
|
@@ -52,9 +64,9 @@ declare function err<E>(error: E): Result<never, E>;
|
|
|
52
64
|
* @returns A type predicate indicating if the result is an Ok variant
|
|
53
65
|
*/
|
|
54
66
|
declare function isOk<T, E>(result: Result<T, E>): result is {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
readonly ok: true;
|
|
68
|
+
readonly value: T;
|
|
69
|
+
readonly [RESULT_BRAND]: "ok";
|
|
58
70
|
};
|
|
59
71
|
/**
|
|
60
72
|
* Type guard that checks if a Result is an Error variant.
|
|
@@ -70,9 +82,9 @@ declare function isOk<T, E>(result: Result<T, E>): result is {
|
|
|
70
82
|
* @returns A type predicate indicating if the result is an Error variant
|
|
71
83
|
*/
|
|
72
84
|
declare function isErr<T, E>(result: Result<T, E>): result is {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
readonly ok: false;
|
|
86
|
+
readonly error: E;
|
|
87
|
+
readonly [RESULT_BRAND]: "error";
|
|
76
88
|
};
|
|
77
89
|
/**
|
|
78
90
|
* Maps the value inside a Result using a transformation function.
|
|
@@ -213,8 +225,8 @@ declare function orElse<T1, E1, T2, E2>(result: Result<T1, E1>, fn: (error: E1)
|
|
|
213
225
|
* @returns The result of calling the appropriate handler function
|
|
214
226
|
*/
|
|
215
227
|
declare function match$1<T, E, R1, R2>(result: Result<T, E>, patterns: {
|
|
216
|
-
|
|
217
|
-
|
|
228
|
+
ok: (value: T) => R1;
|
|
229
|
+
err: (error: E) => R2;
|
|
218
230
|
}): R1 | R2;
|
|
219
231
|
/**
|
|
220
232
|
* Unwraps the value inside a Result, throwing an error if the Result is an error.
|
|
@@ -290,48 +302,10 @@ declare function combine$1<T1, E1, T2, E2, T3, E3>(results: readonly [Result<T1,
|
|
|
290
302
|
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>]): Result<[T1, T2, T3, T4], E1 | E2 | E3 | E4>;
|
|
291
303
|
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>]): Result<[T1, T2, T3, T4, T5], E1 | E2 | E3 | E4 | E5>;
|
|
292
304
|
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>]): Result<[T1, T2, T3, T4, T5, T6], E1 | E2 | E3 | E4 | E5 | E6>;
|
|
293
|
-
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7>(results: readonly [
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
Result<T4, E4>,
|
|
298
|
-
Result<T5, E5>,
|
|
299
|
-
Result<T6, E6>,
|
|
300
|
-
Result<T7, E7>
|
|
301
|
-
]): Result<[T1, T2, T3, T4, T5, T6, T7], E1 | E2 | E3 | E4 | E5 | E6 | E7>;
|
|
302
|
-
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8>(results: readonly [
|
|
303
|
-
Result<T1, E1>,
|
|
304
|
-
Result<T2, E2>,
|
|
305
|
-
Result<T3, E3>,
|
|
306
|
-
Result<T4, E4>,
|
|
307
|
-
Result<T5, E5>,
|
|
308
|
-
Result<T6, E6>,
|
|
309
|
-
Result<T7, E7>,
|
|
310
|
-
Result<T8, E8>
|
|
311
|
-
]): Result<[T1, T2, T3, T4, T5, T6, T7, T8], E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8>;
|
|
312
|
-
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9>(results: readonly [
|
|
313
|
-
Result<T1, E1>,
|
|
314
|
-
Result<T2, E2>,
|
|
315
|
-
Result<T3, E3>,
|
|
316
|
-
Result<T4, E4>,
|
|
317
|
-
Result<T5, E5>,
|
|
318
|
-
Result<T6, E6>,
|
|
319
|
-
Result<T7, E7>,
|
|
320
|
-
Result<T8, E8>,
|
|
321
|
-
Result<T9, E9>
|
|
322
|
-
]): Result<[T1, T2, T3, T4, T5, T6, T7, T8, T9], E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9>;
|
|
323
|
-
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9, T10, E10>(results: readonly [
|
|
324
|
-
Result<T1, E1>,
|
|
325
|
-
Result<T2, E2>,
|
|
326
|
-
Result<T3, E3>,
|
|
327
|
-
Result<T4, E4>,
|
|
328
|
-
Result<T5, E5>,
|
|
329
|
-
Result<T6, E6>,
|
|
330
|
-
Result<T7, E7>,
|
|
331
|
-
Result<T8, E8>,
|
|
332
|
-
Result<T9, E9>,
|
|
333
|
-
Result<T10, E10>
|
|
334
|
-
]): Result<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9 | E10>;
|
|
305
|
+
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>, Result<T7, E7>]): Result<[T1, T2, T3, T4, T5, T6, T7], E1 | E2 | E3 | E4 | E5 | E6 | E7>;
|
|
306
|
+
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>, Result<T7, E7>, Result<T8, E8>]): Result<[T1, T2, T3, T4, T5, T6, T7, T8], E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8>;
|
|
307
|
+
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>, Result<T7, E7>, Result<T8, E8>, Result<T9, E9>]): Result<[T1, T2, T3, T4, T5, T6, T7, T8, T9], E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9>;
|
|
308
|
+
declare function combine$1<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9, T10, E10>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>, Result<T7, E7>, Result<T8, E8>, Result<T9, E9>, Result<T10, E10>]): Result<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9 | E10>;
|
|
335
309
|
declare function combine$1<T, E>(results: readonly Result<T, E>[]): Result<T[], E>;
|
|
336
310
|
/**
|
|
337
311
|
* Combines an array of Results into a single Result containing an array of values.
|
|
@@ -358,48 +332,10 @@ declare function combineAll<T1, E1, T2, E2, T3, E3>(results: readonly [Result<T1
|
|
|
358
332
|
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>]): Result<[T1, T2, T3, T4], (E1 | E2 | E3 | E4)[]>;
|
|
359
333
|
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>]): Result<[T1, T2, T3, T4, T5], (E1 | E2 | E3 | E4 | E5)[]>;
|
|
360
334
|
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>]): Result<[T1, T2, T3, T4, T5, T6], (E1 | E2 | E3 | E4 | E5 | E6)[]>;
|
|
361
|
-
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7>(results: readonly [
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
Result<T4, E4>,
|
|
366
|
-
Result<T5, E5>,
|
|
367
|
-
Result<T6, E6>,
|
|
368
|
-
Result<T7, E7>
|
|
369
|
-
]): Result<[T1, T2, T3, T4, T5, T6, T7], (E1 | E2 | E3 | E4 | E5 | E6 | E7)[]>;
|
|
370
|
-
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8>(results: readonly [
|
|
371
|
-
Result<T1, E1>,
|
|
372
|
-
Result<T2, E2>,
|
|
373
|
-
Result<T3, E3>,
|
|
374
|
-
Result<T4, E4>,
|
|
375
|
-
Result<T5, E5>,
|
|
376
|
-
Result<T6, E6>,
|
|
377
|
-
Result<T7, E7>,
|
|
378
|
-
Result<T8, E8>
|
|
379
|
-
]): Result<[T1, T2, T3, T4, T5, T6, T7, T8], (E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8)[]>;
|
|
380
|
-
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9>(results: readonly [
|
|
381
|
-
Result<T1, E1>,
|
|
382
|
-
Result<T2, E2>,
|
|
383
|
-
Result<T3, E3>,
|
|
384
|
-
Result<T4, E4>,
|
|
385
|
-
Result<T5, E5>,
|
|
386
|
-
Result<T6, E6>,
|
|
387
|
-
Result<T7, E7>,
|
|
388
|
-
Result<T8, E8>,
|
|
389
|
-
Result<T9, E9>
|
|
390
|
-
]): Result<[T1, T2, T3, T4, T5, T6, T7, T8, T9], (E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9)[]>;
|
|
391
|
-
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9, T10, E10>(results: readonly [
|
|
392
|
-
Result<T1, E1>,
|
|
393
|
-
Result<T2, E2>,
|
|
394
|
-
Result<T3, E3>,
|
|
395
|
-
Result<T4, E4>,
|
|
396
|
-
Result<T5, E5>,
|
|
397
|
-
Result<T6, E6>,
|
|
398
|
-
Result<T7, E7>,
|
|
399
|
-
Result<T8, E8>,
|
|
400
|
-
Result<T9, E9>,
|
|
401
|
-
Result<T10, E10>
|
|
402
|
-
]): Result<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], (E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9 | E10)[]>;
|
|
335
|
+
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>, Result<T7, E7>]): Result<[T1, T2, T3, T4, T5, T6, T7], (E1 | E2 | E3 | E4 | E5 | E6 | E7)[]>;
|
|
336
|
+
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>, Result<T7, E7>, Result<T8, E8>]): Result<[T1, T2, T3, T4, T5, T6, T7, T8], (E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8)[]>;
|
|
337
|
+
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>, Result<T7, E7>, Result<T8, E8>, Result<T9, E9>]): Result<[T1, T2, T3, T4, T5, T6, T7, T8, T9], (E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9)[]>;
|
|
338
|
+
declare function combineAll<T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9, T10, E10>(results: readonly [Result<T1, E1>, Result<T2, E2>, Result<T3, E3>, Result<T4, E4>, Result<T5, E5>, Result<T6, E6>, Result<T7, E7>, Result<T8, E8>, Result<T9, E9>, Result<T10, E10>]): Result<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], (E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9 | E10)[]>;
|
|
403
339
|
declare function combineAll<T, E>(results: readonly Result<T, E>[]): Result<T[], E[]>;
|
|
404
340
|
/**
|
|
405
341
|
* Separates an array of Results into successes and failures.
|
|
@@ -412,8 +348,8 @@ declare function combineAll<T, E>(results: readonly Result<T, E>[]): Result<T[],
|
|
|
412
348
|
* // { successes: [1, 3], failures: ['bad', 'worse'] }
|
|
413
349
|
*/
|
|
414
350
|
declare const partition: <T, E>(results: Result<T, E>[]) => {
|
|
415
|
-
|
|
416
|
-
|
|
351
|
+
successes: T[];
|
|
352
|
+
failures: E[];
|
|
417
353
|
};
|
|
418
354
|
/**
|
|
419
355
|
* Converts a Result to an Option.
|
|
@@ -669,7 +605,18 @@ declare function tapErrWith<E>(fn: (error: E) => void): <T>(result: Result<T, E>
|
|
|
669
605
|
* @returns A function that takes a Result and returns either the original Ok or the result of calling fn
|
|
670
606
|
*/
|
|
671
607
|
declare function orElseWith<E1, T2, E2>(fn: (error: E1) => Result<T2, E2>): <T1>(result: Result<T1, E1>) => Result<T1 | T2, E2>;
|
|
672
|
-
|
|
608
|
+
/**
|
|
609
|
+
* Symbol used to identify Option objects.
|
|
610
|
+
*
|
|
611
|
+
* Not meant to be used directly, but it must stay in the published type
|
|
612
|
+
* declarations: `Option` refers to it, and without it a plain
|
|
613
|
+
* `{ some: true, value }` object would type-check as an `Option`.
|
|
614
|
+
*
|
|
615
|
+
* `Symbol.for` makes every copy of this module (each entry point, or a second
|
|
616
|
+
* installed copy of the package) share one symbol, so Options compare equal no
|
|
617
|
+
* matter which copy created them.
|
|
618
|
+
*/
|
|
619
|
+
declare const OPTION_BRAND: unique symbol;
|
|
673
620
|
/**
|
|
674
621
|
* Represents an Option type.
|
|
675
622
|
*
|
|
@@ -681,12 +628,12 @@ declare function orElseWith<E1, T2, E2>(fn: (error: E1) => Result<T2, E2>): <T1>
|
|
|
681
628
|
* @returns An Option containing a value or nothing
|
|
682
629
|
*/
|
|
683
630
|
type Option<T> = {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
631
|
+
readonly some: true;
|
|
632
|
+
readonly value: T;
|
|
633
|
+
readonly [OPTION_BRAND]: "some";
|
|
687
634
|
} | {
|
|
688
|
-
|
|
689
|
-
|
|
635
|
+
readonly some: false;
|
|
636
|
+
readonly [OPTION_BRAND]: "none";
|
|
690
637
|
};
|
|
691
638
|
/**
|
|
692
639
|
* Creates an Option containing a value.
|
|
@@ -719,9 +666,9 @@ declare function none<T = never>(): Option<T>;
|
|
|
719
666
|
* @returns A type predicate indicating if the option is a Some variant
|
|
720
667
|
*/
|
|
721
668
|
declare function isSome<T>(option: Option<T>): option is {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
669
|
+
readonly some: true;
|
|
670
|
+
readonly value: T;
|
|
671
|
+
readonly [OPTION_BRAND]: "some";
|
|
725
672
|
};
|
|
726
673
|
/**
|
|
727
674
|
* Type guard that checks if an Option is a None variant containing no value.
|
|
@@ -737,8 +684,8 @@ declare function isSome<T>(option: Option<T>): option is {
|
|
|
737
684
|
* @returns A type predicate indicating if the option is a None variant
|
|
738
685
|
*/
|
|
739
686
|
declare function isNone<T>(option: Option<T>): option is {
|
|
740
|
-
|
|
741
|
-
|
|
687
|
+
readonly some: false;
|
|
688
|
+
readonly [OPTION_BRAND]: "none";
|
|
742
689
|
};
|
|
743
690
|
/**
|
|
744
691
|
* Maps the value inside an Option using a transformation function.
|
|
@@ -832,8 +779,8 @@ declare function tap<T>(option: Option<T>, fn: (value: T) => void): Option<T>;
|
|
|
832
779
|
* @returns The result of calling the appropriate handler function
|
|
833
780
|
*/
|
|
834
781
|
declare function match<T, R1, R2>(option: Option<T>, patterns: {
|
|
835
|
-
|
|
836
|
-
|
|
782
|
+
some: (value: T) => R1;
|
|
783
|
+
none: () => R2;
|
|
837
784
|
}): R1 | R2;
|
|
838
785
|
/**
|
|
839
786
|
* Unwraps the value inside an Option, throwing an error if the Option is none.
|
|
@@ -898,29 +845,8 @@ declare function combine<T1, T2, T3, T4, T5>(options: readonly [Option<T1>, Opti
|
|
|
898
845
|
declare function combine<T1, T2, T3, T4, T5, T6>(options: readonly [Option<T1>, Option<T2>, Option<T3>, Option<T4>, Option<T5>, Option<T6>]): Option<[T1, T2, T3, T4, T5, T6]>;
|
|
899
846
|
declare function combine<T1, T2, T3, T4, T5, T6, T7>(options: readonly [Option<T1>, Option<T2>, Option<T3>, Option<T4>, Option<T5>, Option<T6>, Option<T7>]): Option<[T1, T2, T3, T4, T5, T6, T7]>;
|
|
900
847
|
declare function combine<T1, T2, T3, T4, T5, T6, T7, T8>(options: readonly [Option<T1>, Option<T2>, Option<T3>, Option<T4>, Option<T5>, Option<T6>, Option<T7>, Option<T8>]): Option<[T1, T2, T3, T4, T5, T6, T7, T8]>;
|
|
901
|
-
declare function combine<T1, T2, T3, T4, T5, T6, T7, T8, T9>(options: readonly [
|
|
902
|
-
|
|
903
|
-
Option<T2>,
|
|
904
|
-
Option<T3>,
|
|
905
|
-
Option<T4>,
|
|
906
|
-
Option<T5>,
|
|
907
|
-
Option<T6>,
|
|
908
|
-
Option<T7>,
|
|
909
|
-
Option<T8>,
|
|
910
|
-
Option<T9>
|
|
911
|
-
]): Option<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
|
|
912
|
-
declare function combine<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(options: readonly [
|
|
913
|
-
Option<T1>,
|
|
914
|
-
Option<T2>,
|
|
915
|
-
Option<T3>,
|
|
916
|
-
Option<T4>,
|
|
917
|
-
Option<T5>,
|
|
918
|
-
Option<T6>,
|
|
919
|
-
Option<T7>,
|
|
920
|
-
Option<T8>,
|
|
921
|
-
Option<T9>,
|
|
922
|
-
Option<T10>
|
|
923
|
-
]): Option<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
|
|
848
|
+
declare function combine<T1, T2, T3, T4, T5, T6, T7, T8, T9>(options: readonly [Option<T1>, Option<T2>, Option<T3>, Option<T4>, Option<T5>, Option<T6>, Option<T7>, Option<T8>, Option<T9>]): Option<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
|
|
849
|
+
declare function combine<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(options: readonly [Option<T1>, Option<T2>, Option<T3>, Option<T4>, Option<T5>, Option<T6>, Option<T7>, Option<T8>, Option<T9>, Option<T10>]): Option<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
|
|
924
850
|
declare function combine<T>(options: readonly Option<T>[]): Option<T[]>;
|
|
925
851
|
/**
|
|
926
852
|
* Creates an Option from a nullable value.
|
|
@@ -1058,6 +984,4 @@ declare function tapWith<T>(fn: (value: T) => void): (option: Option<T>) => Opti
|
|
|
1058
984
|
* @returns A function that takes an Option and returns a Result
|
|
1059
985
|
*/
|
|
1060
986
|
declare function mapToResultWith<E>(error: E): <T>(option: Option<T>) => Result<T, E>;
|
|
1061
|
-
|
|
1062
|
-
export { filterWith as a, bimap as b, bimap$1 as bimap, combine as c, combine$1 as combine, combineAll, flatMap as d, flatMapWith as e, err, filter as f, filter$1 as filter, filterWith$1 as filterWith, flatMap$1 as flatMap, flatMapWith$1 as flatMapWith, fromPromise, fromPromiseWithError, fromTry, fromTryWithError, fromNullable as g, isSome as h, isNone as i, isErr, isOk, mapToResult as j, mapToResultWith as k, mapWith as l, map as m, map$1 as map, mapErr, mapErrWith, mapToOption, mapWith$1 as mapWith, match$1 as match, match as n, none as o, ok, orElse, orElseWith, tapWith as p, partition, unwrapOr as q, unwrapOrElse as r, some as s, tap as t, tap$1 as tap, tapErr, tapErrWith, tapWith$1 as tapWith, toPromise, unwrap as u, unwrap$1 as unwrap, unwrapOr$1 as unwrapOr, unwrapOrElse$1 as unwrapOrElse };
|
|
1063
|
-
export type { Option as O, Result };
|
|
987
|
+
export { tapWith$1 as $, filter$1 as A, map$1 as B, unwrapOrElse as C, combine$1 as D, bimap$1 as E, fromPromiseWithError as F, match$1 as G, mapErrWith as H, fromTry as I, orElseWith as J, ok as K, fromTryWithError as L, flatMap$1 as M, flatMapWith$1 as N, combineAll as O, fromPromise as P, tapErrWith as Q, isErr as R, unwrapOr as S, Result as T, mapToOption as U, mapErr as V, mapWith$1 as W, tap$1 as X, partition as Y, tapErr as Z, none as _, filter as a, tapWith as b, flatMapWith as c, isSome as d, toPromise as et, map as f, match as g, mapWith as h, combine as i, filterWith$1 as j, err as k, fromNullable as l, mapToResultWith as m, Option as n, unwrapOr$1 as nt, filterWith as o, mapToResult as p, orElse as q, bimap as r, unwrapOrElse$1 as rt, flatMap as s, OPTION_BRAND as t, unwrap$1 as tt, isNone as u, some as v, RESULT_BRAND as w, unwrap as x, tap as y, isOk as z };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Option type module - A functional way to handle optional values
|
|
3
|
+
*
|
|
4
|
+
* @module option
|
|
5
|
+
*/
|
|
6
|
+
import { C as unwrapOrElse, S as unwrapOr, _ as none, a as filter, b as tapWith, c as flatMapWith, d as isSome, f as map, g as match, h as mapWith, i as combine, l as fromNullable, m as mapToResultWith, n as Option, o as filterWith, p as mapToResult, r as bimap, s as flatMap, t as OPTION_BRAND, u as isNone, v as some, x as unwrap, y as tap } from "../index-DDkNG41b.mjs";
|
|
7
|
+
export { OPTION_BRAND, Option, bimap, combine, filter, filterWith, flatMap, flatMapWith, fromNullable, isNone, isSome, map, mapToResult, mapToResultWith, mapWith, match, none, some, tap, tapWith, unwrap, unwrapOr, unwrapOrElse };
|
package/dist/option/index.mjs
CHANGED
|
@@ -1,114 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var RESULT_BRAND = /* @__PURE__ */ Symbol("RESULT_BRAND");
|
|
3
|
-
function ok(value) {
|
|
4
|
-
return {
|
|
5
|
-
ok: true,
|
|
6
|
-
value,
|
|
7
|
-
[RESULT_BRAND]: "ok"
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function err(error) {
|
|
11
|
-
return { ok: false, error, [RESULT_BRAND]: "error" };
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// src/option/option.ts
|
|
15
|
-
var OPTION_BRAND = /* @__PURE__ */ Symbol("OPTION_BRAND");
|
|
16
|
-
function some(value) {
|
|
17
|
-
return {
|
|
18
|
-
some: true,
|
|
19
|
-
value,
|
|
20
|
-
[OPTION_BRAND]: "some"
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function none() {
|
|
24
|
-
return {
|
|
25
|
-
some: false,
|
|
26
|
-
[OPTION_BRAND]: "none"
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function isSome(option) {
|
|
30
|
-
return option.some;
|
|
31
|
-
}
|
|
32
|
-
function isNone(option) {
|
|
33
|
-
return !option.some;
|
|
34
|
-
}
|
|
35
|
-
function map(option, fn) {
|
|
36
|
-
return option.some ? some(fn(option.value)) : none();
|
|
37
|
-
}
|
|
38
|
-
function flatMap(option, fn) {
|
|
39
|
-
return option.some ? fn(option.value) : none();
|
|
40
|
-
}
|
|
41
|
-
function bimap(option, someFn, noneFn) {
|
|
42
|
-
return option.some ? someFn(option.value) : noneFn();
|
|
43
|
-
}
|
|
44
|
-
function filter(option, predicate) {
|
|
45
|
-
return option.some && predicate(option.value) ? option : none();
|
|
46
|
-
}
|
|
47
|
-
function tap(option, fn) {
|
|
48
|
-
if (isSome(option)) {
|
|
49
|
-
const callback = fn;
|
|
50
|
-
callback(option.value);
|
|
51
|
-
}
|
|
52
|
-
return option;
|
|
53
|
-
}
|
|
54
|
-
function match(option, patterns) {
|
|
55
|
-
if (isSome(option)) {
|
|
56
|
-
const someFn = patterns.some;
|
|
57
|
-
return someFn(option.value);
|
|
58
|
-
}
|
|
59
|
-
const noneFn = patterns.none;
|
|
60
|
-
return noneFn();
|
|
61
|
-
}
|
|
62
|
-
function unwrap(option, errorMsg) {
|
|
63
|
-
if (option.some) {
|
|
64
|
-
return option.value;
|
|
65
|
-
}
|
|
66
|
-
throw new Error(errorMsg || "Cannot unwrap a none Option");
|
|
67
|
-
}
|
|
68
|
-
function unwrapOr(option, defaultValue) {
|
|
69
|
-
return option.some ? option.value : defaultValue;
|
|
70
|
-
}
|
|
71
|
-
function unwrapOrElse(option, defaultFn) {
|
|
72
|
-
return option.some ? option.value : defaultFn();
|
|
73
|
-
}
|
|
74
|
-
function combine(options) {
|
|
75
|
-
const values = [];
|
|
76
|
-
for (const option of options) {
|
|
77
|
-
if (!option.some) return none();
|
|
78
|
-
values.push(option.value);
|
|
79
|
-
}
|
|
80
|
-
return some(values);
|
|
81
|
-
}
|
|
82
|
-
var fromNullable = (value) => {
|
|
83
|
-
return value === null || value === void 0 ? none() : some(value);
|
|
84
|
-
};
|
|
85
|
-
function mapToResult(option, error) {
|
|
86
|
-
return option.some ? ok(option.value) : err(error);
|
|
87
|
-
}
|
|
88
|
-
function mapWith(fn) {
|
|
89
|
-
return (option) => map(option, fn);
|
|
90
|
-
}
|
|
91
|
-
function flatMapWith(fn) {
|
|
92
|
-
return (option) => {
|
|
93
|
-
if (!option.some) return option;
|
|
94
|
-
return fn(option.value);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function filterWith(predicate) {
|
|
98
|
-
return (option) => filter(option, predicate);
|
|
99
|
-
}
|
|
100
|
-
function tapWith(fn) {
|
|
101
|
-
return (option) => {
|
|
102
|
-
if (!option.some) return option;
|
|
103
|
-
const out = fn(option.value);
|
|
104
|
-
if (out instanceof Promise) return out.then(() => option);
|
|
105
|
-
return option;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
function mapToResultWith(error) {
|
|
109
|
-
return (option) => mapToResult(option, error);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export { OPTION_BRAND, bimap, combine, filter, filterWith, flatMap, flatMapWith, fromNullable, isNone, isSome, map, mapToResult, mapToResultWith, mapWith, match, none, some, tap, tapWith, unwrap, unwrapOr, unwrapOrElse };
|
|
113
|
-
//# sourceMappingURL=index.mjs.map
|
|
114
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export { t as OPTION_BRAND, n as bimap, r as combine, i as filter, a as filterWith, o as flatMap, s as flatMapWith, c as fromNullable, l as isNone, u as isSome, d as map, f as mapToResult, p as mapToResultWith, m as mapWith, h as match, g as none, _ as some, v as tap, y as tapWith, b as unwrap, x as unwrapOr, S as unwrapOrElse } from "../option-BQCaaEBP.mjs";
|