import { AsyncResult } from "./async_result"; import { type Result } from "./result"; import type { InferErr } from "./util"; /** * Runs 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 Result * const result = tryFn(function* () { * const a = yield* Ok(1) * const random = Math.random() * if (random > 0.5) { * yield* Err("error") * } * return a + random * }) * ``` */ export declare function trySync, U>(fn: () => Generator): Result>; /** * Runs 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 `AsyncResult` or `Result`. * * **Examples** * * ```ts * const okOne = () => new AsyncResult(Promise.resolve(Ok(1))) * * // $ExpectType AsyncResult * const result = tryAsyncFn(async function* () { * const a = yield* okOne() * const random = Math.random() * if (random > 0.5) { * yield* Err("error") * } * return a + random * }) * ``` */ export declare function tryAsync | Result, U>(fn: () => AsyncGenerator): AsyncResult>>;