import { type Result } from "./result"; import { AsyncResult } from "./async_result"; import type { InferErr, InferOk } from "./util"; /** * Wraps a function that returns any shape of `Result` and infers its return type as `Result`. * * **Examples** * * ``` * // (a: number, b: number) => Err | Ok * const divide = (a: number, b: number) => b === 0 ? Err("division by zero") : Ok(a / b) * * // (a: number, b: number) => Result * const wrapped = fn(divide) * ``` */ export declare function fn>(f: (...args: A) => R): (...args: A) => Result, InferErr>; /** * Wraps a function that returns any shape of `Promise>` and wraps the return value in a `AsyncResult`. * * **Examples** * * ``` * // (a: number, b: number) => Promise | Ok> * const divide = async (a: number, b: number) => b === 0 ? Err("division by zero") : Ok(a / b) * * // (a: number, b: number) => AsyncResult * const wrapped = asyncFn(divide) * // now you can do this: * const result = await wrapped(1, 2) // => Result * ``` */ export declare function asyncFn>(f: (...args: A) => R): (...args: A) => AsyncResult>, InferErr>>; export declare function asyncFn>>(f: (...args: A) => R): (...args: A) => AsyncResult>, InferErr>>; /** * Wraps a generator function that returns a `Result` and infers its return type as `Result`. * * `yield*` must be used to yield the result of a `Result`. * * **Examples** * * ```ts * // $ExpectType (arg: number) => Result * const fn = genFn(function* (arg: number) { * const a = yield* Ok(1) * if (Math.random() > 0.5) { * yield* Err("error") * } * return a + arg * }) * ``` */ export declare function gen, T>(fn: (...args: A) => Generator): (...args: A) => Result>; /** * Wraps an async generator function that returns a `Result` and infers its return type as `AsyncResult`. * * `yield*` must be used to yield the result of a `Result`. * * **Examples** * * ```ts * // $ExpectType (arg: number) => AsyncResult * const fn = asyncGenFn(async function* (arg: number) { * const a = yield* Ok(1) * if (Math.random() > 0.5) { * yield* Err("error") * } * return a + arg * }) * ``` */ export declare function asyncGen | Result, T>(fn: (...args: A) => AsyncGenerator): (...args: A) => AsyncResult>>;