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 syntax for Bitraverse to allow traversal and sequencing of the left side #2606

Merged

Conversation

andimiller
Copy link
Contributor

@andimiller andimiller commented Nov 12, 2018

This adds Bitraverse-based syntax for:

  • leftTraverse
  • leftSequence

This adds syntax for:
* traverse
* sequence
* leftTraverse
* leftSequence

I am open to having better names, but I think these would be useful to have in cats-core.
}

final class BitraverseOps[F[_, _], A, B](val fab: F[A, B]) extends AnyVal {
def bitraverse[G[_]: Applicative, C, D](f: A => G[C], g: B => G[D])(implicit F: Bitraverse[F]): G[F[C, D]] =
F.bitraverse(fab)(f, g)
def traverse[G[_], C](f: B => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, C]] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this one and sequence, we already have them defined on Traverse and I think that can cause complications. Maybe we should remove these or rename them to rightTraverse and rightSequence

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about this, but I'll change it to rightTraverse and rightSequence for now. You don't normally have syntax in scope to give you traverse and sequence, so I do think they're still valuable to have.

Copy link
Member

@LukaJCB LukaJCB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton for opening this, I left a couple of comments :)

@kubukoz
Copy link
Member

kubukoz commented Nov 13, 2018

Looks like this isn't binary compatible, @andimiller would you mind adding these implicit conversions to a new trait like https://github.com/typelevel/cats/pull/2600/files ?

@andimiller
Copy link
Contributor Author

Looks like this isn't binary compatible, @andimiller would you mind adding these implicit conversions to a new trait like https://github.com/typelevel/cats/pull/2600/files ?

I have no idea how binary compatibility works, but I can give it a go copying how that PR does it

@codecov-io
Copy link

codecov-io commented Nov 13, 2018

Codecov Report

Merging #2606 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2606      +/-   ##
==========================================
+ Coverage   95.13%   95.15%   +0.02%     
==========================================
  Files         365      365              
  Lines        6757     6773      +16     
  Branches      286      309      +23     
==========================================
+ Hits         6428     6445      +17     
+ Misses        329      328       -1
Impacted Files Coverage Δ
core/src/main/scala/cats/syntax/bitraverse.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/instances/duration.scala 100% <0%> (ø) ⬆️
...src/main/scala/cats/instances/finiteDuration.scala 100% <0%> (ø) ⬆️
core/src/main/scala/cats/syntax/monadError.scala 100% <0%> (ø) ⬆️
...estkit/src/main/scala/cats/tests/ListWrapper.scala 100% <0%> (ø) ⬆️
testkit/src/main/scala/cats/tests/CatsSuite.scala 70% <0%> (ø) ⬆️
core/src/main/scala/cats/data/Chain.scala 99.6% <0%> (+0.01%) ⬆️
core/src/main/scala/cats/data/EitherT.scala 97.91% <0%> (+0.01%) ⬆️
kernel/src/main/scala/cats/kernel/Hash.scala 100% <0%> (+8.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee7d356...28f6c9a. Read the comment docs.

@andimiller
Copy link
Contributor Author

I think I've managed to make it binary compatible, I've left {Left,Right}NestedBitraverseOps without the BinCompat0 suffix because they're new syntax classes, not sure if they should have the suffix to match the others, or if it's okay to leave them as is, because there are no "original" versions of those classes?

@andimiller
Copy link
Contributor Author

Should I have made a new SyntaxBinCompat4 or put it into an existing one? No idea how these are meant to work

@kubukoz
Copy link
Member

kubukoz commented Nov 13, 2018

I believe it'll be fine if you add it to bincompat3. As long as you get this merged before 1.5.0 is released :)

@ikempf
Copy link

ikempf commented Nov 30, 2018

I think there should be no rightTraverse nor rightSequence since both are already offered by traverse and sequence from Traverse typeclass.

Bifunctor only offers bimap and leftMap since map/rightMap is already offered by Functor.

@andimiller andimiller changed the title Add syntax for Bitraverse to allow independent traversal of sides Add syntax for Bitraverse to allow traversal and sequencing of the left side Dec 3, 2018
@andimiller
Copy link
Contributor Author

I've changed this to only provide leftTraverse and leftSequence, since adding the right-based versions is out of scope for this PR

@ikempf
Copy link

ikempf commented Dec 22, 2018

@andimiller Hi, are you still on this ? Now that 1.5.0 is out this will have to go into a bincompat4.

@andimiller
Copy link
Contributor Author

@ikempf yeah I'll be updating this PR later today to put it in bincompat4

LukaJCB
LukaJCB previously approved these changes Jan 8, 2019
Copy link
Member

@LukaJCB LukaJCB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping this up to date :)

@kailuowang kailuowang added this to the 1.6 milestone Jan 8, 2019
@LukaJCB
Copy link
Member

LukaJCB commented Jan 8, 2019

Seems like there's a bug in the travis reporting, I'm going to close/reopen :)

@LukaJCB LukaJCB closed this Jan 8, 2019
@LukaJCB LukaJCB reopened this Jan 8, 2019
kailuowang
kailuowang previously approved these changes Jan 9, 2019
@kailuowang
Copy link
Contributor

Thanks! @andimiller Adding some doctests, an example, would be helpful. Although I admit that a doctest here would be hard to find. I'll leave that to you.

@andimiller andimiller dismissed stale reviews from kailuowang and LukaJCB via 76d8787 January 10, 2019 11:58
@andimiller
Copy link
Contributor Author

I've added doctests to these syntax methods, I did look at adding these methods directly onto Bitraverse as derived methods, but that trips the binary compatibility checker, so it'd probably need to wait til 2.0.

I also can't figure out how to run doctests, so I've pushed it to see if travis manages it better than I can locally.

@kailuowang
Copy link
Contributor

@andimiller thanks for adding them. simple test will run the doctest. In this case sbt coreJVM/test

@kailuowang kailuowang merged commit b4d1ad1 into typelevel:master Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants