blob: 08690c25251219cb3f7c1acf577b8d5366fb90b4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package magnolia.examples.cats
import scala.collection.immutable.ListMap
import scala.language.experimental.macros
import scala.language.higherKinds
import cats.Show
import magnolia.ContravariantDerivation
import magnolia.Macros
object instances extends instances1 {
implicit val showDerivation = 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("{", ", ", "}")
}
}
trait instances1 {
implicit def genericShow[T]: Show[T] = macro Macros.magnolia[T, Show[_]]
}
|