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)); }
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)); }
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)); }
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)); }
public MonadPlusAdapter <TA> GetMonadPlusAdapter() { return(MonadPlusAdapterRegistry.Get <TA>(typeof(Maybe <>))); }