Exemple #1
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 override Monad <A> Concatenate(Monad <A> otherMonad)
 {
     if (!isNothing)
     {
         aValue = otherMonad.Return();
     }
     return(this);
 }
Exemple #2
0
        public override Monad <B> App <B>(Monad <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);
        }
Exemple #3
0
 public static Maybe <T> ToMaybe <T>(this Monad <T> value)
 {
     return(value.Return());
 }
Exemple #4
0
 public static Identity <T> ToIdentity <T>(this Monad <T> value)
 {
     return(new Identity <T>(value.Return()));
 }
Exemple #5
0
 public override Monad <A> Concatenate(Monad <A> otherMonad)
 {
     this.idValue = otherMonad.Return();
     return(this);
 }
Exemple #6
0
 public Monad<A> Set(Monad<A> other)
 {
     return Pure(other.Return());
 }