import { asInfallible } from "https://deno.land/x/eitherway@0.10.0/lib/core/result.ts";
Use this as errMapFn
to indicate that a function or Promise to be lifted
into a Result or Task context is infallible
If the lifted function or Promise throws an exception, the error will be propagated
Examples
Example 1
Example 1
import { assert } from "./assert.ts"
import { Err, Ok, Result, asInfallible } from "./result.ts"
//Let's re-implement `Result.from`
const customFromImpl = <T>(fn: () => T) => Result.fromFallible(fn, asInfallible);
const getNumber = () => 42;
const fromOriginal = Result.from(getNumber);
const fromCustom = customFromImpl(getNumber);
assert(fromOriginal.isOk() === fromCustom.isOk());