Applies a transformation function to the error value of a Result or ResultAsync. If the input is a Success, it will be returned unchanged.
The input Result or ResultAsync.
The transformed error value type.
import { import Result Result } from '@praha/byethrow';
const const result: Result.Result<never, Error> result = import Result Result .const pipe: <Result.Result<never, "NotFound">, Result.Result<never, Error>>(a: Result.Result<never, "NotFound">, ab: (a: Result.Result<never, "NotFound">) => Result.Result<never, Error>) => Result.Result<never, Error> (+25 overloads) pipe (
import Result Result .const fail: <"NotFound">(error: "NotFound") => Result.Result<never, "NotFound"> (+1 overload) fail ('NotFound'),
import Result Result .const mapError: <Result.Result<never, "NotFound">, Error>(fn: (a: "NotFound") => Error) => (result: Result.Result<never, "NotFound">) => Result.Result<never, Error> (+1 overload) mapError ((error: "NotFound" error ) => new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error (error: "NotFound" error )),
);
// { type: 'Failure', error: Error('NotFound') }import { import Result Result } from '@praha/byethrow';
const const result: Result.Result<123, Error> result = import Result Result .const pipe: <Result.Result<123, never>, Result.Result<123, Error>>(a: Result.Result<123, never>, ab: (a: Result.Result<123, never>) => Result.Result<123, Error>) => Result.Result<123, Error> (+25 overloads) pipe (
import Result Result .const succeed: <123>(value: 123) => Result.Result<123, never> (+1 overload) succeed (123),
import Result Result .const mapError: <Result.Result<123, never>, Error>(fn: (a: never) => Error) => (result: Result.Result<123, never>) => Result.Result<123, Error> (+1 overload) mapError ((error: never error ) => new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error (error: never error )),
);
// { type: 'Success', value: 123 }pipe - It is recommended to use this function with the pipe function for better readability and composability.
mapError<
R1,E2>(fn): (result) =>ResultFor<R1,InferSuccess<R1>,E2>
Defined in: functions/map-error.ts:44
R1 extends ResultMaybeAsync<any, any>
E2
(a) => E2
(
result):ResultFor<R1,InferSuccess<R1>,E2>
R1
ResultFor<R1, InferSuccess<R1>, E2>
mapError<
E1,E2>(fn): <R1>(result) =>ResultFor<R1,InferSuccess<R1>,E2>
Defined in: functions/map-error.ts:45
E1
E2
(a) => E2
<
R1>(result):ResultFor<R1,InferSuccess<R1>,E2>
R1 extends ResultMaybeAsync<any, E1>
R1
ResultFor<R1, InferSuccess<R1>, E2>