Package: effect
Module: Result
Transforms both the success and failure channels of a Result.
When to use
Use to transform both success and failure values without changing whether the result succeeds or fails.
Details
onSuccess if the result is a SuccessonFailure if the result is a FailureExample (Mapping both channels)
import { pipe, Result } from "effect"
const result = pipe(
Result.succeed(1),
Result.mapBoth({
onSuccess: (n) => n + 1,
onFailure: (e) => `Error: ${e}`
})
)
console.log(result)
// Output: { _tag: "Success", success: 2, ... }
See
map to transform only the success valuemapError to transform only the error valuematch to fold into a single valueSignature
declare const mapBoth: { <E, E2, A, A2>(options: { readonly onFailure: (left: E) => E2; readonly onSuccess: (right: A) => A2; }): (self: Result<A, E>) => Result<A2, E2>; <E, A, E2, A2>(self: Result<A, E>, options: { readonly onFailure: (left: E) => E2; readonly onSuccess: (right: A) => A2; }): Result<A2, E2>; }
Since v2.0.0