コード例 #1
0
        public void SecondFunctorLawHoldsForMapRight(IEitherValueType <string, int> e)
        {
            char f(bool b) => b ? 'T' : 'F';
            bool g(int i) => i % 2 == 0;

            Assert.AreEqual(e.MapRight(x => f(g(x))), e.MapRight(g).MapRight(f));
        }
コード例 #2
0
        public void SecondFunctorLawHoldsForMapLeft(IEitherValueType <string, int> e)
        {
            bool f(int x) => x % 2 == 0;
            int g(string s) => s.Length;

            Assert.AreEqual(e.MapLeft(x => f(g(x))), e.MapLeft(g).MapLeft(f));
        }
コード例 #3
0
        public void ConsistencyLawHolds(IEitherValueType <string, int> e)
        {
            bool f(string s) => string.IsNullOrWhiteSpace(s);
            DateTime g(int i) => new DateTime(i);

            Assert.AreEqual(e.Map(f, g), e.MapRight(g).MapLeft(f));
            Assert.AreEqual(
                e.MapLeft(f).MapRight(g),
                e.MapRight(g).MapLeft(f));
        }
コード例 #4
0
        public void MapCompositionLawHolds(IEitherValueType <string, int> e)
        {
            bool f(int x) => x % 2 == 0;
            int g(string s) => s.Length;
            char h(bool b) => b ? 'T' : 'F';
            bool i(int x) => x % 2 == 0;

            Assert.AreEqual(
                e.Map(x => f(g(x)), y => h(i(y))),
                e.Map(g, i).Map(f, h));
        }
コード例 #5
0
 public void MapOnExtensionMethodObeysFirstFunctorLaw(IEitherValueType <string, int> e)
 {
     e.Should().Be(e.Map(l => Identity(l), r => Identity(r)));
 }
コード例 #6
0
 public void MapLeftObeysFirstFunctorLaw(IEitherValueType <string, int> e)
 {
     e.Should().Be(e.MapLeft(l => Identity(l)));
 }