Ejemplo n.º 1
0
 // 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)));
 }
Ejemplo 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")));
        }
Ejemplo n.º 3
0
 public static T GetValueOrDefault <T>(this IMaybe <T> source, T defaultValue)
 {
     return(source.Accept(new FromMaybeVisitor <T>(defaultValue)));
 }
Ejemplo n.º 4
0
 public static bool IsNothing <T>(this IMaybe <T> source)
 {
     return(source.Accept(new IsNothingVisitor <T>()));
 }
Ejemplo n.º 5
0
 // Monad
 public static IMaybe <T> Flatten <T>(this IMaybe <IMaybe <T> > source)
 {
     return(source.Accept(new FlattenMaybeVisitor <T>()));
 }
Ejemplo n.º 6
0
 public static IChurchBoolean IsJust <T>(this IMaybe <T> m)
 {
     return(m.Accept(new IsJustMaybeVisitor <T>()));
 }