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

Contains the success value

Type Parameters

  • T

Implements

Constructors

  • Type Parameters

    • T

    Parameters

    • val: T

    Returns SomeImpl<T>

Methods

  • Helper function if you know you have an Some and T is iterable

    Returns Iterator<T extends Iterable<U>
        ? U
        : never, any, undefined>

  • 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

    Returns Option<T2>

  • 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 T

  • 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: ((val) => T2)
        • (val): T2
        • Parameters

          • val: T

          Returns T2

    Returns Some<T2>

  • 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: ((val) => T2)
        • (val): T2
        • Parameters

          • val: T

          Returns T2

    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: ((val) => U)
        • (val): U
        • Parameters

          • val: T

          Returns U

    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.

    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.

    Parameters

    Returns Option<T>

    Example

    Some(1).orElse(() => Some(2)) // => Some(1)
    None.orElse(() => Some(2)) // => Some(2)
  • Returns the contained Some value, but never throws. Unlike unwrap(), this method doesn't throw and is only callable on an Some

    Therefore, it can be used instead of unwrap() as a maintainability safeguard that will fail to compile if the type of the Option is later changed to a None that can actually occur.

    (this is the into_Some() in rust)

    Returns T

  • Maps an Option<T> to a Result<T, E>.

    Type Parameters

    • E

    Parameters

    • error: E

    Returns Ok<T>

  • 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 T

  • Returns the contained Some value or a provided default.

    (This is the unwrap_or in rust)

    Parameters

    • _val: unknown

    Returns T

Properties

value: T

References

Re-exports EMPTY