cats
cats copied to clipboard
Add `traverseCollect` to `TraverseFilter` typeclass
Thank you for contributing to Cats!
This is a kind reminder to run sbt +prePR
and commit the changed files, if any, before submitting.
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?
Looking at
TraverseFilterLaws
, we don't have laws for other functions likesequenceFilter
. Should I add some. fortraverseCollect
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
By laws you mean we want to have a test proving that traverseCollect
works the same as traverse
and collect
in two operations?
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!
I added all necessary stuff (I believe so) :)
thanks for your PR!