import type { Result } from "./result"; /** Function that transforms one Result into another */ export type PipeFn = (input: Result) => Result | Promise>; /** Context passed to onEach callback */ export type PipeEachContext = { prevResult: Result; currentFn: string; nextFn: string | undefined; }; /** Options for pipeline execution */ export type PipeRunOptions = { /** Called after each function executes */ onEach?: (ctx: PipeEachContext) => void; /** Called when pipeline completes successfully */ onSuccess?: (value: any) => void; /** Called when pipeline encounters an error (only when allowErrors is false) */ onError?: (error: Error) => void; /** If true, continues pipeline even when a function returns Err */ allowErrors?: boolean; }; /** Pipeline object returned by pipe() */ export type Pipeline = { run: (options?: PipeRunOptions) => Promise>; }; /** * Creates a pipeline for sequential function composition. * Each function receives the previous Result and returns a new Result. * * @param initial - Starting value (plain value, Option, Result, or Atom) * @param fns - Pipeline functions that transform Results * @returns Pipeline object with `.run()` method * * @example * const add = (x: number) => (res: Result) => * res.isOk ? Ok(res.value + x) : res; * * const result = await pipe(5, add(3), add(2)).run(); * // result.value === 10 * * @example * const result = await pipe(option(5), add(3)).run({ * onEach: ({ currentFn, prevResult }) => console.log(currentFn, prevResult), * onSuccess: (value) => console.log("Done:", value), * allowErrors: false, * }); */ export declare function pipe(initial: T, ...fns: PipeFn[]): Pipeline;