Exemplo n.º 1
0
        public void BindRightIdentity()
        {
            // m >>= return == m
            var m = EitherString.Return(5);

            Assert.That(m.Bind(EitherString.Return), Is.EqualTo(m));
        }
Exemplo n.º 2
0
        public void BindLeftIdentity()
        {
            // (return x) >>= f == f x
            const int x = 5;
            Func <int, Either <string, int> > f = n => EitherString.Right(n * n);

            Assert.That(EitherString.Return(x).Bind(f), Is.EqualTo(f(x)));
        }
Exemplo n.º 3
0
        public void BindAssociativity()
        {
            // (m >>= f) >>= g == m >>= (\x -> f x >>= g)
            Func <int, Either <string, int> >    f = n => EitherString.Right(n * n);
            Func <int, Either <string, string> > g = n => EitherString.Right(Convert.ToString(n));
            var m = EitherString.Return(5);

            Assert.That(m.Bind(f).Bind(g), Is.EqualTo(m.Bind(x => f(x).Bind(g))));
        }