Package: effect
Module: Result
Wraps a synchronous computation that may throw into a Result safely.
Details
Success<A>Failure<E>unknown{ try, catch } options, the catch function maps the thrown value to EExample (Catching JSON parse errors)
import { Result } from "effect"
const ok = Result.try(() => JSON.parse('{"name": "Alice"}'))
console.log(ok)
// Output: { _tag: "Success", success: { name: "Alice" }, ... }
const err = Result.try({
try: () => JSON.parse("not json"),
catch: (e) => `Parse failed: ${e}`
})
console.log(Result.isFailure(err))
// Output: true
See
succeed / fail for direct constructionfromNullishOr for nullable valuesSignature
declare const try: { <A, E>(options: { readonly try: LazyArg<A>; readonly catch: (error: unknown) => E; }): Result<A, E>; <A>(evaluate: LazyArg<A>): Result<A, unknown>; }
Since v2.0.0