Example #1
0
        public void EitherIterateWhenLeft()
        {
            string expected             = "Hello World";
            string result               = "World";
            Either <string, int> either = "Hello ";

            EitherModule.Iterate(
                right => right += right * 2,
                left => result  = string.Concat(left, result)
                , either);

            Assert.AreEqual(expected, result);
        }
Example #2
0
        public void EitherIterateWhenRight()
        {
            int expected = 20;
            int result   = 10;
            Either <string, int> either = 10;

            EitherModule.Iterate(
                right => result += right,
                left => string.Concat(left, left)
                , either);

            Assert.AreEqual(expected, result);
        }
Example #3
0
 /// <summary>Applies the given functions to <see cref="Either{TLeft, TRight}"/> value depends on its state.</summary>
 /// <typeparam name="TLeft">The type of the left value.</typeparam>
 /// <typeparam name="TRight">The type of the right value.</typeparam>
 /// <param name="actionWhenLeft">The action to apply to left value of input <paramref name="either"/>.</param>
 /// <param name="actionWhenRight">The action to apply to right value of input <paramref name="either"/>.</param>
 /// <param name="either">the input either.</param>
 public static void Iterate <TLeft, TRight>(this Either <TLeft, TRight> either, Action <TRight> actionWhenRight, Action <TLeft> actionWhenLeft)
 => EitherModule.Iterate(actionWhenRight, actionWhenLeft, either);