effect-io-ai

Package: effect
Module: Cause

Cause.map

Transforms the typed error values inside a Cause using the provided function. Only Fail reasons are affected; Die and Interrupt reasons pass through unchanged.

When to use

Use to transform expected typed failures while preserving defects and interruptions unchanged.

Details

If at least one Fail reason exists, this returns a new Cause containing the mapped failures. If the cause has no Fail reasons, the original cause is returned unchanged.

Example (Mapping errors to uppercase)

import { Cause } from "effect"

const cause = Cause.fail("error")
const mapped = Cause.map(cause, (e) => e.toUpperCase())
const reason = mapped.reasons[0]
if (Cause.isFailReason(reason)) {
  console.log(reason.error) // "ERROR"
}

Signature

declare const map: { <E, E2>(f: (error: Types.NoInfer<E>) => E2): (self: Cause<E>) => Cause<E2>; <E, E2>(self: Cause<E>, f: (error: Types.NoInfer<E>) => E2): Cause<E2>; }

Source

Since v2.0.0