⚠️ Internal: This API is not publically exported by the package.

Contains the None value

Implements

Constructors

Methods

  • Returns Iterator<never, never, any>

  • Calls mapper if the Option is Some, otherwise returns None. This function can be used for control flow based on Option values.

    Type Parameters

    • T2

    Parameters

    • op: unknown

    Returns NoneImpl

  • Returns the contained Some value, if exists. Throws an error if not.

    If you know you're dealing with Some and the compiler knows it too (because you tested isSome() or isNone()) you should use value instead. While Some's expect() and value will both return the same value using value is preferable because it makes it clear that there won't be an exception thrown on access.

    Parameters

    • msg: string

      the message to throw if no Some value.

    Returns never

  • Maps an Option<T> to Option<U> by applying a function to a contained Some value, leaving a None value untouched.

    This function can be used to compose the Options of two functions.

    Type Parameters

    • T2

    Parameters

    • _mapper: unknown

    Returns NoneImpl

  • Maps an Option<T> to Option<U> by either converting T to U using mapper (in case of Some) or using the default_ value (in case of None).

    If default is a result of a function call consider using mapOrElse() instead, it will only evaluate the function when needed.

    Type Parameters

    • T2

    Parameters

    • default_: T2
    • _mapper: unknown

    Returns T2

  • Maps an Option<T> to Option<U> by either converting T to U using mapper (in case of Some) or producing a default value using the default function (in case of None).

    Type Parameters

    • U

    Parameters

    • default_: (() => U)
        • (): U
        • Returns U

    • _mapper: unknown

    Returns U

  • Returns Some() if we have a value, otherwise returns other.

    other is evaluated eagerly. If other is a result of a function call try orElse() instead – it evaluates the parameter lazily.

    Type Parameters

    • T

    Parameters

    Returns Option<T>

    Example

    Some(1).or(Some(2)) // => Some(1)
    None.or(Some(2)) // => Some(2)
  • Returns Some() if we have a value, otherwise returns the result of calling other().

    other() is called only when needed.

    Type Parameters

    • T

    Parameters

    Returns Option<T>

    Example

    Some(1).orElse(() => Some(2)) // => Some(1)
    None.orElse(() => Some(2)) // => Some(2)
  • Maps an Option<T> to a Result<T, E>.

    Type Parameters

    • E

    Parameters

    • error: E

    Returns Err<E>

  • Returns string

  • Returns the contained Some value. Because this function may throw, its use is generally discouraged. Instead, prefer to handle the None case explicitly.

    If you know you're dealing with Some and the compiler knows it too (because you tested isSome() or isNone()) you should use value instead. While Some's unwrap() and value will both return the same value using value is preferable because it makes it clear that there won't be an exception thrown on access.

    Throws if the value is None.

    Returns never

  • Returns the contained Some value or a provided default.

    (This is the unwrap_or in rust)

    Type Parameters

    • T2

    Parameters

    • val: T2

    Returns T2