-
-
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
Improve the type signature of orElse #575
Improve the type signature of orElse #575
Conversation
Current coverage is
|
👍 for the idea and type signature change. If the original |
The whole point of orElse is to drop the left hand value of a Disjunction, no sense having the type that is dropped influence the resulting type.
798d4c1
to
68e4e49
Compare
@ceedubs Sure! |
👍 thanks! |
fold(_ => fallback, _ => this) | ||
def orElse[C, BB >: B](fallback: => C Xor BB): C Xor BB = this match { | ||
case Xor.Left(_) => fallback | ||
case r @ Xor.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.
is there a difference in
case r @ Xor.Right(_) => r
and
case r => r
? The former is probably nicer to read, but does it come at a cost? i don't actually know and have wondered about this.
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 would be surprised if it did not come at a cost, but who knows, maybe the scala pattern matcher is smarter than I give it credit for. Happy to change it to r => 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 think it will essentially correspond to an else case, so it seems fine to me.
👍 |
…f_Xor Improve the type signature of orElse
This is the same as typelevel#575 but for Validated instead of Xor.
The whole point of orElse is to drop the left hand value of a Disjunction, no sense having the type that is dropped influence the resulting type.
Let me know if I am missing something! :-)