tryCatch
import { tryCatch } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/either.ts";Execute a function that might throw an exception and convert the result to an Either. If the function throws, the error is caught and converted to a Left using the onError function. If successful, the result is wrapped in Right.
@example
import * as E from "./either.ts";
const safeDivide = E.tryCatch(
(a: number, b: number) => a / b,
(error) => `Division failed: ${error}`
);
const result1 = safeDivide(10, 2); // Right(5)
const result2 = safeDivide(10, 0); // Left("Division failed: Error: Division by zero")
function tryCatch<E, A, AS extends unknown[]>(fn: (...as: AS) => A, onError: (e: unknown, as: AS) => E): (...as: AS) => Either<E, A>;