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());
Returns
NoneifoptAisNone, otherwise callsoptBand return the result. This is an implementation ofFlatMap. The order of arguments is reversed because of that it is useful for partial applying.