Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Optional<T>

An optional value of type T.

Construct using Optional.of or Optional.empty.

Collabs uses this utility type in places where T | undefined or T | null is inappropriate because T may itself be null/undefined.

Local data structure - not a Collab.

Type Parameters

  • T

Hierarchy

  • Optional

Index

Properties

isPresent: boolean

Whether the value is present.

Methods

  • get(): T
  • Returns the value if present, else throwing an error.

    Returns T

  • map<U>(f: ((value: T) => U)): Optional<U>
  • Map the value by f if present, else returning an empty Optional.

    Type Parameters

    • U

    Parameters

    • f: ((value: T) => U)
        • (value: T): U
        • Parameters

          • value: T

          Returns U

    Returns Optional<U>

  • orElse(other: T): T
  • Returns the value if present, else returning other.

    Parameters

    • other: T

    Returns T

  • toString(): string
  • Returns string

  • Returns an empty (not present) Optional.

    Internally, all empty Optionals are the same literal object.

    Type Parameters

    • T

    Returns Optional<T>

  • Returns a new present Optional representing value.

    Type Parameters

    • T

    Parameters

    • value: T

    Returns Optional<T>

Generated using TypeDoc