Similar to Opt.chain (in other languages called bind or >>=), but supports more functions passed at once (resembles do notation in Haskell).
It is used to model a sequence of operations where each operation can fail (can return None).
// does addition when first argument is number constf1 = (x: string | number) => (y: number) =>opt(x).narrow(isNumber).map(z=>z + y); // passes only even numbers constf2 = (x: number): Opt<number> =>x % 2 === 0 ? opt(x) : none;
Similar to Opt.chain (in other languages called
bind
or>>=
), but supports more functions passed at once (resemblesdo
notation in Haskell). It is used to model a sequence of operations where each operation can fail (can return None).