Class Optional<T>Abstract

Represents a value that might or might not be. The API is inspired from Option in scala. You operate on this type like you would on an array, allowing you to chain possible mappings operations that will happen if a value is defined (of type Some), and will not happen if the value is undefined (of type None).

Type Parameters

  • T extends NonNullable<any>

Constructors

Methods

  • Filters out value if it doesn't fulfill predicate. A Some value then becomes None

    Parameters

    • predicate: ((val) => boolean)
        • (val): boolean
        • Parameters

          • val: T

          Returns boolean

    Returns Optional<T>

  • Maps the contained value with a function that returns Optional. It functions like map, except it also flattens so that you don't get a nested Optional<Optional>

    Type Parameters

    • A extends unknown

    Parameters

    Returns Optional<A>

  • Performs the operation on the given value, then return the option again. This is unlike the Scala API, where Unit is returned. here it allows for additional chaining of mappings etc.

    Parameters

    • f: ((val) => void)
        • (val): void
        • Parameters

          • val: T

          Returns void

    Returns Optional<T>

  • Gets get value if exists, otherwise throws exception.

    Returns T

  • Gets the value if exists, otherwise returns inserted value.

    Parameters

    • val: T

    Returns T

  • Check if a value exists

    Returns boolean

  • Maps the contained value if exists using the given function.

    Type Parameters

    • A extends unknown

    Parameters

    • f: ((val) => A)
        • (val): A
        • Parameters

          • val: T

          Returns A

    Returns Optional<A>

  • Checks if a value doesn't exist.

    Returns boolean

  • If this optional isn't some, the or statement will be evaluated.

    Parameters

    Returns Optional<T>

  • Type Parameters

    • T

    Parameters

    • value: undefined | T

    Returns Optional<T>

Generated using TypeDoc