@pleisto/active-support
    Preparing search index...

    Class Err<T, E>

    Type Parameters

    • T
    • E

    Implements

    • IResult<T, E>
    Index

    Constructors

    • Type Parameters

      • T
      • E

      Parameters

      • error: E

      Returns Err<T, E>

    Properties

    error: E

    Methods

    • This method is unsafe, and should only be used in a test environments

      Takes a Result<T, E> and returns a T when the result is an Ok, otherwise it throws a custom object.

      Parameters

      • Optionalconfig: ErrorConfig

      Returns T

    • This method is unsafe, and should only be used in a test environments

      takes a Result<T, E> and returns a E when the result is an Err, otherwise it throws a custom object.

      Parameters

      • Optional_: ErrorConfig

      Returns E

    • Returns Generator<Err<never, E>, T>

    • This "tee"s the current value to an passed-in computation such as side effect functions but still returns the same current value as the result.

      This is useful when you want to pass the current result to your side-track work such as logging but want to continue main-track work after that. This method does not care about the result of the passed in computation.

      Parameters

      • _f: (t: T) => unknown

      Returns Result<T, E>

    • Similar to map Except you must return a new Result.

      This is useful for when you need to do a subsequent computation using the inner T value, but that computation might fail. Additionally, andThen is really useful as a tool to flatten a Result<Result<A, E2>, E1> into a Result<A, E2> (see example below).

      Type Parameters

      • R extends Result<unknown, unknown>

      Parameters

      • _f: (t: T) => R

      Returns Result<InferOkTypes<R>, E | InferErrTypes<R>>

    • Type Parameters

      • U
      • F

      Parameters

      Returns Result<U, E | F>

    • Similar to andTee except error result of the computation will be passed to the downstream in case of an error.

      This version is useful when you want to make side-effects but in case of an error, you want to pass the error to the downstream.

      Type Parameters

      • F

      Parameters

      Returns Result<T, E | F>

    • Similar to map Except you must return a new Result.

      This is useful for when you need to do a subsequent async computation using the inner T value, but that computation might fail. Must return a ResultAsync

      Type Parameters

      • U
      • F

      Parameters

      Returns ResultAsync<U, E | F>

    • Maps a Result<T, E> to ResultAsync<U, E> by applying an async function to a contained Ok value, leaving an Err value untouched.

      Type Parameters

      • U

      Parameters

      • _f: (t: T) => Promise<U>

      Returns ResultAsync<U, E>

    • Used to check if a Result is an Err

      Returns this is Err<T, E>

      true if the result is an Err variant of Result

    • Used to check if a Result is an OK

      Returns this is Ok<T, E>

      true if the result is an OK variant of Result

    • Maps a Result<T, E> to Result<U, E> by applying a function to a contained Ok value, leaving an Err value untouched.

      Type Parameters

      • A

      Parameters

      • _f: (t: T) => A

      Returns Result<A, E>

      the result of applying f or an Err untouched

    • Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err value, leaving an Ok value untouched.

      This function can be used to pass through a successful result while handling an error.

      Type Parameters

      • U

      Parameters

      • f: (e: E) => U

        a function to apply to the error Err value

      Returns Result<T, U>

    • Given 2 functions (one for the Ok variant and one for the Err variant) execute the function that matches the Result variant.

      Match callbacks do not necessitate to return a Result, however you can return a Result if you want to.

      match is like chaining map and mapErr, with the distinction that with match both functions must have the same return type.

      Type Parameters

      • A
      • B = A

      Parameters

      • _ok: (t: T) => A
      • err: (e: E) => B

      Returns A | B

    • Takes an Err value and maps it to a Result<T, SomeNewType>.

      This is useful for error recovery.

      Type Parameters

      • R extends Result<unknown, unknown>

      Parameters

      • f: (e: E) => R

        A function to apply to an Err value, leaving Ok values untouched.

      Returns Result<T | InferOkTypes<R>, InferErrTypes<R>>

    • Type Parameters

      • U
      • A

      Parameters

      Returns Result<T | U, A>

    • This "tee"s the current Err value to an passed-in computation such as side effect functions but still returns the same Err value as the result.

      This is useful when you want to pass the current Err value to your side-track work such as logging but want to continue error-track work after that. This method does not care about the result of the passed in computation.

      Parameters

      • f: (t: E) => unknown

        The function to apply to the current Err value

      Returns Result<T, E>

    • Returns Generator<Err<never, E>, T>

      will be removed in 9.0.0.

      You can use safeTry without this method.

      safeTry(function* () {
      const okValue = yield* yourResult
      })

      Emulates Rust's ? operator in safeTry's body. See also safeTry.

    • Unwrap the Ok value, or return the default if there is an Err

      Type Parameters

      • A

      Parameters

      • v: A

        the default value to return if there is an Err

      Returns T | A