Open raphaelimahorn opened 1 year ago
Some question to improve my understanding of your proposal:
.ToEither()
in favour of .ToA()
and .ToB()
?.ToA()
and .ToB()
would not allow you to swap an Either. Would you therefore suggestion to add .Swap()
anyways? I read your proposal like we could either add .Swap()
or (.ToA()
and .ToB()
).Note that the package generally uses the prefix To
instead of As
which is why I slightly changed the names of the methods compared to your proposal.
For 1. I would obsolete ToEither()
, since it's a breaking change to remove it. ToEither
and ToA
are like the same thing. But I have no strong opinion on that.
For 2. I too think that are 2 different use cases. So I think a Swap()
Method would be a good extension too since we are currently really limited on how to access the value of an Either.
With
Option<T>.ToEither(B)
there is a way to convert an Option to an Either with a fallback value. The drawback is, that the Option's value will always be in the A spot and the fallback value in the B spot.The order of the A, B, (and C) in an Either have no intrinsic semantic meaning. Therefore there exist legitimate cases, where you have an interface, requiring a parameter of type
Either<X,Y>
that you would like to call from anOption<Y>
or anEither<Y,X>
.To achieve this, there are multiple solutions:
Swap()
onEither<TA, TB>
returning anEither<TB, TA>
Option<X>
:AsA(B valueIfNone)
returning anEither<X, B>
andAsB(A valueIfNone)
returning anEither<A, X>