import { Result } from "https://deno.land/x/eitherway@0.10.0/lib/core/result.ts";
const { lift } = Result;
Use this to lift a function into a Result
context, by composing
the wrapped function with a Result
constructor.
If no constructor is provided, Ok
is used as default.
This is useful for integrating 3rd party code without the need to manually wrap it.
Examples
Example 1
Example 1
import { assert } from "./assert.ts";
import { Err, Ok, Result } from "./mod.ts";
function powerOfTwo(n: number): number {
return Math.pow(2, n);
}
const lifted = Result.lift(powerOfTwo);
const res = Ok(2).andThen(lifted);
assert(res.isOk() === true);
assert(res.unwrap() === 4);