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.
It might be good to leave the override defs 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.
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
|
|
||
| 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.
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.
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.
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 noBitraverseinstances forValidatedandXorT.I would welcome suggestions, possible improvements, ... (maybe for
XorTBifoldable?)