Example #1
0
        public void Initialize_Either_From_Left_Should_Return_Left()
        {
            int num = 1;
            Either <int, string> e = EitherExt.Left(num);

            e.Match(i => Assert.Equal(num, i),
                    s => Assert.True(false));
        }
Example #2
0
        public void Map_Left_To_Trasnform_Modifies_Right_only()
        {
            string s = "10";
            Either <string, int> Either = EitherExt.Left(s);

            var e = Either.Map(xfrm);

            e.Match(i => Assert.Equal(int.Parse(s) * 2, i),
                    i2 => Assert.False(true));
        }
Example #3
0
        public void SelectMany_combine_many_either_L_R_into_single_scope()
        {
            Either <string, int> e1 = EitherExt.Right(1);
            Either <string, int> e2 = EitherExt.Left("2");
            Either <string, int> e3 = EitherExt.Right(3);
            Either <string, int> e4 = EitherExt.Left("4");
            var res = from n1 in e1
                      from n2 in e2
                      from n3 in e3
                      from n4 in e4
                      select n1 + n2 + n3 + n4;

            res.Match(s => Assert.Equal("2", s),
                      v => Assert.Equal(1 + 2 + 3, v));
        }
Example #4
0
        public void SelectMany_combine_many_either_L_R_into_single_scope_it_stop_as_soon_see_left()
        {
            Either <string, int> e1 = EitherExt.Right(1);
            Either <string, int> e2 = EitherExt.Left("2");
            Either <string, int> e3 = EitherExt.Right(3);
            Either <string, int> e4 = EitherExt.Left("4");
            var res = from n1 in e1.RightIfPresent()
                      from n2 in e2.RightIfPresent()
                      from n3 in e3.RightIfPresent()
                      from n4 in e4.RightIfPresent()
                      select n1 + n2 + n3 + n4;

            //var res1 = res.Flip();
            res.Match(() => Assert.True(true),
                      i => Assert.False(true));
        }