FuncType - v0.8.85
    Preparing search index...

    Interface Option<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.

    interface Option<T extends Type> {
        _tag: "Some" | "None";
        isEmpty: boolean;
        size: number;
        value: undefined | T;
        ap<U extends unknown>(ff: Option<(value: T) => U>): Option<U>;
        contains(value: T): boolean;
        count(p: (x: T) => boolean): number;
        exists(p: (a: T) => boolean): boolean;
        filter(predicate: (value: T) => boolean): Option<T>;
        find(p: (a: 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;
        forEach(f: (a: T) => void): void;
        get(): T;
        getOrElse(defaultValue: T): T;
        getOrThrow(error: Error): T;
        map<U extends unknown>(f: (value: T) => U): Option<U>;
        match<R>(patterns: { None: () => R; Some: (value: T) => R }): R;
        orElse(alternative: Option<T>): Option<T>;
        orNull(): null | T;
        orUndefined(): undefined | T;
        pipe<U extends unknown>(f: (value: T) => U): U;
        reduce<U>(f: (acc: U, value: T) => U): U;
        reduceRight<U>(f: (acc: U, value: T) => U): U;
        serialize(): SerializationMethods<T>;
        toEither<E>(left: E): Either<E, T>;
        toList(): List<T>;
        toString(): string;
        toValue(): { _tag: "Some" | "None"; value: T };
    }

    Type Parameters

    • T extends Type

      The type of the value contained in the Option

    Hierarchy (View Summary)

    Index

    Properties

    _tag: "Some" | "None"
    isEmpty: boolean

    Whether this Option contains no value

    size: number

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

    value: undefined | T

    The contained value (undefined for None)

    Methods

    • Applies a wrapped function to a wrapped value (Applicative pattern)

      Type Parameters

      • U extends unknown

      Parameters

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

        An Option containing a function from T to U

      Returns Option<U>

      A new Option containing the result of applying the 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

    • Counts elements that satisfy the predicate. For single-value containers: returns 0 or 1 For collections: returns the count of matching elements

      Parameters

      • p: (x: T) => boolean

      Returns number

    • Tests whether any element satisfies the predicate. For single-value containers: tests the single value For collections: returns true if any element matches

      Parameters

      • p: (a: T) => boolean

      Returns boolean

    • 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

    • Finds the first element that satisfies the predicate. For single-value containers: returns Some(value) if predicate matches, None otherwise For collections: returns the first matching element wrapped in Option

      Parameters

      • p: (a: T) => boolean

      Returns Option<T>

    • 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

    • 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

    • 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

    • 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

    • 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

    • Applies an effect function to each element. For single-value containers: applies to the value if present For collections: applies to each element

      Parameters

      • f: (a: T) => void

      Returns void

    • Extracts the value if present

      Returns T

      The contained value

      Error if the Option is None

    • 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

    • 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

    • 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

    • Pattern matches over the Option, applying a handler function based on the variant

      Type Parameters

      • R

      Parameters

      • patterns: { None: () => R; Some: (value: T) => R }

        Object with handler functions for Some and None variants

      Returns R

      The result of applying the matching handler 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

    • Returns the contained value or null if None

      Returns null | T

      The contained value or null

    • Returns the contained value or undefined if None

      Returns undefined | T

      The contained value or undefined

    • Pipes the value through the provided function

      Type Parameters

      • U extends unknown

        The return type of the function

      Parameters

      • f: (value: T) => U

        The function to apply to the value

      Returns U

      The result of applying the function to the value

    • 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

    • 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

    • 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

    • Converts this Option to a List

      Returns List<T>

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

    • Returns a string representation of this Option

      Returns string

      A string representation

    • Returns a simple object representation of this Option

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

      An object with _tag and value properties