effect-io-ai

Package: effect
Module: Result

Result.mapError

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

Example (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

Signature

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>; }

Source

Since v4.0.0