ConstReturns None if optA is None, otherwise calls optB and return the result. This is an implementation of FlatMap. The order of arguments is reversed because of that it is useful for partial applying.
optB or a None.
const sqrtThenToString = (num: number): Option<string> =>
0 <= num ? some(Math.sqrt(num).toString()) : none();
const applied = andThen(sqrtThenToString);
expect(applied(some(4))).toStrictEqual(some("2"));
expect(applied(some(-1))).toStrictEqual(none());
expect(applied(none())).toStrictEqual(none());
The alias of
andThen.