import { async_either } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { tryCatch } = async_either;
Wraps a Async of A in a try-catch block which upon failure returns B instead. Upon success returns a Right and Left for a failure.
Examples
Example 1
Example 1
import * as TE from "./async_either.ts";
import * as E from "./either.ts";
const tryFetch = TE.tryCatch(
fetch,
(error, args) => ({ message: "Fetch Error", error, args })
);
const result1 = await tryFetch("blah")(); // Left(ErrorStruct)
const result2 = await tryFetch("https://deno.land/")(); // Right(*Deno Website*)
Returns
(...as: AS) => AsyncEither<B, A>