Hyperlinkv0.8.0-beta.28

Cause

Cause.mapconsteffect/Cause.ts:676
<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>

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"
}
mapping
Source effect/Cause.ts:6764 lines
export 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>
} = effect.causeMap