FuncType - v0.8.85
    Preparing search index...

    Interface Try<T>

    Base interface for all functype data structures. This provides a standard contract with core functional programming traits.

    // Implementing FunctypeBase for a custom data structure
    class MyContainer<T> implements FunctypeBase<T, "Empty" | "Full"> {
    // Implementation of all required methods...
    }
    interface Try<T> {
        _tag: TypeNames;
        ap: <U>(ff: Try<(value: T) => U>) => Try<U>;
        error: undefined | Error;
        flatMap: <U>(f: (value: T) => Try<U>) => Try<U>;
        flatMapAsync: <U>(f: (value: T) => Promise<Try<U>>) => Promise<Try<U>>;
        fold: <U extends unknown>(
            onFailure: (error: Error) => U,
            onSuccess: (value: T) => U,
        ) => U;
        get: () => T;
        getOrElse: (defaultValue: T) => T;
        getOrThrow: (error?: Error) => T;
        isFailure: () => boolean;
        isSuccess: () => boolean;
        map: <U>(f: (value: T) => U) => Try<U>;
        orElse: (alternative: Try<T>) => Try<T>;
        orNull: () => null | T;
        orThrow: (error: Error) => T;
        orUndefined: () => undefined | T;
        toEither: () => Either<Error, T>;
        toString: () => string;
        get isEmpty(): boolean;
        get size(): number;
        contains(value: T): boolean;
        count(p: (x: T) => boolean): number;
        exists(p: (a: T) => boolean): boolean;
        find(p: (a: T) => boolean): Option<T>;
        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;
        match<R>(
            patterns: { Failure: (error: Error) => R; Success: (value: T) => R },
        ): R;
        pipe<U extends unknown>(f: (value: T) => U): U;
        reduce(f: (b: T, a: T) => T): T;
        reduceRight(f: (b: T, a: T) => T): T;
        serialize(): SerializationMethods<T>;
        toValue(): { _tag: TypeNames; value: Error | T };
    }

    Type Parameters

    • T

      The type of value contained in the functor

    Hierarchy (View Summary)

    Index

    Properties

    _tag: TypeNames
    ap: <U>(ff: Try<(value: T) => U>) => Try<U>
    error: undefined | Error
    flatMap: <U>(f: (value: T) => Try<U>) => Try<U>
    flatMapAsync: <U>(f: (value: T) => Promise<Try<U>>) => Promise<Try<U>>
    fold: <U extends unknown>(
        onFailure: (error: Error) => U,
        onSuccess: (value: T) => U,
    ) => U

    Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success

    Type declaration

      • <U extends unknown>(
            onFailure: (error: Error) => U,
            onSuccess: (value: T) => U,
        ): U
      • Type Parameters

        • U extends unknown

        Parameters

        • onFailure: (error: Error) => U

          Function to apply if the Try is Failure

        • onSuccess: (value: T) => U

          Function to apply if the Try is Success

        Returns U

        The result of applying the appropriate function

    get: () => T

    Extracts the value unsafely

    Type declaration

      • (): T
      • Returns T

        The contained value

    Error if the container is empty

    getOrElse: (defaultValue: T) => T

    Returns the contained value or a default value

    Type declaration

      • (defaultValue: T): T
      • Parameters

        • defaultValue: T

          The value to return if extraction fails

        Returns T

        The contained value or defaultValue

    getOrThrow: (error?: Error) => T

    Returns the contained value or throws an error

    Type declaration

      • (error?: Error): T
      • Parameters

        • Optionalerror: Error

          Optional error to throw (implementations may have defaults)

        Returns T

        The contained value

    The specified error if extraction fails

    isFailure: () => boolean
    isSuccess: () => boolean
    map: <U>(f: (value: T) => U) => Try<U>
    orElse: (alternative: Try<T>) => Try<T>

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

    Type declaration

      • (alternative: Try<T>): Try<T>
      • Parameters

        • alternative: Try<T>

          The alternative container

        Returns Try<T>

        This container or the alternative

    orNull: () => null | T

    Returns the contained value or null

    Type declaration

      • (): null | T
      • Returns null | T

        The contained value or null

    orThrow: (error: Error) => T
    orUndefined: () => undefined | T

    Returns the contained value or undefined

    Type declaration

      • (): undefined | T
      • Returns undefined | T

        The contained value or undefined

    toEither: () => Either<Error, T>
    toString: () => string

    Returns a string representation of an object.

    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: 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

    • 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>

    • 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

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

      Type Parameters

      • R

      Parameters

      • patterns: { Failure: (error: Error) => R; Success: (value: T) => R }

        Object with handler functions for Success and Failure variants

      Returns R

      The result of applying the matching handler function

    • 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