import { Option } from "https://deno.land/x/eitherway@0.10.0/lib/core/option.ts";
const { liftFallible } = Option;
Same as Option.lift
but with a safety net.
Use this if the function to be lifted might throw. In case of an
exception, None
is returned.
Examples
Example 1
Example 1
import { assert } from "./assert.ts";
import { Option, None, Some } from "./option.ts";
function fallible(input: number): number {
if (input === 42) return input;
throw TypeError("Not even!");
}
const lifted = Option.liftFallible(fallible, Option.fromCoercible);
const maybe = Option.from(42).andThen(lifted);
assert(maybe.isSome() === true);
assert(maybe.unwrap() === 42);