import type MapFn from "./Map"; import type UnwrapFn from "./Unwrap"; import type { Err, ErrL, IsErrFn, IsOkFn, OfErrFn, OfOkFn, Ok, OkL } from "./core"; import type { Fn1, PartialApply } from "../HKT"; import type { Lazied } from "../helpers"; /** * A type that represents the result of an operation that may fail. */ export type Result = Ok | Err; /** * {@link Lazied} version of {@link Result}. */ export type ResultL = OkL | ErrL; export type { Err, ErrL, Ok, OkL }; /*********** * Methods * ***********/ /** * Methods for `Result`. */ export namespace Result { /** * [Fn] Check if a {@link Result} is {@link Ok}. */ export type IsOk = IsOkFn; /** * [Fn] Check if a {@link Result} is {@link Err}. */ export type IsErr = IsErrFn; /** * [Fn] Apply a function to the value of a {@link Result}. * * Sig: `(f: (x: T) => U) => (r: Result) => Result` */ export type Map = PartialApply; /** * [Fn] Get the inner value of a {@link Result} if it is {@link Ok}, otherwise return `never`. * * Type safety is **not guaranteed**. * * Sig: `(o: Result) => T` */ export type Unwrap = UnwrapFn; } /****************** * Static members * ******************/ /** * [Fn] Wrap a value in an {@link Ok}. * * Sig: `(value: T) => Ok` * * @example * ```typescript * type R = $; * // ^?: Ok<42> * ``` */ export type Result$$OfOk = OfOkFn; /** * [Fn] Wrap a value in an {@link Err}. * * Sig: `(err: E) => Err` * * @example * ```typescript * type R = $; * // ^?: Err<"Something went wrong"> * ``` */ export type Result$$OfErr = OfErrFn; /**************** * Type classes * ****************/