FuncType - v0.8.85
    Preparing search index...

    Interface Functype<A, Tag>

    Interface for single-value containers like Option, Either, Try. Extends FunctypeBase with extraction methods and Pipe.

    interface Functype<A, Tag extends string = string> {
        _tag: Tag;
        get isEmpty(): boolean;
        get size(): number;
        ap<B extends unknown>(ff: Applicative<(value: A) => B>): Applicative<B>;
        contains(value: A): boolean;
        count(p: (x: A) => boolean): number;
        exists(p: (a: A) => boolean): boolean;
        find(p: (a: A) => boolean): Option<A>;
        flatMap<B extends unknown>(f: (value: A) => Monad<B>): Monad<B>;
        flatMapAsync<B extends unknown>(
            f: (value: A) => PromiseLike<AsyncMonad<B>>,
        ): PromiseLike<AsyncMonad<B>>;
        fold<B>(onEmpty: () => B, onValue: (value: A) => B): B;
        foldLeft<B>(z: B): (op: (b: B, a: A) => B) => B;
        foldRight<B>(z: B): (op: (a: A, b: B) => B) => B;
        forEach(f: (a: A) => void): void;
        get(): A;
        getOrElse(defaultValue: A): A;
        getOrThrow(error?: Error): A;
        map<B extends unknown>(f: (value: A) => B): Functor<B>;
        match<R>(patterns: Record<Tags, (value: A) => R>): R;
        orElse(alternative: Extractable<A>): Extractable<A>;
        orNull(): null | A;
        orUndefined(): undefined | A;
        pipe<U extends unknown>(f: (value: A) => U): U;
        reduce(f: (b: A, a: A) => A): A;
        reduceRight(f: (b: A, a: A) => A): A;
        serialize(): SerializationMethods<A>;
        toValue(): { _tag: Tag; value: A };
    }

    Type Parameters

    • A

      The type of value contained

    • Tag extends string = string

      The type tag for pattern matching

    Hierarchy (View Summary)

    Index

    Properties

    _tag: Tag

    Accessors

    • get isEmpty(): boolean

      Returns boolean

    • get size(): number

      Returns number

    Methods

    • 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: A) => 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: A) => boolean

      Returns boolean

    • 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: A) => boolean

      Returns Option<A>

    • Pattern matches over the structure, applying specific handlers for each variant

      Type Parameters

      • B

      Parameters

      • onEmpty: () => B

        Function to apply if the structure is empty or has no value

      • onValue: (value: A) => B

        Function to apply if the structure has a value

      Returns B

      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: A) => 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: A, 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: A) => void

      Returns void

    • Extracts the value unsafely

      Returns A

      The contained value

      Error if the container is empty

    • Returns the contained value or a default value

      Parameters

      • defaultValue: A

        The value to return if extraction fails

      Returns A

      The contained value or defaultValue

    • Returns the contained value or throws an error

      Parameters

      • Optionalerror: Error

        Optional error to throw (implementations may have defaults)

      Returns A

      The contained value

      The specified error if extraction fails

    • Pattern matches against this data structure, applying handlers for each variant based on tag. Similar to fold but with stronger type safety for tag-based variants.

      The return type is inferred from the pattern handlers when not explicitly specified.

      Type Parameters

      • R

      Parameters

      • patterns: Record<Tags, (value: A) => R>

        An object containing handler functions for each variant

      Returns R

      The result of applying the matching handler function

    • Returns this container if it has a value, otherwise returns the alternative

      Parameters

      • alternative: Extractable<A>

        The alternative container

      Returns Extractable<A>

      This container or the alternative

    • Returns the contained value or null

      Returns null | A

      The contained value or null

    • Returns the contained value or undefined

      Returns undefined | A

      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: A) => U

        The function to apply to the value

      Returns U

      The result of applying the function to the value

    • Returns { _tag: Tag; value: A }