Skip to content

Commit

Permalink
Category[Is] and related tests (#2759)
Browse files Browse the repository at this point in the history
* Category[Is] instance and related tests

* Category[Is] tests

* scalafmt dislike my usage of infix op
  • Loading branch information
ctongfei authored and kailuowang committed Apr 5, 2019
1 parent 8c2ba18 commit c9f10f2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/src/main/scala/cats/evidence/Is.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cats.evidence

import cats.Id
import cats.arrow._

/**
* A value of `A Is B` is proof that the types `A` and `B` are the same. More
Expand Down Expand Up @@ -65,7 +66,19 @@ abstract class Is[A, B] extends Serializable {
substitute[A =:= ?](implicitly[A =:= A])
}

object Is {
sealed abstract class IsInstances {
import Is._

/**
* The category instance on Leibniz categories.
*/
implicit val leibniz: Category[Is] = new Category[Is] {
def id[A]: A Is A = refl[A]
def compose[A, B, C](bc: B Is C, ab: A Is B): A Is C = bc.compose(ab)
}
}

object Is extends IsInstances {

/**
* In truth, "all values of `A Is B` are `refl`". `reflAny` is that
Expand Down
16 changes: 16 additions & 0 deletions tests/src/test/scala/cats/tests/IsSuite.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
package cats
package tests

import cats.arrow._
import cats.kernel.laws.discipline.SerializableTests
import cats.laws.discipline.CategoryTests
import org.scalacheck.{Arbitrary, Gen}

class IsSuite extends CatsSuite {
import evidence._

implicit def arbIs[A, B](implicit ev: A Is B): Arbitrary[A Is B] = Arbitrary(Gen.const(ev))
implicit def eqIs[A, B]: Eq[A Is B] = Eq.fromUniversalEquals

trait Top {
def foo: String = this.getClass.getName
}
case class Bottom() extends Top

checkAll("Is[Bottom, Bottom]", CategoryTests[Is].category[Bottom, Bottom, Bottom, Bottom])
checkAll("Category[Is]", SerializableTests.serializable(Category[Is]))

test("syntax") {
trait Bar

Expand Down

0 comments on commit c9f10f2

Please sign in to comment.