aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRui Gonçalves <ruippeixotog@gmail.com>2017-06-21 22:38:58 +0100
committerRui Gonçalves <ruippeixotog@gmail.com>2017-06-21 22:38:58 +0100
commit0ccdf446c4c7770e60ede55ab712c8a551e36796 (patch)
treecc2579e18c5c4659d04386abe091de8a5b64e2aa /examples
parent4a6e5eaa04fe54fdda2c501cf79fb2c4c5aaa439 (diff)
downloadmagnolia-0ccdf446c4c7770e60ede55ab712c8a551e36796.tar.gz
magnolia-0ccdf446c4c7770e60ede55ab712c8a551e36796.tar.bz2
magnolia-0ccdf446c4c7770e60ede55ab712c8a551e36796.zip
Reorganize magnolia.Show implicits
Scopes magnolia.Show implicits so that they do not clash with cats' Show type class
Diffstat (limited to 'examples')
-rw-r--r--examples/src/main/scala/example.scala21
1 files changed, 10 insertions, 11 deletions
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 {