Skip to main content

asTry

Callable

  • asTry<T>(x: T): AsTry<T>

  • Take an expression and evaluate it. When the expression throws it will be converted to a Try Failure.

    Example

    asTry("foobar")
    // => "foobar"

    asTry(() => "foobar")
    // => "foobar"

    asTry(async () => "foobar")
    // => Promise<"foobar">

    Type parameters

    • T: unknown

      The expression type.

    Parameters

    • x: T

      The expression to evaluate.

    Returns AsTry<T>

    The unpacked value.