Package: effect
Module: Result
A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
succeed / fail to constructmatch to fold both branchesisSuccess / isFailure to narrow the typeE defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
See
succeed / fail to create valuesmatch to fold both branchesisSuccess / isFailure for type guardsSignature
type Result<A, E> = Success<A, E> | Failure<A, E>
Since v4.0.0