Bluestep JS Documentation
    Preparing search index...

    Class Optional<T>

    A container object which may or may not contain a non-null value. If a value is present, isPresent() returns true. If no value is present, the object is considered empty and isPresent() returns false.

    See async-optional for a JavaScript implementation of Java Optional.

    See java.util.Optional for full documentation

    Type Parameters

    • T
    Index

    Constructors

    Methods

    • If a value is present, and the value matches the given predicate, returns an Optional describing the value, otherwise returns an empty Optional.

      Parameters

      • predicate: (t: T) => boolean

      Returns Optional<T>

    • If a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional.

      Essentially, use [[map]] if you're returning an Object and flatMap if you're returning an Optional.

      Type Parameters

      • U

      Parameters

      Returns Optional<U>

    • If a value is present, returns the value, otherwise throws NoSuchElementException.

      Returns T

    • If a value is present, performs the given action with the value, otherwise does nothing.

      Parameters

      • action: (t: T) => void

      Returns void

    • If a value is present, performs the given action with the value, otherwise performs the given empty-based action.

      Parameters

      • action: (t: T) => void
      • emptyAction: () => void

      Returns void

    • If a value is not present, returns true, otherwise false.

      Returns boolean

    • If a value is present, returns true, otherwise false.

      Returns boolean

    • If a value is present, returns an Optional describing (as if by [[Optional.ofNullable]]) the result of applying the given mapping function to the value, otherwise returns an empty Optional.

      If you're familiar with JavaScript, you know that Array.prototype.map() works like a factory. You supply it with an input set, it applies the same process to each item, then it outputs them as an array. Optional.map() is the same concept, except instead of taking and returning arrays, it takes and returns single items.

      Type Parameters

      • U

      Parameters

      • mapper: (t: T) => U

      Returns Optional<U>

    • If a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function.

      Parameters

      Returns Optional<T>

    • If a value is present, returns the value, otherwise returns other.

      Parameters

      • other: T

      Returns T

    • If a value is present, returns the value, otherwise returns the result produced by the supplying function.

      Parameters

      • supplier: () => T

      Returns T

    • If a value is present, returns the value, otherwise throws NoSuchElementException.

      Returns T

    • If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.

      Type Parameters

      Parameters

      • supplier: () => X

      Returns T

    • If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.

      Returns Stream<T>

    • Returns an empty Optional instance.

      Type Parameters

      • T

      Returns Optional<T>

    • Returns an Optional describing the given non-null value.

      Type Parameters

      • T

      Parameters

      • value: T

      Returns Optional<T>

    • Returns an Optional describing the given value, if non-null, otherwise returns an empty Optional.

      Type Parameters

      • T

      Parameters

      • value: T

      Returns Optional<T>