Exemplo n.º 1
0
        public void EitherToOptionLeftWhenLeft()
        {
            string expected                   = "Hello World";
            Either <string, int> either       = expected;
            Option <string>      optionResult =
                EitherModule.ToOptionLeft(either);

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

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Convert the <see cref="Either{TLeft, TRight}"/> to a <see cref="Option{T}"/> where T is <typeparamref name="TLeft"/>.
 /// </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="TLeft"/>.
 /// The option value state is <see cref="Option{T}.Some(T)"/> when <paramref name="either"/> <see cref="Either{TLeft, TRight}.IsLeft"/>, otherwise is <see cref="Option{T}.None"/>
 /// </returns>
 public static Option <TLeft> ToOptionLeft <TLeft, TRight>(this Either <TLeft, TRight> either)
 => EitherModule.ToOptionLeft(either);