Пример #1
0
        public void SelectBothCompositionLawHolds(IEither <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.Equal(
                e.SelectBoth(x => f(g(x)), y => h(i(y))),
                e.SelectBoth(g, i).SelectBoth(f, h));
        }
Пример #2
0
        public void ConsistencyLawHolds(IEither <string, int> e)
        {
            bool f(string s) => string.IsNullOrWhiteSpace(s);
            DateTime g(int i) => new DateTime(i);

            Assert.Equal(e.SelectBoth(f, g), e.SelectRight(g).SelectLeft(f));
            Assert.Equal(
                e.SelectLeft(f).SelectRight(g),
                e.SelectRight(g).SelectLeft(f));
        }
Пример #3
0
 public static IEither <L, R1> SelectRight <L, R, R1>(
     this IEither <L, R> source,
     Func <R, R1> selector)
 {
     return(source.SelectBoth(l => l, selector));
 }
Пример #4
0
 public static IEither <L1, R> SelectLeft <L, L1, R>(
     this IEither <L, R> source,
     Func <L, L1> selector)
 {
     return(source.SelectBoth(selector, r => r));
 }
Пример #5
0
 public void SelectBothObeysIdentityLaw(IEither <string, int> e)
 {
     Assert.Equal(e, e.SelectBoth(Id, Id));
 }