Options
All
  • Public
  • Public/Protected
  • All
Menu

A type that represents the presence of a value.

This type is not intended to be used or instantiated directly. Instead, Some instances can be created with Optional.some and can then be manipulated with any method available on Optional.

Please see the Optional documentation for more information.

Note:

All Some methods are documented at the Optional level.

Type parameters

  • T

    The type of the value contained in this Some instance.

Hierarchy

Index

Methods

and

ap

filter

  • filter(condition: function): Optional<T>

flatMap

  • flatMap<U>(func: function): Optional<U>

forEach

  • forEach(func: function): void

forceUnwrap

  • forceUnwrap(message?: undefined | string): T

isNone

  • isNone(): boolean

isSome

  • isSome(): boolean

map

match

  • match<U, V>(options: OptMatch<T, U, V>): U | V

or

orElse

toArray

  • toArray(): Array<T>

toString

  • toString(): string

unwrap

  • unwrap(message?: undefined | string): T

unwrapOr

  • unwrapOr(other: T | function): T

unwrapOrElse

  • unwrapOrElse(func: function): T

Static fromNullable

  • Creates an Optional with the given value. If null or undefined is provided a None will be returned, otherwise a Some containing the given value will be returned.

    const one = Optional.fromNullable(1);     // one.unwrapOr(0) === 1
    const none = Optional.fromNullable(null); // none.unwrapOr(0) === 0
    const nope = Optional.fromNullable();     // nope.unwrapOr(0) === 0

    Type parameters

    • A

      The type of the value that the new Optional will contain.

    Parameters

    • Optional value: A

      The value to create an Optional with.

    Returns Optional<A>

    Either a Some or a None depending on the value provided.

Static none

Static of

  • Creates an Some with the given value.

    const one = Optional.of(1);
    // one.unwrapOr(0) === 1

    Type parameters

    • A

      The type of the value that the new Some will contain.

    Parameters

    • value: A

      A value to create a Some with.

    Returns Optional<A>

    A Some instance containing value.

Static some

  • Creates a Some with the given value.

    const one = Optional.some(1);
    // one.unwrapOr(0) === 1

    Type parameters

    • A

      The type of the value that the new Some will contain.

    Parameters

    • value: A

      A value to create a Some with.

    Returns Optional<A>

    A Some instance containing value.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc