resA
or fn()
.
import { err, ok, orElse } from "./result.ts";
import { assertEquals } from "../deps.ts";
const sq = orElse((x: number) => ok<number>(x * x));
const residual = orElse((x: number) => err<number>(x));
assertEquals(sq(sq(ok(2))), ok(2));
assertEquals(sq(residual(ok(2))), ok(2));
assertEquals(residual(sq(err(3))), ok(9));
assertEquals(residual(residual(err(3))), err(3));
Generated using TypeDoc
Returns
fn()
ifresA
is anErr
, otherwise returns the successresA
. The order of arguments is reversed because of that it is useful for partial applying.