-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add EitherOps#leftMapOrKeep
and EitherOps#leftFlatMapOrKeep
#4638
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
def leftMapOrKeep[AA >: A](pf: PartialFunction[A, AA]): Either[AA, B] = | ||
eab match { | ||
case Left(a) => Left(pf.applyOrElse(a, identity[AA])) | ||
case r @ Right(_) => r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if on a byte-code level this could be more performant:
case r : Right[B] => r
because there's no extractor to be called nor intermediate Option
value to be created in opposite to the former case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, I never thought that x @ Foo(_)
might have any significant distinction from x: Foo
.
It totally makes sense, thank you! I've realized - perhaps it makes sense to add Things seem more complicated for In fact, there's |
Agreed. Are you arguing we should do it as a drop-in replacement instead of adding |
I think it wouldn't hurt if there were Also I feel this PR would be better off if it stays focused on the |
@satorg wouldn't you mind submitting yet another review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@satorg thanks! |
These are companions to
Functor#mapOrKeep
andcats.Monad#flatMapOrKeep
, but for the left-hand side ofEither[A, B]
.