public MaybeMonad <TTo> BindM <TTo>(Func <T, MaybeMonad <TTo> > f) { if (isNothing) { return(MaybeMonad <TTo> .Nothing()); } var newM = f(value); return(newM); }
public void change(int diff) { // if current capacity is out of range // the container will be broken and not working var capaM = currentCapa.BindM(capa => { if (capa + diff < 0 || capa + diff > capacity) { return(MaybeMonad <int> .Nothing()); } else { return(MaybeMonad <int> .Return(capa + diff)); } }); currentCapa = capaM; }