ts-data-forge
    Preparing search index...
    • Unwraps an Optional, returning the contained value or undefined if empty.

      This function provides a safe way to extract values from Optionals without throwing exceptions. It has overloaded behavior based on the type:

      • For Optional.Some<T>: Always returns T (guaranteed by type system)
      • For general Optional<T>: Returns T | undefined

      Type Parameters

      • O extends Readonly<{ value: unknown }>

        The Optional.Base type to unwrap.

      Parameters

      • optional: O

        The Optional to unwrap.

      Returns Unwrap<O>

      The contained value if Optional.Some, otherwise undefined.

      const someString = Optional.some('text');
      const noneString = Optional.none as Optional<string>;

      assert(Optional.unwrap(someString) === 'text');
      assert(Optional.unwrap(noneString) === undefined);
    • Unwraps an Optional, returning the contained value or undefined if empty.

      This function provides a safe way to extract values from Optionals without throwing exceptions. It has overloaded behavior based on the type:

      • For Optional.Some<T>: Always returns T (guaranteed by type system)
      • For general Optional<T>: Returns T | undefined

      Type Parameters

      Parameters

      • optional: O

        The Optional to unwrap.

      Returns Unwrap<O> | undefined

      The contained value if Optional.Some, otherwise undefined.

      const someString = Optional.some('text');
      const noneString = Optional.none as Optional<string>;

      assert(Optional.unwrap(someString) === 'text');
      assert(Optional.unwrap(noneString) === undefined);