Skip to main content

recoverTry

Callable

  • recoverTry<U, T>(x: T, recover: (e: Error) => U): AsTry<U> | T

  • Map the value of the Try when it is a Failure.

    Example

    recoverTry("foobar", s => `${s}${s}`)
    // => "foobar"

    recoverTry(new Error("foobar"), s => "bar")
    // => "bar"

    Type parameters

    • U

      The transformed type.

    • T: unknown

      The input type.

    Parameters

    • x: T

      The Try to transform.

    • recover: (e: Error) => U

      The failure transform.

    Returns AsTry<U> | T