Skip to content
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

Merged
merged 1 commit into from
Apr 27, 2016

Conversation

peterneyens
Copy link
Collaborator

While experimenting with MonadCombine.separate (for #975), I noticed there were no Bitraverse instances for Validated and XorT.

I would welcome suggestions, possible improvements, ... (maybe for XorTBifoldable ?)

@codecov-io
Copy link

Current coverage is 90.85%

Merging #986 into master will increase coverage by +0.03% as of a48a9da

@@            master    #986   diff @@
======================================
  Files          184     184       
  Stmts         2180    2208    +28
  Branches        42      43     +1
  Methods          0       0       
======================================
+ Hit           1980    2006    +26
  Partial          0       0       
- Missed         200     202     +2

Review entire Coverage Diff as of a48a9da

Powered by Codecov. Updated on successful CI builds.

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] =
Copy link
Contributor

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 defs for bimap and leftMap in since they should be slightly more efficient than the versions derived from Bitraverse.

Copy link
Contributor

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!).

@ceedubs
Copy link
Contributor

ceedubs commented Apr 18, 2016

@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.

maybe for XorTBifoldable

Sounds good to me!

@peterneyens peterneyens force-pushed the add-bitraverse-instances branch 2 times, most recently from d82cedb to b05b9a1 Compare April 18, 2016 15:06
@@ -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]] =
Copy link
Contributor

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?

Copy link
Collaborator Author

@peterneyens peterneyens Apr 18, 2016

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 ?

Copy link
Contributor

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.

@ceedubs
Copy link
Contributor

ceedubs commented Apr 18, 2016

Thanks again @peterneyens, especially for the cleanup you did outside of your initial PR. 👍 as long as the build goes green.

@Jacoby6000
Copy link
Contributor

If #976 gets merged, it gives you a bitraverse for these types for free (but I didn't clean things up)

@non
Copy link
Contributor

non commented Apr 27, 2016

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).

@peterneyens
Copy link
Collaborator Author

It was a simple merge. The conflict was just me renaming xorBifunctor to xorBitraverse.

@non
Copy link
Contributor

non commented Apr 27, 2016

Works for me. 👍

@non non merged commit 95501f7 into typelevel:master Apr 27, 2016
@peterneyens peterneyens deleted the add-bitraverse-instances branch April 27, 2016 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants