Exemple #1
0
        public MaybeMonad <TTo> BindM <TTo>(Func <T, MaybeMonad <TTo> > f)
        {
            if (isNothing)
            {
                return(MaybeMonad <TTo> .Nothing());
            }

            var newM = f(value);

            return(newM);
        }
Exemple #2
0
        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;
        }
Exemple #3
0
 public Container(int capacity)
 {
     this.capacity = capacity;
     currentCapa   = new MaybeMonad <int>(0);
 }