Skip to content

Commit

Permalink
Add more syntax (#1398)
Browse files Browse the repository at this point in the history
* Add compose aliases

* Alter compose syntax so it doesn't cause problems with right associative statements

* Fix compile issues

* Seems operator associativity works?
  • Loading branch information
Fristi authored and johnynek committed Oct 18, 2016
1 parent 6f3a9ee commit 3b0c07c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/arrow/Compose.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import simulacrum.typeclass
* Must obey the laws defined in cats.laws.ComposeLaws.
*/
@typeclass trait Compose[F[_, _]] { self =>

@simulacrum.op("<<<", alias = true)
def compose[A, B, C](f: F[B, C], g: F[A, B]): F[A, C]

@simulacrum.op(">>>", alias = true)
def andThen[A, B, C](f: F[A, B], g: F[B, C]): F[A, C] =
compose(g, f)

Expand Down
13 changes: 12 additions & 1 deletion tests/src/test/scala/cats/tests/SyntaxTests.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cats
package tests

import cats.arrow.Compose
import cats.instances.AllInstances
import cats.syntax.AllSyntax
import cats.functor.{Invariant, Contravariant}
import cats.functor.{Contravariant, Invariant}

/**
* Test that our syntax implicits are working.
Expand Down Expand Up @@ -46,6 +47,16 @@ object SyntaxTests extends AllInstances with AllSyntax {
val z: Boolean = x.isEmpty
}

def testCompose[F[_,_] : Compose, A, B, C, D]: Unit = {
val x = mock[F[A, B]]
val y = mock[F[B, C]]
val z = mock[F[C, D]]

val a = x >>> y >>> z
val b = z <<< y <<< x

}

def testEq[A: Eq]: Unit = {
val x = mock[A]
val y = mock[A]
Expand Down

0 comments on commit 3b0c07c

Please sign in to comment.