Function safeCatch

  • Tries to execute function transform. In case of an exception, it returns fallback instead.

    Example

    import { safeCatch } from "flurp";

    const tryMath = E.safeCatch((s: string) => Math[s](1), null);
    tryMath("log"); // 0
    tryMath("no-such-function") // null

    Type Parameters

    • T

    • U

    Parameters

    • transform: ((val: T) => U)
        • (val: T): U
        • Parameters

          • val: T

          Returns U

    • fallback: U

    Returns ((val: T) => U)

      • (val: T): U
      • Parameters

        • val: T

        Returns U