Package: effect
Module: Exit
Transforms both the success value and typed error of an Exit.
When to use
Use when you need to remap both channels in one step.
Details
onSuccess transforms the value if the Exit is a Success. onFailure
transforms the typed error if the Exit is a Failure with a Fail reason.
Allocates a new Exit.
Gotchas
If the Cause contains only defects or interruptions, the failure passes through unchanged.
Example (Mapping both channels)
import { Data, Exit } from "effect"
class ExitError extends Data.TaggedError("ExitError")<{ readonly input: string }> {}
const exit = Exit.succeed(42)
const mapped = Exit.mapBoth(exit, {
onSuccess: (x) => String(x),
onFailure: (e: string) => new ExitError({ input: e })
})
console.log(Exit.isSuccess(mapped) && mapped.value) // "42"
See
map to transform only the success valuemapError to transform only the errorSignature
declare const mapBoth: { <E, E2, A, A2>(options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2; }): (self: Exit<A, E>) => Exit<A2, E2>; <A, E, E2, A2>(self: Exit<A, E>, options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2; }): Exit<A2, E2>; }
Since v2.0.0