FuncType - v0.8.64
    Preparing search index...

    Type Alias Option<T>

    Option: {
        _tag: "Some" | "None";
        isEmpty: boolean;
        size: number;
        value: T | undefined;
        contains(value: T): boolean;
        filter(predicate: (value: T) => boolean): Option<T>;
        flatMap<U extends unknown>(f: (value: T) => Option<U>): Option<U>;
        flatMapAsync<U extends unknown>(
            f: (value: T) => Promise<Option<U>>,
        ): Promise<Option<U>>;
        fold<U>(onNone: () => U, onSome: (value: T) => U): U;
        foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B;
        foldRight<B>(z: B): (op: (a: T, b: B) => B) => B;
        get(): T;
        getOrElse(defaultValue: T): T;
        getOrThrow(error: Error): T;
        map<U extends unknown>(f: (value: T) => U): Option<U>;
        orElse(alternative: Option<T>): Option<T>;
        orNull(): null | T;
        reduce<U>(f: (acc: U, value: T) => U): U;
        reduceRight<U>(f: (acc: U, value: T) => U): U;
        toEither<E>(left: E): Either<E, T>;
        toList(): List<T>;
        toString(): string;
        toValue(): { _tag: "Some" | "None"; value: T };
    } & Traversable<T> & Functor<T> & Typeable<"Some" | "None"> & Valuable<
        "Some"
        | "None",
        T,
    > & AsyncFunctor<T>

    The Option type represents a value that may or may not exist. It's used to handle potentially null or undefined values in a type-safe way.

    Type Parameters

    • T extends Type

      The type of the value contained in the Option

    Type declaration

    • Readonly_tag: "Some" | "None"

      Tag identifying if this is a Some or None variant

    • isEmpty: boolean

      Whether this Option contains no value

    • size: number

      The number of elements in this Option (0 or 1)

    • Readonlyvalue: T | undefined

      The contained value (undefined for None)

    • contains: function
      • Checks if this Option contains the specified value

        Parameters

        • value: T

          The value to check for

        Returns boolean

        true if this Option contains the value, false otherwise

    • filter: function
      • Returns this Option if it contains a value that satisfies the predicate, otherwise returns None

        Parameters

        • predicate: (value: T) => boolean

          The predicate function to test the value

        Returns Option<T>

        This Option or None

    • flatMap: function
      • Maps the value using a function that returns an Option

        Type Parameters

        • U extends unknown

        Parameters

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

          The mapping function returning an Option

        Returns Option<U>

        The result of applying f to the contained value, or None if this Option is None

    • flatMapAsync: function
      • Maps the value using an async function that returns an Option

        Type Parameters

        • U extends unknown

        Parameters

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

          The async mapping function returning an Option

        Returns Promise<Option<U>>

        Promise of the result of applying f to the contained value, or None if this Option is None

    • fold: function
      • Pattern matches over the Option, applying onNone if None and onSome if Some

        Type Parameters

        • U

        Parameters

        • onNone: () => U

          Function to apply if the Option is None

        • onSome: (value: T) => U

          Function to apply if the Option has a value

        Returns U

        The result of applying the appropriate function

    • foldLeft: function
      • Left-associative fold using the provided zero value and operation

        Type Parameters

        • B

        Parameters

        • z: B

          Zero/identity value

        Returns (op: (b: B, a: T) => B) => B

        A function that takes an operation to apply

    • foldRight: function
      • Right-associative fold using the provided zero value and operation

        Type Parameters

        • B

        Parameters

        • z: B

          Zero/identity value

        Returns (op: (a: T, b: B) => B) => B

        A function that takes an operation to apply

    • get: function
      • Extracts the value if present

        Returns T

        The contained value

        Error if the Option is None

    • getOrElse: function
      • Returns the contained value or a default value if None

        Parameters

        • defaultValue: T

          The value to return if this Option is None

        Returns T

        The contained value or defaultValue

    • getOrThrow: function
      • Returns the contained value or throws a specified error if None

        Parameters

        • error: Error

          The error to throw if this Option is None

        Returns T

        The contained value

        The specified error if the Option is None

    • map: function
      • Maps the value inside the Option using the provided function

        Type Parameters

        • U extends unknown

        Parameters

        • f: (value: T) => U

          The mapping function

        Returns Option<U>

        A new Option containing the mapped value, or None if this Option is None

    • orElse: function
      • Returns this Option if it contains a value, otherwise returns the alternative

        Parameters

        • alternative: Option<T>

          The alternative Option to return if this is None

        Returns Option<T>

        This Option or the alternative

    • orNull: function
      • Returns the contained value or null if None

        Returns null | T

        The contained value or null

    • reduce: function
      • Applies a binary operator to a start value and the contained value

        Type Parameters

        • U

        Parameters

        • f: (acc: U, value: T) => U

          The binary operator

        Returns U

        The result of the reduction

    • reduceRight: function
      • Applies a binary operator to the contained value and a start value

        Type Parameters

        • U

        Parameters

        • f: (acc: U, value: T) => U

          The binary operator

        Returns U

        The result of the reduction

    • toEither: function
      • Converts this Option to an Either

        Type Parameters

        • E

        Parameters

        • left: E

          The value to use for Left if this Option is None

        Returns Either<E, T>

        Either.Right with the contained value if Some, or Either.Left with left if None

    • toList: function
      • Converts this Option to a List

        Returns List<T>

        A List containing the value if Some, or empty List if None

    • toString: function
      • Returns a string representation of this Option

        Returns string

        A string representation

    • toValue: function
      • Returns a simple object representation of this Option

        Returns { _tag: "Some" | "None"; value: T }

        An object with _tag and value properties