cats
cats copied to clipboard
Add traverseCollect to TraverseFilter typeclass
Analogous to the collect
method on FunctorFilter
we can define a traverseCollect
method derived from traverseFilter
using a PartialFunction
like this:
def traverseCollect[F[_]: TraverseFilter, G[_]: Applicative, A, B](fa: F[A], f: PartialFunction[A, G[B]]): G[F[B]] =
fa.traverseFilter(a => f.lift(a).sequence)
Can I help with this? I'm looking for my first contribution to Cats.
@emilhotkowski indeed, that would be great!