Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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 orElseGet(value: Optional<T> | T): T;
public orElseThrows(exception: Error);
public toString(): String;
 
static private readonly EMPTY: Optional<any>;
 
static public empty<T>(): Optional<T>;
static public of<T>(value: T): Optional<T>;
static public ofNullable<T>(value: T): Optional<T>;
}

§Type Parameters

§Constructors

§
new Optional()
[src]

§Properties

§
value: T | null
[src]

"Optionable" object.

§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.

§
ifPresent(): boolean
[src]

Returns a boolean value of whether the optional value is present.

§
orElseGet(value: Optional<T> | T): T
[src]

Returns the value present in the Optional instance. if @param value is an Optional, it will invoke "get", otherwise it will return the whole value. If not value is present, it will return undefined.

§
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.

§
toString(): String
[src]

§Static Properties

§
EMPTY: Optional<any>
[src]

Default empty optional

§Static Methods

§
empty<T>(): Optional<T>
[src]

Returns a empty optional

§
of<T>(value: T): Optional<T>
[src]

Creates a new optional from a value which will be the optional's object.

§
ofNullable<T>(value: T): Optional<T>
[src]

Creates a Optional instance. if @param value is provided but it is either null or undefined, then it creates an empty instance of Optional.