Package: effect
Module: Option
Lifts a function that may throw into one that returns an Option.
When to use
Use to wrap exception-throwing APIs (e.g. JSON.parse) for safe usage
Details
Some with the resultNone (exception is swallowed)Example (Lifting JSON.parse)
import { Option } from "effect"
const parse = Option.liftThrowable(JSON.parse)
console.log(parse("1"))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
console.log(parse(""))
// Output: { _id: 'Option', _tag: 'None' }
See
liftNullishOr for nullable-returning functionsSignature
declare const liftThrowable: <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => B) => (...a: A) => Option<B>
Since v2.0.0