import { Future, Result } from "@bloodyowl/boxed"; import { AsyncResult, Result as Result$1 } from "unthrown"; //#region src/index.d.ts /** * Convert a `Result` into a Boxed `Result`, triaging any Defect. * * @remarks * Boxed's `Result` has no Defect channel, so `onDefect` **must** fold a * `Defect`'s cause into a modeled error `E` (an `Error`). `Ok → Result.Ok`, * `Err → Result.Error`, `Defect → Result.Error(onDefect(cause))`. * * @typeParam T - the success value type. * @typeParam E - the modeled error type. * @param result - the result to convert. * @param onDefect - folds a Defect's unknown cause into a modeled `E`. * * @example * ```ts * import { fromThrowable } from "unthrown"; * import { toBoxed } from "@unthrown/boxed"; * * // Mint a Defect, then convert: it has no home in Boxed's Result, so onDefect folds it into E. * const defective = fromThrowable((): number => { * throw new Error("boom"); * }, (cause, defect) => defect(cause))(); * const boxed = toBoxed(defective, (cause) => `bug: ${String(cause)}`); * boxed.isError(); // => true — the Error carries "bug: Error: boom" * ``` */ export declare function toBoxed(result: Result$1, onDefect: (cause: unknown) => E): Result; /** * Convert a Boxed `Result` into a `Result`. * * @remarks * `Result.Ok → Ok`, `Result.Error → Err`. Boxed's `Result` carries no Defect, so * the result is never a `Defect`. * * @typeParam T - the success value type. * @typeParam E - the modeled error type. * @param result - the Boxed result to convert. * * @example * ```ts * import { Result as BoxedResult } from "@bloodyowl/boxed"; * import { fromBoxed } from "@unthrown/boxed"; * * const result = fromBoxed(BoxedResult.Ok(1)); * result.isOk(); // => true * ``` */ export declare function fromBoxed(result: Result): Result$1; /** * Convert an `AsyncResult` into a Boxed `Future`, triaging any * Defect. * * @remarks * The async counterpart of {@link toBoxed}: `onDefect` is required for the same * reason. The `AsyncResult` is awaited (it never rejects) and its settled * `Result` is converted, then resolved into the `Future`. * * `onDefect` must not throw: Boxed's `Future` has no failure channel, so a * throw is re-raised out-of-band (uncaught) rather than left as a hung * `Future`. * * @typeParam T - the success value type. * @typeParam E - the modeled error type. * @param asyncResult - the async result to convert. * @param onDefect - folds a Defect's unknown cause into a modeled `E`. * * @example * ```ts * import { fromSafePromise } from "unthrown"; * import { toBoxedFuture } from "@unthrown/boxed"; * * // A rejection inside fromSafePromise is a Defect; onDefect folds it into E on the way out. * const defective = fromSafePromise(Promise.reject(new Error("boom"))); * const future = toBoxedFuture(defective, (cause) => `bug: ${String(cause)}`); * (await future.toPromise()).isError(); // => true — the Error carries "bug: Error: boom" * ``` */ export declare function toBoxedFuture(asyncResult: AsyncResult, onDefect: (cause: unknown) => E): Future>; /** * Convert a Boxed `Future` into an `AsyncResult`. * * @remarks * The async counterpart of {@link fromBoxed}. A `Result.Error` inside the future * stays an `Err`. Boxed's `Future` has no failure channel of its own — * `Future.toPromise()` does not reject — so in practice no `Defect` arises here; * the `fromSafePromise` boundary is a defensive net that would only capture one * if a future somehow rejected. The returned `AsyncResult` never throws when * awaited. * * @typeParam T - the success value type. * @typeParam E - the modeled error type. * @param future - the Boxed future to convert. * * @example * ```ts * import { Future, Result as BoxedResult } from "@bloodyowl/boxed"; * import { fromBoxedFuture } from "@unthrown/boxed"; * * const result = await fromBoxedFuture(Future.value(BoxedResult.Ok(1))); * result.isOk(); // => true * ``` */ export declare function fromBoxedFuture(future: Future>): AsyncResult; //#endregion