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<TLeft2, TRight2> BiMap<TLeft1, TLeft2, TRight1, TRight2>(
            [NotNull] this Either<TLeft1, TRight1> either,
            [NotNull] Func<TLeft1, TLeft2> leftSelector,
            [NotNull] Func<TRight1, TRight2> rightSelector)
        {
            if (either is null) throw new ArgumentNullException(nameof(either));
            if (leftSelector is null) throw new ArgumentNullException(nameof(leftSelector));
            if (rightSelector is null) throw new ArgumentNullException(nameof(rightSelector));
            switch (either)
            {
                case EitherLeft<TLeft1, TRight1> left:
                    return Either.Left(leftSelector(left.Value), new TypeHint<TRight2>());
                case EitherRight<TLeft1, TRight1> right:
                    return Either.Right(rightSelector(right.Value), new TypeHint<TLeft2>());
                default:
                    throw new ArgumentOutOfRangeException(nameof(either));
            }
        }
[ NotNull ] public static Either < TLeft2 , TRight2 > BiMap < TLeft1 , TLeft2 , TRight1 , TRight2 > ( [ NotNull ] this Either < TLeft1 , TRight1 > either , [ NotNull ] Func < TLeft1 , TLeft2 > leftSelector , [ NotNull ] Func < TRight1 , TRight2 > rightSelector ) { if ( either is null ) throw new ArgumentNullException ( nameof ( either ) ) ; if ( leftSelector is null ) throw new ArgumentNullException ( nameof ( leftSelector ) ) ; if ( rightSelector is null ) throw new ArgumentNullException ( nameof ( rightSelector ) ) ; switch ( either ) { case EitherLeft < TLeft1 , TRight1 > left : return Either . Left ( leftSelector ( left . Value ) , new TypeHint < TRight2 > ( ) ) ; case EitherRight < TLeft1 , TRight1 > right : return Either . Right ( rightSelector ( right . Value ) , new TypeHint < TLeft2 > ( ) ) ; default : throw new ArgumentOutOfRangeException ( nameof ( either ) ) ; } }
Transform the right value contained in
.
Transform the right value contained in .
this
[NotNull]
Func<TLeft1, TLeft2>
[NotNull]
Func<TRight1, TRight2>
[NotNull]