optB
or a None
.
import { andThen, Option, some, none } from "./option.ts";
import { assertEquals } from "../deps.ts";
const sqrtThenToString = (num: number): Option<string> =>
0 <= num ? some(Math.sqrt(num).toString()) : none();
const applied = andThen(sqrtThenToString);
assertEquals(applied(some(4)), some("2"));
assertEquals(applied(some(-1)), none());
assertEquals(applied(none()), none());
Generated using TypeDoc
Returns
None
ifoptA
isNone
, otherwise callsoptB
and return the result. This is an implementation ofFlatMap
. The order of arguments is reversed because of that it is useful for partial applying.