Package: effect
Module: Result
Transforms the failure channel of a Result, leaving the success channel unchanged.
When to use
Use to transform only the failure channel while preserving success values.
Details
Failure, applies f to the error and returns a new FailureSuccess, returns it as-isExample (Adding context to an error)
import { pipe, Result } from "effect"
const result = pipe(
Result.fail("not found"),
Result.mapError((e) => `Error: ${e}`)
)
console.log(result)
// Output: { _tag: "Failure", failure: "Error: not found", ... }
See
map to transform only the success valuemapBoth to transform both channelsSignature
declare const mapError: { <E, E2>(f: (err: E) => E2): <A>(self: Result<A, E>) => Result<A, E2>; <A, E, E2>(self: Result<A, E>, f: (err: E) => E2): Result<A, E2>; }
Since v4.0.0