import { async_either } from "https://deno.land/x/fun@v2.0.0-alpha.6/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.
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import * as TE from "./async_either.ts";
import * as E from "./either.ts";
const _fetch = TE.tryCatch(
fetch,
(error, args) => ({ message: "Fetch Error", error, args })
);
const t1 = await _fetch("blah")();
assertEquals(t1.tag, "Left");
const t2 = await _fetch("https://deno.land/")();
assertEquals(t2.tag, "Right");
Returns
(...as: AS) => AsyncEither<B, A>