cats icon indicating copy to clipboard operation
cats copied to clipboard

Add `traverseCollect` to `TraverseFilter` typeclass

Open emilhotkowski opened this issue 2 years ago • 6 comments

Thank you for contributing to Cats!

This is a kind reminder to run sbt +prePR and commit the changed files, if any, before submitting.

emilhotkowski avatar Jul 30 '22 08:07 emilhotkowski

I added syntax and test for it, but I am not sure if we need laws. Looking at TraverseFilterLaws, we don't have laws for other functions like sequenceFilter. Should I add some. for traverseCollect anyway?

emilhotkowski avatar Jul 31 '22 07:07 emilhotkowski

Looking at TraverseFilterLaws, we don't have laws for other functions like sequenceFilter. Should I add some. for traverseCollect anyway?

Oh that's interesting. I think laws are good to have, in case an implementation overrides this method, and at the very least to exercise this code. It's also often good to have some tests with a concrete implementation testing it works as expected. Here's a recent PR that is a great example:

  • https://github.com/typelevel/cats/pull/4248

armanbilge avatar Jul 31 '22 07:07 armanbilge

By laws you mean we want to have a test proving that traverseCollect works the same as traverse and collect in two operations?

emilhotkowski avatar Jul 31 '22 09:07 emilhotkowski

The law should verify that the actual implementation of the method matches the default implementation—you can reuse the same code. You might find the commentary in https://github.com/typelevel/cats/pull/4248#discussion_r907327872 helpful :) let me know if you have questions!

armanbilge avatar Jul 31 '22 22:07 armanbilge

I added all necessary stuff (I believe so) :)

emilhotkowski avatar Aug 02 '22 16:08 emilhotkowski

thanks for your PR!

johnynek avatar Aug 02 '22 23:08 johnynek