示例#1
0
        public static void IntLiftInfinityTest()
        {
            var intPlus    = new Monoid <int>(0, (x, y) => x + y);
            var intPlusInf = intPlus.LiftMonoidWithInfinity();

            Assert.True(intPlusInf.Neutral.HasValue);
            Assert.Equal(0, intPlusInf.Neutral.Value());

            var r = intPlusInf.Op(Maybe.Just(3), Maybe.Just(8));

            Assert.True(r.HasValue);
            Assert.Equal(11, r.Value());

            r = intPlusInf.Op(Maybe.Nothing <int>(), Maybe.Just(8));
            Assert.False(r.HasValue);

            r = intPlusInf.Op(Maybe.Just(3), Maybe.Nothing <int>());
            Assert.False(r.HasValue);

            r = intPlusInf.Op(Maybe.Nothing <int>(), Maybe.Nothing <int>());
            Assert.False(r.HasValue);
        }