Exemple #1
0
        public void EitherExistsFalseWhenLeft()
        {
            bool expected = false;
            Either <string, int> either = "Hello World";
            bool result =
                EitherModule.Exists(
                    right => right == 10,
                    left => left == "Test"
                    , either);

            Assert.AreEqual(expected, result);
        }
Exemple #2
0
        public void EitherExistsTrueWhenRight()
        {
            bool expected = true;
            Either <string, int> either = 10;
            bool result =
                EitherModule.Exists(
                    right => right == 10,
                    left => left == "Test"
                    , either);

            Assert.AreEqual(expected, result);
        }
Exemple #3
0
 /// <summary>
 ///  Returns true if the given predicate functions return true when applied to either value.
 ///  Otherwise, returns false.
 /// </summary>
 /// <typeparam name="TLeft">The type of the left value.</typeparam>
 /// <typeparam name="TRight">The type of the right value.</typeparam>
 /// <param name="predicateWhenLeft">A function that evaluates whether the left value contained in the option is valid or not.</param>
 /// <param name="predicateWhenRight">A function that evaluates whether the right value contained in the option is valid or not.</param>
 /// <param name="either">the input either.</param>
 /// <returns>
 /// Returns true if the given predicate functions return true when applied to either value.
 /// </returns>
 public static bool Exists <TLeft, TRight>(this Either <TLeft, TRight> either, Func <TRight, bool> predicateWhenRight, Func <TLeft, bool> predicateWhenLeft)
 => EitherModule.Exists(predicateWhenRight, predicateWhenLeft, either);