-
-
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
instances for std Either. closes #117 #125
Conversation
looking good. I think we also have MonadCombine when the left is a monoid (we need the monoidal zero on the left for filter) |
I don't know how to implement MonadFilter without requiring A (left) to always have Monoid. For MonadCombine, A should always have Monoid and B should always have Semigroup. Any suggestions? |
|
I tried to write something, but I'm not sure it's correct. |
@stew (and anyone else who wants to weigh in: Is the If we do keep it, I think we can change |
hmm, maybe not MonadCombine, but MonadFilter for using them in for comprehensions? |
First, what is the laws of |
@stew so something like this? val errorOrInt: Either[String, Int] = Right(-2)
for {
x <- errorOrInt if (x > 0)
} yield x + 1
// Either[String, Int] = Left("") It just seems unlikely that this is actually what people would want. It seems like something like |
similar discussion in scalaz https://groups.google.com/d/topic/scalaz/NCiRRxLjanM/discussion |
also |
@xuwei-k It's a great point -- we need laws for For example: |
In addition to the law @non listed, I think we also need: |
Right, and really my law should be generalized to |
@wedens Definitely wish for |
I don't think we need to solve this as part of this PR, but I think we should discuss whether we really want |
Ok. I'll remove this controversial instances, so we can add them later when it'll became more clear. |
implicit def eitherOrder[A: Order, B: Order]: Order[Either[A, B]] = new Order[Either[A, B]] { | ||
def compare(x: Either[A, B], y: Either[A, B]): Int = x.fold( | ||
a => y.fold(Order[A].compare(a, _), _ => -1), | ||
b => y.fold(_ => 1, Order[B].compare(b, _)) |
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.
Sorry we haven't added it to the contributor guide, but can you please follow the convention agreed upon in #27 and use implicit A: Order[A], B: Order[B]
and then use A.compare
and B.compare
instead of Order[A].compare
and Order[B].compare
?
@ceedubs done. should i squash commits? |
def traverse[F[_]: Applicative, B, C](fa: Either[A, B])(f: B => F[C]): F[Either[A, C]] = | ||
fa.fold( | ||
a => Applicative[F].pure(Left(a)), | ||
b => Applicative[F].map(f(b))(Right(_)) |
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.
@wedens ah sorry here's one more that I missed - the Applicative.apply
calls.
@wedens nah it sounds like enough cats contributors dislike changing git history that it's preferred to not squash commits once a PR is open. We need to get this into the contributor guide. Thanks for all of the work and the prompt turnarounds. Sorry that a bunch of discussions (MonadFilter, etc) got pork-barreled into this PR discussion. |
Wow that was a fast turnaround! 👍 once Travis goes green. |
@ceedubs yeah. It's definetly should be in contributor guide as it varies from project to project. Some prefer to squash commits, others prefer not to overwrite history. |
👍 |
instances for std Either. closes #117
No description provided.