A class representing an Option that contains a value. This is the "Some" variant of the Option type, indicating that a value exists.

Type Parameters

  • T

    The type of the contained value

Implements

  • IOption<T>

Constructors

  • Creates a new Some instance with the provided value.

    Type Parameters

    • T

    Parameters

    • value: NonNullable<T>

      The non-null value to wrap

    Returns Some<T>

Methods

  • Applies a function to the contained value and returns the result. This method is essentially the same as Some::and_then() in Rust language.

    Type Parameters

    • U

      The type of the value returned by the function

    Parameters

    • f: ((value: NonNullable<T>) => Option<NonNullable<U>>)

      Function to apply to the contained value

        • (value): Option<NonNullable<U>>
        • Parameters

          • value: NonNullable<T>

          Returns Option<NonNullable<U>>

    Returns Option<NonNullable<U>>

    The result of applying f to the contained value

  • Type guard that always returns false for Some instances.

    Returns this is None

    Always false, indicating this Option contains a value

  • Gets the contained value directly. This is a convenience method for accessing the wrapped value.

    Returns NonNullable<T>

    The contained value

  • Type guard that always returns true for Some instances.

    Returns this is Some<NonNullable<T>>

    Always true, indicating this Option contains a value

  • Executes the Some handler function with the contained value.

    Type Parameters

    • U

      The return type of the match functions

    Parameters

    • obj: {
          None: (() => U | NonNullable<U>);
          Some: ((value: NonNullable<T>) => U | NonNullable<U>);
      }

      Object containing Some and None handler functions

      • None: (() => U | NonNullable<U>)
          • (): U | NonNullable<U>
          • Returns U | NonNullable<U>

      • Some: ((value: NonNullable<T>) => U | NonNullable<U>)
          • (value): U | NonNullable<U>
          • Parameters

            • value: NonNullable<T>

            Returns U | NonNullable<U>

    Returns U | NonNullable<U>

    The result of executing obj.Some with the contained value

  • Returns this Some instance, ignoring the provided function. Since this Option already contains a value, the alternative is not needed.

    Type Parameters

    • U

      The type of the alternative Option (unused)

    Parameters

    • f: (() => Option<NonNullable<U>>)

      Function that returns an alternative Option (unused)

    Returns Option<NonNullable<U>>

    This Some instance cast to the appropriate type

  • Returns the contained value. This method never throws since Some always contains a value.

    Returns NonNullable<T>

    The contained value

  • Returns the contained value, ignoring the provided default. Since this Option contains a value, the alternative is not needed.

    Parameters

    • altValue: NonNullable<T>

      The default value (unused)

    Returns NonNullable<T>

    The contained value

  • Returns the contained value, ignoring the provided function. Since this Option contains a value, the alternative is not needed.

    Parameters

    • f: (() => NonNullable<T>)

      Function that returns a default value (unused)

        • (): NonNullable<T>
        • Returns NonNullable<T>

    Returns NonNullable<T>

    The contained value

  • Returns the contained value. This method never returns undefined since Some always contains a value.

    Returns undefined | NonNullable<T>

    The contained value