コード例 #1
0
        public void EitherMapRightWhenLeft()
        {
            bool expected = false;
            Either <string, int>  either       = "10";
            Either <string, bool> eitherResult =
                EitherModule.MapRight(
                    _isEven,
                    either);

            bool result = eitherResult.Match(right => right, left => false);

            Assert.AreEqual(expected, result);
        }
コード例 #2
0
ファイル: Either.Linq.cs プロジェクト: urielgoncalves/Tango
 /// <summary>
 /// Creates a new <see cref="Either{TLeft, TRight}"/> whose value is the result of applying the given <paramref name="mapping"/> function when <see cref="Either{TLeft, TRight}.IsRight"/>.
 /// Otherwise, returns itself.
 /// </summary>
 /// <typeparam name="TLeft">The type of the left value.</typeparam>
 /// <typeparam name="TRight">The type of the right value.</typeparam>
 /// <typeparam name="TRightResult">The type of the right value returned by mapping functions</typeparam>
 /// <param name="mapping">The function to transform either value when <see cref="Either{TLeft, TRight}.IsRight"/>.</param>
 /// <param name="either">the input either.</param>
 /// <returns>
 /// Returns a new <see cref="Either{TLeft, TRight}"/> whose value is the result of applying the given mapping functions.
 /// </returns>
 public static Either <TLeft, TRightResult> MapRight <TLeft, TRight, TRightResult>(
     this Either <TLeft, TRight> either,
     Func <TRight, TRightResult> mapping)
 => EitherModule.MapRight(mapping, either);