import { Option } from "https://deno.land/x/eitherway@0.10.0/lib/core/option.ts";
const { fromCoercible } = Option;
Use this if all falsy values should be evaluated to None
Behaves like Option.from() but returns None for falsy values This is also reflected in the return type in case of unions
Examples
Example 1
Example 1
import { assert } from "./assert.ts";
import { Option, None, Some } from "./option.ts";
type Bit = 1 | 0;
type Maybe = "thing" | "";
const str = "" as Maybe;
const bit = 0 as Bit;
const some: Option<"thing"> = Option.fromCoercible(str);
const none: Option<1> = Option.fromCoercible(bit);
assert(some instanceof Option === true);
assert(none instanceof Option === true);
assert(some.isSome() === true);
assert(none.isNone() === true);
Parameters
value: T