import { Task } from "https://deno.land/x/eitherway@0.10.0/lib/async/mod.ts";
Use this to construct a Task<T, E>
from the return value of a fallible
function.
Examples
Example 1
Example 1
import { Task } from "https://deno.land/x/eitherway/mod.ts";
async function rand(): Promise<number> {
throw new TypeError("Oops");
}
function toTypeError(e: unknown): TypeError {
if (e instanceof TypeError) return e;
return TypeError("Unexpected error", { cause: e });
}
const task: Task<number, TypeError> = Task.fromFallible(
rand,
toTypeError,
)