import { Option } from "https://deno.land/x/eitherway@0.10.0/lib/core/option.ts";
const { fromFallible } = Option;
Use this if instances of Error
should be evaluated to None
Behaves like Option.from() but also returns None for instances of Error
Examples
Example 1
Example 1
import { assert } from "./assert.ts";
import { Option, None, Some } from "./option.ts";
const str = "thing" as string | undefined;
const undef = undefined as string | undefined;
const err = new Error() as string | Error | TypeError;
const some: Option<string> = Option.fromFallible(str);
const none: Option<string> = Option.fromFallible(undef);
const alsoNone: Option<string> = Option.fromFallible(err);
assert(some instanceof Option === true);
assert(none instanceof Option === true);
assert(alsoNone instanceof Option === true);
assert(some.isSome() === true);
assert(none.isNone() === true);
assert(alsoNone.isNone() === true);
Parameters
value: T