Sudoo-Optional

Build Status codecov npm version downloads

Optional makes life better

Install

yarn add @sudoo/optional
# Or
npm install @sudoo/optional --save

Usage

import { Optional } from "@sudoo/optional";

const foo: Optional = Optional.of("bar");
foo.exists; // true
foo.value; // "bar"

const bar: Optional = Optional.of();
bar.exists; // false
bar.value; // undefined
bar.getOrThrow(); // Throw Error A
bar.getOrThrow(new Error("B")); // Throw Error B
bar.getOrDefault("baz"); // "baz"