Exemplo n.º 1
0
        public static TMonadPlus Guard <TMonadPlus>(bool b)
            where TMonadPlus : IMonadPlus <Unit>
        {
            var monadPlusAdapter = MonadPlusAdapterRegistry.Get <Unit>(typeof(TMonadPlus));

            return((TMonadPlus)(b ? monadPlusAdapter.Return(new Unit()) : monadPlusAdapter.MZero));
        }
Exemplo n.º 2
0
        public static TMonadPlus MSum <TMonadPlus, TA>(IEnumerable <IMonadPlus <TA> > ms)
            where TMonadPlus : IMonadPlus <TA>
        {
            var monadPlusAdapter = MonadPlusAdapterRegistry.Get <TA>(typeof(TMonadPlus));

            return((TMonadPlus)ms.FoldRight(monadPlusAdapter.MZero, monadPlusAdapter.MPlus));
        }
Exemplo n.º 3
0
        public static TMonadPlus LookupM <TMonadPlus, TA, TB>(TA k, IEnumerable <Tuple <TA, TB> > alist)
            where TMonadPlus : IMonadPlus <TB>
        {
            var monadPlusAdapter = MonadPlusAdapterRegistry.Get <TB>(typeof(TMonadPlus));

            return(LookupMInternal <TMonadPlus, TA, TB>(k, alist, monadPlusAdapter));
        }
Exemplo n.º 4
0
        public static TMonadPlus MFilter <TMonadPlus, TA>(Func <TA, bool> p, IMonadPlus <TA> ma)
            where TMonadPlus : IMonadPlus <TA>
        {
            var monadPlusAdapter = MonadPlusAdapterRegistry.Get <TA>(typeof(TMonadPlus));

            return((TMonadPlus)monadPlusAdapter.Bind(
                       ma, a => p(a) ? monadPlusAdapter.Return(a) : monadPlusAdapter.MZero));
        }
 public void Test1()
 {
     var maybeMonadPlusAdapter = MonadPlusAdapterRegistry.Get<int>(typeof (Maybe<>));
     var maybe = (Maybe<int>)maybeMonadPlusAdapter.Return(42);
     Assert.That(maybe.FromJust, Is.EqualTo(42));
 }
Exemplo n.º 6
0
 public MonadPlusAdapter <TA> GetMonadPlusAdapter()
 {
     return(MonadPlusAdapterRegistry.Get <TA>(typeof(Maybe <>)));
 }