Variable Result

Result: {
    andThen: (<V, E, T>(mapper: Mapper<V, Result<T, E>>) => Mapper<Result<V, E>, Result<T, E>>);
    asNullable: (<V, E>() => Mapper<Result<V, E>, Result<Option<V>, E>>);
    err: (<V, E>(value: E) => Result<V, E>);
    error: (<V>(message: string) => Result<V, Error>);
    isErr: (<V, E>() => Mapper<Result<V, E>, boolean>);
    isInstance: (<V, E>(value: unknown) => value is Result<V, E>);
    isOk: (<V, E>() => Mapper<Result<V, E>, boolean>);
    map: (<V, E, T>(mapper: Mapper<V, T>) => Mapper<Result<V, E>, Result<T, E>>);
    mapErr: (<V, E, T>(mapper: Mapper<E, T>) => Mapper<Result<V, E>, Result<V, T>>);
    ok: (<V, E>(value: V) => Result<V, E>);
    someOrNone: (<V, E>() => Mapper<Result<V, E>, Option<V>>);
    transpose: (<V, E>(result: Result<Option<V>, E>) => Option<Result<V, E>>);
    valueOr: (<V, E>(fallback: V | Mapper<E, V>) => Mapper<Result<V, E>, V>);
}

Result-related utilities.

Type declaration

  • andThen: (<V, E, T>(mapper: Mapper<V, Result<T, E>>) => Mapper<Result<V, E>, Result<T, E>>)

    Higher order function returning a function that performs the andThen method on the provided Result.

    The returned function maps the current Result to a new one if it is Ok.

  • asNullable: (<V, E>() => Mapper<Result<V, E>, Result<Option<V>, E>>)

    Higher order function returning a function that performs the asNullable method on the provided Result.

    The returned function maps the Result so the Ok value is wrapped in an Option based on its presence.

  • err: (<V, E>(value: E) => Result<V, E>)

    Creates a new Err instance.

      • <V, E>(value): Result<V, E>
      • Type Parameters

        • V
        • E extends Error

        Parameters

        • value: E

          The error to wrap.

        Returns Result<V, E>

        A new Err instance.

  • error: (<V>(message: string) => Result<V, Error>)

    Creates a new Error with the provided message and wraps it in an Err.

      • <V>(message): Result<V, Error>
      • Type Parameters

        • V

        Parameters

        • message: string

          The error message.

        Returns Result<V, Error>

        A new Err instance with the error.

  • isErr: (<V, E>() => Mapper<Result<V, E>, boolean>)

    Higher order function returning a function that performs the isErr method on the provided Result.

    The returned function checks if the value is Err.

      • <V, E>(): Mapper<Result<V, E>, boolean>
      • Type Parameters

        • V
        • E extends Error

        Returns Mapper<Result<V, E>, boolean>

        A function that checks if the value is Err.

  • isInstance: (<V, E>(value: unknown) => value is Result<V, E>)

    Checks if the value is an instance of the Result jonad.

      • <V, E>(value): value is Result<V, E>
      • Type Parameters

        • V
        • E extends Error

        Parameters

        • value: unknown

          The value to check.

        Returns value is Result<V, E>

        true if the value is an instance of Result, false otherwise.

  • isOk: (<V, E>() => Mapper<Result<V, E>, boolean>)

    Higher order function returning a function that performs the isOk method on the provided Result.

    The returned function checks if the value is Ok.

      • <V, E>(): Mapper<Result<V, E>, boolean>
      • Type Parameters

        • V
        • E extends Error

        Returns Mapper<Result<V, E>, boolean>

        A function that checks if the value is Ok.

  • map: (<V, E, T>(mapper: Mapper<V, T>) => Mapper<Result<V, E>, Result<T, E>>)

    Higher order function returning a function that performs the map method on the provided Result.

    The returned function maps the value if it is an Ok.

  • mapErr: (<V, E, T>(mapper: Mapper<E, T>) => Mapper<Result<V, E>, Result<V, T>>)

    Higher order function returning a function that performs the mapErr method on the provided Result.

    The returned function maps the error if it is an Err.

      • <V, E, T>(mapper): Mapper<Result<V, E>, Result<V, T>>
      • Type Parameters

        • V
        • E extends Error
        • T extends Error

        Parameters

        • mapper: Mapper<E, T>

          The mapper function to apply to the error if it is an Err.

        Returns Mapper<Result<V, E>, Result<V, T>>

        A function that maps the error if it is an Err.

  • ok: (<V, E>(value: V) => Result<V, E>)

    Creates a new Ok instance.

      • <V, E>(value): Result<V, E>
      • Type Parameters

        • V
        • E extends Error

        Parameters

        • value: V

          The value to wrap.

        Returns Result<V, E>

        A new Ok instance.

  • someOrNone: (<V, E>() => Mapper<Result<V, E>, Option<V>>)

    Higher order function returning a function that performs the someOrNone method on the provided Result.

    The returned function maps the Result into an Option.

  • transpose: (<V, E>(result: Result<Option<V>, E>) => Option<Result<V, E>>)

    Transposes a Result of an Option into an Option of a Result.

      • <V, E>(result): Option<Result<V, E>>
      • Type Parameters

        • V
        • E extends Error

        Parameters

        Returns Option<Result<V, E>>

        An Option with the value if the Result is an Ok, otherwise None.

  • valueOr: (<V, E>(fallback: V | Mapper<E, V>) => Mapper<Result<V, E>, V>)

    Higher order function returning a function that performs the valueOr method on the provided Result.

    The returned function returns the value if it is an Ok, otherwise a default value.

      • <V, E>(fallback): Mapper<Result<V, E>, V>
      • Type Parameters

        • V
        • E extends Error

        Parameters

        • fallback: V | Mapper<E, V>

          The default value (as-is or produced from a callback) to return if the value is an Err.

        Returns Mapper<Result<V, E>, V>

        A function that returns the value if it is an Ok, otherwise the default value.