Add EitherOps#leftMapOrKeep and EitherOps#leftFlatMapOrKeep#4638
Conversation
| 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.
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.
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? |
|
@satorg thanks! |
These are companions to
Functor#mapOrKeepandcats.Monad#flatMapOrKeep, but for the left-hand side ofEither[A, B].