Example #1
0
        public void EitherToOptionRightWhenLeft()
        {
            int expected = 0;
            Either <string, int> either       = "Hello World";
            Option <int>         optionResult =
                EitherModule.ToOptionRight(either);

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

            Assert.AreEqual(expected, result);
        }
Example #2
0
 /// <summary>
 /// Convert the <see cref="Either{TLeft, TRight}"/> to a <see cref="Option{T}"/> where T is <typeparamref name="TRight"/>.
 /// </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 an <see cref="Option{T}"/> where T is <typeparamref name="TRight"/>.
 /// The option value state 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 <TRight> ToOptionRight <TLeft, TRight>(this Either <TLeft, TRight> either)
 => EitherModule.ToOptionRight(either);