-
-
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 Bitraverse
instances for Validated
and XorT
.
#986
Conversation
Current coverage is
|
new Bifunctor[Validated] { | ||
override def bimap[A, B, C, D](fab: Validated[A, B])(f: A => C, g: B => D): Validated[C, D] = fab.bimap(f, g) | ||
override def leftMap[A, B, C](fab: Validated[A, B])(f: A => C): Validated[C, B] = fab.leftMap(f) | ||
implicit def validatedBifunctor: Bitraverse[Validated] = |
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.
It might be good to leave the override def
s for bimap
and leftMap
in since they should be slightly more efficient than the versions derived from Bitraverse
.
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.
A couple other notes:
I know this was already a def
, but since I noticed it in the diff: could we switch it to a val
to avoid repeated allocations? Or does it hit the #965 strangeness?
Are we keeping the name validatedBifunctor
for compatibility reasons? If so, we should probably leave a comment that that's what we are doing. However, I think we can feel free to change this to validatedBitraverse
since we won't really start to focus on compatibility until a 1.0 release (hopefully coming soon!).
@peterneyens thanks! In general this looks good. I'd want to see https://github.com/typelevel/cats/pull/986/files#r60056173 addressed before this is merged.
Sounds good to me! |
d82cedb
to
b05b9a1
Compare
@@ -65,6 +65,9 @@ final case class XorT[F[_], A, B](value: F[A Xor B]) { | |||
|
|||
def bimap[C, D](fa: A => C, fb: B => D)(implicit F: Functor[F]): XorT[F, C, D] = XorT(F.map(value)(_.bimap(fa, fb))) | |||
|
|||
def bitraverse[G[_], C, D](f: A => G[C], g: B => G[D])(implicit traverseF: Traverse[F], bitraverseXor: Bitraverse[Xor], applicativeG: Applicative[G]): G[XorT[F, C, D]] = |
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.
We shouldn't need to take Bitraverse[Xor]
as a parameter, because that's already defined within cats, 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.
Yeah, that felt strange. Can I just write Bitraverse[Xor].bitraverse(axb)(f, g)
directly ?
Can I do the same with Bifoldable[Xor]
in XorTBifoldable
?
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.
Seems reasonable to me. I don't know why we have traverseXorA
in the XorT.traverse
signature. I would think we could remove that too.
b05b9a1
to
9efc288
Compare
Thanks again @peterneyens, especially for the cleanup you did outside of your initial PR. 👍 as long as the build goes green. |
If #976 gets merged, it gives you a bitraverse for these types for free (but I didn't clean things up) |
This looks good to me. 👍 Unfortunately there are merge conflicts now. Sorry! @peterneyens would you be able to merge and update? If not, I can give it a shot (I imagine the merge will be relatively easy). |
9efc288
to
da49118
Compare
It was a simple merge. The conflict was just me renaming |
Works for me. 👍 |
While experimenting with
MonadCombine.separate
(for #975), I noticed there were noBitraverse
instances forValidated
andXorT
.I would welcome suggestions, possible improvements, ... (maybe for
XorTBifoldable
?)