Ejemplo n.º 1
0
        public IMonad <A> Where(Func <A, int, bool> predicate)
        {
            Maybe <A> result = new Nothing <A>();

            if (!this.isNothing && predicate(aValue, 0))
            {
                result = new Just <A>(aValue);
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// If this is not nothing, then the result monad is a new Maybe<A> with the value inside the other monad.
        /// </summary>
        /// <param name="otherMonad">The other monad.</param>
        /// <returns>The new monad.</returns>
        public IMonad <A> Concat(IMonad <A> otherMonad)
        {
            Maybe <A> resultMonad = new Nothing <A>();

            if (!isNothing)
            {
                resultMonad = new Just <A>(otherMonad.Return());
            }
            return(resultMonad);
        }
Ejemplo n.º 3
0
        public IMonad <C> Com <B, C>(Func <A, B, C> function, IMonad <B> mOther)
        {
            IMonad <C> resultMonad = new Nothing <C>();  // New Nothing<B> maybe

            if (!isNothing && !(mOther is Nothing <B>))
            {
                foreach (var otherValue in mOther)
                {
                    resultMonad = new Just <C>(function(aValue, otherValue));
                }
            }
            return(resultMonad);
        }
Ejemplo n.º 4
0
        public IMonad <B> App <B>(IMonad <Func <A, B> > functionMonad)
        {
            Maybe <B> result = new Nothing <B>();

            if (this is Just <A> && functionMonad != null)
            {
                foreach (var function in functionMonad)
                {
                    if (function != null)
                    {
                        result = new Just <B>(functionMonad.Return()(aValue));
                    }
                }
                if (result == null)
                {
                    result = new Nothing <B>();
                }
            }
            return(result);
        }