FuncType - v0.60.3
    Preparing search index...

    Interface Extractable<T>

    Extractable type class for data structures that can extract their values with various fallback strategies.

    Covariance: T is declared <out T>. The fallback methods orElse and or widen the result via <T2>, matching Scala's getOrElse[B1 >: B](default: => B1): B1 shape — when the caller passes a T-typed default the result is just T, and when they pass a wider T2 the result union widens accordingly.

    Implementers that previously overrode or/orElse with widened signatures (Option, Either, Try) can inherit from this base directly; their 0.58-era Omit<Extractable<T>, "or" | "orElse"> workarounds are no longer needed.

    interface Extractable<out T extends Type> {
        or<T2 extends unknown>(
            alternative: Extractable<T2>,
        ): Extractable<T | T2>;
        orElse<T2 extends unknown>(defaultValue: T2): T | T2;
        orNull(): T | null;
        orThrow(error?: Error): T;
        orUndefined(): T | undefined;
    }

    Type Parameters

    Hierarchy (View Summary)

    Index

    Methods

    • Returns this container if it has a value, otherwise returns the alternative container. The alternative may carry a different type; the result widens to Extractable<T | T2>.

      Type Parameters

      • T2 extends unknown

      Parameters

      Returns Extractable<T | T2>

      This container or the alternative

    • Returns the contained value or a default value. The default may be of a different type; the result widens to T | T2.

      Type Parameters

      • T2 extends unknown

      Parameters

      • defaultValue: T2

        The value to return if extraction fails

      Returns T | T2

      The contained value or defaultValue

    • Returns the contained value or null

      Returns T | null

      The contained value or null

    • Extract the value or throw an error

      Parameters

      • Optionalerror: Error

        Optional custom error to throw. If not provided, uses type-appropriate default error

      Returns T

      The contained value

      The specified error, container's error, or a sensible default

    • Returns the contained value or undefined

      Returns T | undefined

      The contained value or undefined