FunSharp.Common/EitherExtensions.cs
//--------------------------------------------------
/// <summary>
/// Transform the right value contained in
/// <paramref name="either" />.
/// </summary>
Transform the right value contained in
.
Transform the right value contained in .
[NotNull]
        public static Either<TLeft, TRight2> MapRight<TLeft, TRight1, TRight2>(
            [NotNull] this Either<TLeft, TRight1> either,
            [NotNull] Func<TRight1, TRight2> valueSelector)
        {
            if (either is null) throw new ArgumentNullException(nameof(either));
            if (valueSelector is null) throw new ArgumentNullException(nameof(valueSelector));
            switch (either)
            {
                case EitherLeft<TLeft, TRight1> left:
                    return Either.Left(left.Value, new TypeHint<TRight2>());
                case EitherRight<TLeft, TRight1> right:
                    return Either.Right(valueSelector(right.Value), new TypeHint<TLeft>());
                default:
                    throw new ArgumentOutOfRangeException(nameof(either));
            }
        }
[ NotNull ] public static Either < TLeft , TRight2 > MapRight < TLeft , TRight1 , TRight2 > ( [ NotNull ] this Either < TLeft , TRight1 > either , [ NotNull ] Func < TRight1 , TRight2 > valueSelector ) { if ( either is null ) throw new ArgumentNullException ( nameof ( either ) ) ; if ( valueSelector is null ) throw new ArgumentNullException ( nameof ( valueSelector ) ) ; switch ( either ) { case EitherLeft < TLeft , TRight1 > left : return Either . Left ( left . Value , new TypeHint < TRight2 > ( ) ) ; case EitherRight < TLeft , TRight1 > right : return Either . Right ( valueSelector ( right . Value ) , new TypeHint < TLeft > ( ) ) ; default : throw new ArgumentOutOfRangeException ( nameof ( either ) ) ; } }
Transform the right value contained in
.
Transform the right value contained in .
this
[NotNull]
Func<TRight1, TRight2>
[NotNull]