Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Un-deprecate left Either projections #8012

Merged
merged 2 commits into from
May 2, 2019
Merged

Un-deprecate left Either projections #8012

merged 2 commits into from
May 2, 2019

Conversation

nrinaudo
Copy link
Contributor

Deprecating right projections makes sense - Either is now right-biased, there's no need for them.

Deprecating left projections also seems desirable, but I feel this might have been done a bit quickly, with some unpleasant consequences.

There are existing scenarios where one might want to call .left.map(f) or .left.flatMap(g) - flatMap is particularly useful to recover on errors, for example.

The current state of scala means that we'll get a warning for this (or, for the -Xfatal-warnings crowd, an error) without a clear workaround. Suggestions on scala/contributors were:

e.swap.flatMap(x => f(x).swap).swap

e match {
  case Left(l) => f(l)
  case r@Right(_) => r
}

Both of these work fine, but I doubt anyone who has to replace e.left.flatMap(f) by one of them will feel it's a step forward.

Truth be told, I'd rather see projections disappear and Either get leftMap and leftFlatMap methods, but it's a bit late for that, with the 2.13.0 API being frozen.

@scala-jenkins scala-jenkins added this to the 2.13.1 milestone Apr 29, 2019
@diesalbla diesalbla added the library:base Changes to the base library, i.e. Function Tuples Try label Apr 29, 2019
@SethTisue
Copy link
Member

the previous discussion was at #6682

Copy link
Member

@hrhino hrhino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this. I'd like that we consider introducing mapLeft or what have you in 2.14, but this combinator has its place IMO.

@martijnhoekstra
Copy link
Contributor

With the amount of support I'm seeing for this, let's go for undeprecating. There is no rush. I think there is space for a nicer, more symmetric design, but let's explore that for 2.14.x

@lrytz lrytz modified the milestones: 2.13.1, 2.13.0-RC2 Apr 30, 2019
@nrinaudo
Copy link
Contributor Author

@martijnhoekstra to be clear: I completely agree that projections should disappear. I do feel, however, that they shouldn't take away useful combinators with them.

@adriaanm adriaanm merged commit 7de0f3e into scala:2.13.x May 2, 2019
@nrinaudo nrinaudo deleted the undepreated-either-left branch May 2, 2019 14:57
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library:base Changes to the base library, i.e. Function Tuples Try release-notes worth highlighting in next release notes
Projects
None yet
9 participants