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

Category[Is] and related tests #2759

Merged
merged 3 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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] {
Copy link
Member

Choose a reason for hiding this comment

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

Can we give thise one a more verbose name? Something like catsEvidenceCategoryForLeibniz? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Category instance for As is named as liskov -- so I copied that :-)

Copy link
Member

Choose a reason for hiding this comment

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

Good call :)

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