Example #1
0
        public void EitherSwapWhenRight2()
        {
            string expected                    = string.Empty;
            Either <string, int> either        = 10;
            Either <int, string> swappedEither =
                EitherModule.Swap(either);

            string result = swappedEither.Match(right => right, left => string.Empty);

            Assert.AreEqual(expected, result);
        }
Example #2
0
        public void EitherSwapWhenLeft()
        {
            int expected = 0;
            Either <string, int> either        = "Hello";
            Either <int, string> swappedEither =
                EitherModule.Swap(either);

            int result = swappedEither.Match(right => 0, left => left);

            Assert.AreEqual(expected, result);
        }
Example #3
0
 /// <summary>
 /// Creates a new <see cref="Either{TLeft, TRight}"/> value by swapping <see cref="Either{TLeft, TRight}.Left"/> and <see cref="Either{TLeft, TRight}.Right"/> values.
 /// </summary>
 /// <typeparam name="TLeft">The type of the left value.</typeparam>
 /// <typeparam name="TRight">The type of the right value.</typeparam>
 /// <param name="either">the input either.</param>
 /// <returns>
 /// Returns a new <see cref="Either{TLeft, TRight}"/> value by swapping <see cref="Either{TLeft, TRight}.Left"/> and <see cref="Either{TLeft, TRight}.Right"/> values.
 /// </returns>
 public static Either <TRight, TLeft> Swap <TLeft, TRight>(this Either <TLeft, TRight> either)
 => EitherModule.Swap(either);