Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Optional<T>

An object that represents nullable(undefinable) value.

const opt1 = new Optional<string>(hello);
const opt2 = new Optional();

Type parameters

  • T

Hierarchy

  • Optional

Index

Constructors

constructor

  • new Optional(value?: T | null): Optional

Properties

Protected Optional _value

_value: T | null

Accessors

isNotPresent

  • get isNotPresent(): boolean
  • Returns true if the object has no value, otherwise returns false.

    Returns boolean

isPresent

  • get isPresent(): boolean
  • Returns true if the object has a value, otherwise returns false.

    Returns boolean

Methods

flatMap

  • flatMap<U>(func: function): U | null | undefined
  • Executes the func with the value if the object has a value, and returns the return value of the func. If the object has no value, just returns the value which is null or undefined.

    Type parameters

    • U

    Parameters

    • func: function
        • (value: T): U
        • Parameters

          • value: T

          Returns U

    Returns U | null | undefined

ifNotPresent

  • ifNotPresent(func: function): void
  • Executes the func with the value if the object has no value, otherwise do nothing.

    Parameters

    • func: function
        • (): any
        • Returns any

    Returns void

ifPresent

  • ifPresent(func: function): void
  • Executes the func with the value if the object has a value, otherwise do nothing.

    Parameters

    • func: function
        • (value: T): any
        • Parameters

          • value: T

          Returns any

    Returns void

ifPresentOrElse

  • ifPresentOrElse(func: function, elseFunc: function): void
  • Executes the func with the value if the object has a value, otherwise executes elseFunc.

    Parameters

    • func: function
        • (value: T): any
        • Parameters

          • value: T

          Returns any

    • elseFunc: function
        • (): any
        • Returns any

    Returns void

map

  • Executes the func with the value if the object has a value, and returns new Optional object with the return value of the func. If the object has no value, just returns new Optional object without applying the func.

    Type parameters

    • U

    Parameters

    • func: function
        • (value: T): U
        • Parameters

          • value: T

          Returns U

    Returns Optional<U>

Generated using TypeDoc