variable / @typed/fx/Fx

mapError

Transforms typed failures while preserving defects and interruption.

Package version
2.0.0-beta.13
Category
Errors and recovery
Since
1.0.0

Follow one execution

Transforms typed failures while preserving defects and interruption.

Fx timelinemapError changes the typed failure but keeps values and timingmapError
OperatormapError(toDomainError)
Read this diagram

Follow each lane from left to right. Events stacked vertically share a tick; the green cursor marks the current time across every lane.

  • A value
    The text inside the pill is the emitted value.
  • Work starts
    The raised chevron starts an inner run (^ in the source).
  • The run returns
    The vertical bar ends this lane’s run.
  • A cause is delivered
    The exclamation mark belongs to this lane.
  • Work is interrupted
    The cross marks cancellation of this run.
  • Current time
    The line and diamond move together across all lanes.
  • Happening now
    A highlighted event is at the current tick.
  • Still ahead
    Muted, dashed values have not happened yet.
  • Time continues
    The lane’s arrow is not a return marker. An empty stretch can be quiet work that is still running.

Illustrated ticks start at 0. At 1×, one illustrated tick takes one second; captions specify real durations when timing matters. A cause or interruption belongs to its lane, and other work may continue. Scroll horizontally to inspect the rest of a long timeline.

The mapping function runs synchronously for each Cause.Fail reported by the source. It does not run for defects or interrupts, which pass through unchanged. Values retain order and cardinality. No resource is acquired and the returned Fx has the same subscription lifetime and services as its source.

Source implementation · Learn the surrounding model

Compare all Fx timelines →

Import

import { mapError } from "@typed/fx/Fx";

Signatures

export declare const mapError: {
    <E, E2>(f: (e: E) => E2): <A, R>(self: Fx<A, E, R>) => Fx<A, E2, R>;
    <A, E, R, E2>(self: Fx<A, E, R>, f: (e: E) => E2): Fx<A, E2, R>;
};

Why

Libraries can expose a domain error without losing the richer Cause that Effect uses for defects, interruption, and composed failures.

Ownership and lifetime

The mapping function runs synchronously for each Cause.Fail reported by the source. It does not run for defects or interrupts, which pass through unchanged. Values retain order and cardinality. No resource is acquired and the returned Fx has the same subscription lifetime and services as its source.

Examples

import { mapError } from "@typed/fx/Fx"
import { fail } from "@typed/fx/Fx"

const domainFailure = mapError(fail(404), (status) => ({ _tag: "HttpError", status }))

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source