import { Task } from "https://deno.land/x/eitherway@0.10.0/lib/async/mod.ts";
Use this lift a function into a Task
context, by composing the wrapped
function with a Result
constructor and an error mapping function.
If no constructor is provided, Ok
is used as a default.
This higher order function is especially useful to intergrate 3rd party
code into your Task
pipelines.
Examples
Example 1
Example 1
import { Err, Ok, Result, Task } from "https://deno.land/x/eitherway/mod.ts";
async function toSpecialString(s: string): Promise<string> {
if (s.length % 3 === 0) return s;
throw TypeError("Not confomrming to schema");
}
function toTypeError(e: unknown): TypeError {
if (e instanceof TypeError) return e;
return TypeError("Unexpected error", { cause: e });
}
const lifted = Task.liftFallible(toSpecialString, toTypeError);
const task: Task<string, TypeError> = Task.succeed("abcd").andThen(lifted);