コード例 #1
0
ファイル: Monad.cs プロジェクト: zerke/Thinking-dumps
        public MaybeMonad <TTo> BindM <TTo>(Func <T, MaybeMonad <TTo> > f)
        {
            if (isNothing)
            {
                return(MaybeMonad <TTo> .Nothing());
            }

            var newM = f(value);

            return(newM);
        }
コード例 #2
0
ファイル: Monad.cs プロジェクト: zerke/Thinking-dumps
        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;
        }