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