You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 an Option<Y> or an Either<Y,X>.
To achieve this, there are multiple solutions:
Introduce a method e.g. Swap() on Either<TA, TB> returning an Either<TB, TA>
Introduce two methods on an Option<X>: AsA(B valueIfNone) returning an Either<X, B> and AsB(A valueIfNone) returning an Either<A, X>
The text was updated successfully, but these errors were encountered:
Some question to improve my understanding of your proposal:
Would you remove .ToEither() in favour of .ToA() and .ToB()?
Adding .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>
The text was updated successfully, but these errors were encountered: