Skip to content

Commit

Permalink
Make Show contravariant
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundnoble committed May 5, 2017
1 parent 4e381d2 commit e96bb75
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Show.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import cats.functor.Contravariant
* made a toString method, a Show instance will only exist if someone
* explicitly provided one.
*/
@typeclass trait Show[T] {
@typeclass trait Show[-T] {
def show(f: T): String
}

Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/cats/instances/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ trait AllInstances
with MapInstances
with BigIntInstances
with BigDecimalInstances
with BitSetInstances
with FutureInstances
with TryInstances
with TupleInstances
Expand Down
8 changes: 0 additions & 8 deletions core/src/main/scala/cats/instances/bitSet.scala

This file was deleted.

1 change: 0 additions & 1 deletion core/src/main/scala/cats/instances/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package object instances {
object list extends ListInstances
object option extends OptionInstances
object set extends SetInstances
object bitSet extends BitSetInstances
object stream extends StreamInstances
object vector extends VectorInstances
object map extends MapInstances
Expand Down
21 changes: 0 additions & 21 deletions tests/src/test/scala/cats/tests/BitSetTests.scala

This file was deleted.

16 changes: 15 additions & 1 deletion tests/src/test/scala/cats/tests/ShowTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ShowTests extends CatsSuite {
checkAll("Contravariant[Show]", SerializableTests.serializable(Contravariant[Show]))

test("show string interpolator") {
import cats.syntax.show._

case class Cat(name: String)
object Cat {
Expand All @@ -31,4 +30,19 @@ class ShowTests extends CatsSuite {

assertResult("Good morning, Whiskers!")(show"Good $tod, ${List(cat).head}!")
}

test("show string interpolator and contravariance") {
trait Animal {
val name: String
}
object Animal {
implicit val showAnimal: Show[Animal] =
Show.show(_.name)
}
class Cat(override val name: String, val breed: String) extends Animal

val cat = new Cat("Whiskers", "Calico")

assertResult("Good morning, Whiskers!")(show"Good morning, $cat!")
}
}

0 comments on commit e96bb75

Please sign in to comment.