Optional
import { Optional } from "https://raw.githubusercontent.com/mandarineorg/mandarinets/master/mod.ts";
The optional class is used to avoid repetitive validation with If's. If an object is present, you can verify this with Optional.isPresent() If An object is not present but you would like to get a default value, you can do this with Optional.orElseGet(defaultValue); This classs allows you to avoid null exceptions.
class Optional<T> { }
constructor();
private value: T | null;
public get(): T;
public ifPresent(): boolean;
public orElseThrows(exception: Error);
public toString(): String;
§Properties
§Methods
§
get(): T
[src]Gets the value of the Optional only if it is present. If value is not present, an exception will be thrown.
§
orElseThrows(exception: Error)
[src]Tries to get the value in Optional. If value is not present, it will throw an exception.
@param exception
, exception to be thrown.