Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/eitherway/lib/core/mod.ts>Option.fromCoercible

Yet Another Option and Result Implementation - providing safe abstractions for fallible flows inspired by F# and Rust
Latest
function Option.fromCoercible
import { Option } from "https://deno.land/x/eitherway@0.10.0/lib/core/mod.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

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);