From 0ccdf446c4c7770e60ede55ab712c8a551e36796 Mon Sep 17 00:00:00 2001 From: Rui Gonçalves Date: Wed, 21 Jun 2017 22:38:58 +0100 Subject: Reorganize magnolia.Show implicits Scopes magnolia.Show implicits so that they do not clash with cats' Show type class --- examples/src/main/scala/example.scala | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/src/main/scala/example.scala b/examples/src/main/scala/example.scala index e649b88..c3d4c2f 100644 --- a/examples/src/main/scala/example.scala +++ b/examples/src/main/scala/example.scala @@ -6,21 +6,11 @@ import language.experimental.macros import language.higherKinds import collection.immutable.ListMap -object `package` { - implicit class Showable[T: Show](t: T) { - def show: String = implicitly[Show[T]].show(t) - } - implicit val showString: Show[String] = identity - implicit val showBool: Show[Boolean] = _.toString - implicit def showList[T: Show]: Show[List[T]] = xs => xs.map { x => s"list:${implicitly[Show[T]].show(x)}" }.mkString(";") - implicit def showSet[T: Show]: Show[Set[T]] = s => "set" -} - sealed trait EmptyType sealed trait Tree case class Branch(left: Tree, right: Tree) extends Tree -case class Leaf(value: Int, no: EmptyType) extends Tree +case class Leaf(value: Int, no: String) extends Tree sealed trait Entity case class Person(name: String, address: Address) extends Entity @@ -31,12 +21,21 @@ case class Country(name: String, code: String, salesTax: Boolean) trait Show[T] { def show(t: T): String } object Show extends Show_1 { implicit val showInt: Show[Int] = _.toString + implicit val showString: Show[String] = identity + implicit val showBool: Show[Boolean] = _.toString + implicit def showList[T: Show]: Show[List[T]] = xs => xs.map { x => s"list:${implicitly[Show[T]].show(x)}" }.mkString(";") + implicit def showSet[T: Show]: Show[Set[T]] = s => "set" + implicit val derivation = new ContravariantDerivation[Show] { type Return = String def call[T](show: Show[T], value: T): String = show.show(value) def construct[T](body: T => String): Show[T] = body(_) def join(xs: ListMap[String, String]): String = xs.map { case (k, v) => s"$k=$v" }.mkString("{", ", ", "}") } + + implicit class Showable[T: Show](t: T) { + def show: String = implicitly[Show[T]].show(t) + } } trait Show_1 { -- cgit v1.2.3