Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more syntax #1398

Merged
merged 4 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the asymmetry here. If we have the :<< The other should be >>:.

Copy link
Contributor Author

@Fristi Fristi Oct 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also dislike it, but I am getting this compile error when introducing >>:, guess it's right associative, even when you put the : on the right.

[error] /Users/mark/Projects/cats/tests/src/test/scala/cats/tests/SyntaxTests.scala:55: type mismatch;
[error]  found   : x$1.type (with underlying type F[B,C])
[error]  required: F[D,?]
[error]     val a = x >>: y >>: z
[error]

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