예제 #1
0
 public static Maybe2 <B> Bind <A, B>(this Maybe2 <A> a, Func <A, Maybe2 <B> > func)
 {
     return(a.HasValue ? func(a.Value) : Maybe2 <B> .Nothing());
 }
예제 #2
0
        public static void Maybe2Composition()
        {
            Func <int, Maybe2 <int> > add2 = x => (x != 0) ? Maybe2 <int> .Just(x + 2) : Maybe2 <int> .Nothing();

            Func <int, Maybe2 <int> > multiplyBy2 = x => (x != 0) ? Maybe2 <int> .Just(x * 2) : Maybe2 <int> .Nothing();

            Func <int, Maybe2 <int> > add2MultiplyBy2 = x => add2(x).Bind(multiplyBy2);
            var result = add2MultiplyBy2(3);

            Console.WriteLine("result = {0}", result);
        }