// Monad
 public static IMaybe <TResult> SelectMany <T, TResult>(
     this IMaybe <T> source,
     Func <T, IMaybe <TResult> > selector)
 {
     return(source.Accept(
                new SelectManyMaybeVisitor <T, TResult>(selector)));
 }
Esempio n. 2
0
        public void SimpleQueryExpressionWorks()
        {
            IMaybe <int>    sut    = new Just <int>(42);
            IMaybe <string> actual = from i in sut
                                     select i.ToString();

            Assert.Equal(
                "42",
                actual.Accept(new FromMaybeVisitor <string>("nothing")));
        }
 public static T GetValueOrDefault <T>(this IMaybe <T> source, T defaultValue)
 {
     return(source.Accept(new FromMaybeVisitor <T>(defaultValue)));
 }
 public static bool IsNothing <T>(this IMaybe <T> source)
 {
     return(source.Accept(new IsNothingVisitor <T>()));
 }
Esempio n. 5
0
 // Monad
 public static IMaybe <T> Flatten <T>(this IMaybe <IMaybe <T> > source)
 {
     return(source.Accept(new FlattenMaybeVisitor <T>()));
 }
Esempio n. 6
0
 public static IChurchBoolean IsJust <T>(this IMaybe <T> m)
 {
     return(m.Accept(new IsJustMaybeVisitor <T>()));
 }