UNPKG

@typescript-tea/core

Version:

The Elm Architecture for typescript

30 lines 1.04 kB
/** * @module Result */ /** * A `Result` is either `Ok` meaning the computation succeeded, or it is an * `Err` meaning that there was some failure. */ export declare type Result<TError, TValue> = { readonly type: "Ok"; readonly value: TValue; } | { readonly type: "Err"; readonly error: TError; }; export declare function Ok<TValue>(value: TValue): Result<never, TValue>; export declare function Err<TError>(error: TError): Result<TError, never>; /** * Transform an `Err` value. For example, say the errors we get have too much * information: * parseInt : String -> Result ParseError Int * type alias ParseError = * { message : String * , code : Int * , position : (Int,Int) * } * mapError .message (parseInt "123") == Ok 123 * mapError .message (parseInt "abc") == Err "char 'a' is not a number" */ export declare function mapError<x, y, a>(f: (x: x) => y, result: Result<x, a>): Result<y, a>; //# sourceMappingURL=result.d.ts.map