Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Optional<T>

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: NonNullable<any>

Hierarchy

Index

Methods

Abstract filter

  • filter(predicate: (val: T) => boolean): Optional<T>
  • Filters out value if it doesn't fulfill predicate. A Some value then becomes None

    Parameters

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

          • val: T

          Returns boolean

    Returns Optional<T>

Abstract flatMap

  • 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: NonNullable<any>

    Parameters

    Returns Optional<A>

Abstract foreach

  • foreach(f: (val: T) => void): Optional<T>
  • 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: T) => void
        • (val: T): void
        • Parameters

          • val: T

          Returns void

    Returns Optional<T>

Abstract get

  • get(): T
  • Gets get value if exists, otherwise throws exception.

    Returns T

Abstract getOrElse

  • getOrElse(val: T): T
  • Gets the value if exists, otherwise returns inserted value.

    Parameters

    • val: T

    Returns T

Abstract isEmpty

  • isEmpty(): boolean

Abstract map

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

    Type parameters

    • A: NonNullable<any>

    Parameters

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

          • val: T

          Returns A

    Returns Optional<A>

Abstract nonEmpty

  • nonEmpty(): boolean
  • Checks if a value doesn't exist.

    Returns boolean

Abstract or

Static of

  • of<T>(value: T | undefined): Optional<T>

Generated using TypeDoc