Skip to content

Commit

Permalink
Merge pull request #1273 from ceedubs/filter-syntax
Browse files Browse the repository at this point in the history
Add syntax import objects for FunctorFilter and TraverseFilter
  • Loading branch information
adelbertc authored Aug 8, 2016
2 parents f212a12 + 94bd87b commit 97fc762
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/src/main/scala/cats/syntax/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package object syntax {
object flatMap extends FlatMapSyntax
object foldable extends FoldableSyntax
object functor extends FunctorSyntax
object functorFilter extends FunctorFilterSyntax
object group extends GroupSyntax
object invariant extends InvariantSyntax
object list extends ListSyntax
Expand All @@ -37,6 +38,7 @@ package object syntax {
object strong extends StrongSyntax
object transLift extends TransLiftSyntax
object traverse extends TraverseSyntax
object traverseFilter extends TraverseFilterSyntax
object validated extends ValidatedSyntax
object writer extends WriterSyntax
object xor extends XorSyntax
Expand Down
25 changes: 24 additions & 1 deletion tests/src/test/scala/cats/tests/SyntaxTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import cats.functor.{Invariant, Contravariant}
*
* None of these tests should ever run, or do any runtime checks.
*/
class SyntaxTests extends AllInstances with AllSyntax {
object SyntaxTests extends AllInstances with AllSyntax {

// pretend we have a value of type A
def mock[A]: A = ???
Expand Down Expand Up @@ -258,3 +258,26 @@ class SyntaxTests extends AllInstances with AllSyntax {
val gea4 = ga.recoverWith(pfegea)
}
}

/**
* Similar to [[SyntaxTests]] but doesn't automatically include all
* instances/syntax, so that piecemeal imports can be tested.
*/
object AdHocSyntaxTests {
import SyntaxTests.mock

def testFunctorFilterSyntax[F[_]:FunctorFilter, A]: Unit = {
import cats.syntax.functorFilter._

val fa = mock[F[A]]
val filtered = fa.mapFilter(_ => None)
}

def testTraverseFilterSyntax[F[_]:TraverseFilter, G[_]: Applicative, A, B]: Unit = {
import cats.syntax.traverseFilter._

val fa = mock[F[A]]
val f = mock[A => G[Option[B]]]
val filtered = fa.traverseFilter(f)
}
}

0 comments on commit 97fc762

Please sign in to comment.