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

            (Option <string> Left, Option <int> Right)tuple = EitherModule.ToTuple(either);

            string result = tuple.Left.Match(value => value, () => string.Empty);

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

            (Option <string> Left, Option <int> Right)tuple = EitherModule.ToTuple(either);

            int result = tuple.Right.Match(value => value, () => 0);

            Assert.AreEqual(expected, result);
        }
Example #3
0
 /// <summary>
 /// Convert the <see cref="Either{TLeft, TRight}"/> to a <see cref="Tuple{T1,T2}"/> where T1 and T2 are <see cref="Option{T}"/> value of <typeparamref name="TLeft"/> and <typeparamref name="TRight"/> respectively.
 /// </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 <see cref="Tuple{T1,T2}"/> where T1 and T2 are <see cref="Option{T}"/> value of <typeparamref name="TLeft"/> and <typeparamref name="TRight"/> respectively.
 /// The Tuple left value (Item1) is <see cref="Option{T}.Some(T)"/> when <paramref name="either"/> <see cref="Either{TLeft, TRight}.IsLeft"/>, otherwise is <see cref="Option{T}.None"/>
 /// The Tuple right value (Item2) is <see cref="Option{T}.Some(T)"/> when <paramref name="either"/> <see cref="Either{TLeft, TRight}.IsRight"/>, otherwise is <see cref="Option{T}.None"/>
 /// </returns>
 public static (Option <TLeft>, Option <TRight>) ToTuple <TLeft, TRight>(this Either <TLeft, TRight> either)
 => EitherModule.ToTuple(either);