Skip to main content

mapTry

Callable

  • mapTry<U, T>(x: T, fn: (e: Success<T>) => U): AsTry<U>

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

    Example

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

    mapTry(new Error("foobar"), s => `${s}${s}`)
    // => Error("foobar")

    Type parameters

    • U

      The transformed type.

    • T: unknown

      The input type.

    Parameters

    • x: T

      The Try to transform.

    • fn: (e: Success<T>) => U

      The success transform.

    Returns AsTry<U>