From 0decc5711927b56a8e6515e58296d655844c1962 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 30 Sep 2016 18:05:19 +0200 Subject: [PATCH 1/4] Add compose aliases --- core/src/main/scala/cats/arrow/Compose.scala | 3 +++ tests/src/test/scala/cats/tests/SyntaxTests.scala | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/arrow/Compose.scala b/core/src/main/scala/cats/arrow/Compose.scala index 825c7ca4b9..ef187bdc0b 100644 --- a/core/src/main/scala/cats/arrow/Compose.scala +++ b/core/src/main/scala/cats/arrow/Compose.scala @@ -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) diff --git a/tests/src/test/scala/cats/tests/SyntaxTests.scala b/tests/src/test/scala/cats/tests/SyntaxTests.scala index 43c6b5f359..bdd1083717 100644 --- a/tests/src/test/scala/cats/tests/SyntaxTests.scala +++ b/tests/src/test/scala/cats/tests/SyntaxTests.scala @@ -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. @@ -46,6 +47,14 @@ object SyntaxTests extends AllInstances with AllSyntax { val z: Boolean = x.isEmpty } + def testCompose[F[_,_] : Compose, A, B, C]: Unit = { + val x = mock[F[A, B]] + val y = mock[F[B, C]] + + x >>> y + y <<< x + } + def testEq[A: Eq]: Unit = { val x = mock[A] val y = mock[A] From 78083448fa4361ba7e23e30b7ae439aa623decea Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 1 Oct 2016 11:05:25 +0200 Subject: [PATCH 2/4] Alter compose syntax so it doesn't cause problems with right associative statements --- core/src/main/scala/cats/arrow/Compose.scala | 4 ++-- tests/src/test/scala/cats/tests/SyntaxTests.scala | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/scala/cats/arrow/Compose.scala b/core/src/main/scala/cats/arrow/Compose.scala index ef187bdc0b..82359400ef 100644 --- a/core/src/main/scala/cats/arrow/Compose.scala +++ b/core/src/main/scala/cats/arrow/Compose.scala @@ -8,10 +8,10 @@ import simulacrum.typeclass */ @typeclass trait Compose[F[_, _]] { self => - @simulacrum.op(">>>", alias = true) + @simulacrum.op(":<<", alias = true) def compose[A, B, C](f: F[B, C], g: F[A, B]): F[A, C] - @simulacrum.op("<<<", alias = true) + @simulacrum.op(">>:", alias = true) def andThen[A, B, C](f: F[A, B], g: F[B, C]): F[A, C] = compose(g, f) diff --git a/tests/src/test/scala/cats/tests/SyntaxTests.scala b/tests/src/test/scala/cats/tests/SyntaxTests.scala index bdd1083717..1fc5bb8ccb 100644 --- a/tests/src/test/scala/cats/tests/SyntaxTests.scala +++ b/tests/src/test/scala/cats/tests/SyntaxTests.scala @@ -47,12 +47,13 @@ object SyntaxTests extends AllInstances with AllSyntax { val z: Boolean = x.isEmpty } - def testCompose[F[_,_] : Compose, A, B, C]: Unit = { + 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]] - x >>> y - y <<< x + x >>: y >>: z + z :<< y :<< x } def testEq[A: Eq]: Unit = { From 996b5bbf7065d8e542b88ed985e4b915ade2eb25 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 1 Oct 2016 13:38:13 +0200 Subject: [PATCH 3/4] Fix compile issues --- core/src/main/scala/cats/arrow/Compose.scala | 2 +- tests/src/test/scala/cats/tests/SyntaxTests.scala | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/cats/arrow/Compose.scala b/core/src/main/scala/cats/arrow/Compose.scala index 82359400ef..4dbf53a800 100644 --- a/core/src/main/scala/cats/arrow/Compose.scala +++ b/core/src/main/scala/cats/arrow/Compose.scala @@ -11,7 +11,7 @@ import simulacrum.typeclass @simulacrum.op(":<<", alias = true) def compose[A, B, C](f: F[B, C], g: F[A, B]): F[A, C] - @simulacrum.op(">>:", alias = true) + @simulacrum.op(">>>", alias = true) def andThen[A, B, C](f: F[A, B], g: F[B, C]): F[A, C] = compose(g, f) diff --git a/tests/src/test/scala/cats/tests/SyntaxTests.scala b/tests/src/test/scala/cats/tests/SyntaxTests.scala index 1fc5bb8ccb..b218ebbca0 100644 --- a/tests/src/test/scala/cats/tests/SyntaxTests.scala +++ b/tests/src/test/scala/cats/tests/SyntaxTests.scala @@ -52,8 +52,9 @@ object SyntaxTests extends AllInstances with AllSyntax { val y = mock[F[B, C]] val z = mock[F[C, D]] - x >>: y >>: z - z :<< y :<< x + val a = x >>> y >>> z + val b = z :<< y :<< x + } def testEq[A: Eq]: Unit = { From 13209e715006b0ed74ac4ca8a555326eac5b7ec2 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 18 Oct 2016 13:59:23 +0200 Subject: [PATCH 4/4] Seems operator associativity works? --- core/src/main/scala/cats/arrow/Compose.scala | 2 +- tests/src/test/scala/cats/tests/SyntaxTests.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/arrow/Compose.scala b/core/src/main/scala/cats/arrow/Compose.scala index 4dbf53a800..d5157f24eb 100644 --- a/core/src/main/scala/cats/arrow/Compose.scala +++ b/core/src/main/scala/cats/arrow/Compose.scala @@ -8,7 +8,7 @@ import simulacrum.typeclass */ @typeclass trait Compose[F[_, _]] { self => - @simulacrum.op(":<<", alias = true) + @simulacrum.op("<<<", alias = true) def compose[A, B, C](f: F[B, C], g: F[A, B]): F[A, C] @simulacrum.op(">>>", alias = true) diff --git a/tests/src/test/scala/cats/tests/SyntaxTests.scala b/tests/src/test/scala/cats/tests/SyntaxTests.scala index b218ebbca0..c3c040ac8c 100644 --- a/tests/src/test/scala/cats/tests/SyntaxTests.scala +++ b/tests/src/test/scala/cats/tests/SyntaxTests.scala @@ -53,7 +53,7 @@ object SyntaxTests extends AllInstances with AllSyntax { val z = mock[F[C, D]] val a = x >>> y >>> z - val b = z :<< y :<< x + val b = z <<< y <<< x }