Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Magnolia
✓ magnolia.Magnolia
Derive a Show typeclass for a case class
import magnolia._
import scala.language.experimental.macros
// Define a typeclass and derive instances automatically
sealed trait Show[T] { def show(t: T): String }
object Show extends Derivation[Show] {
def join[T](ctx: CaseClass[Show, T]): Show[T] = (t: T) => ctx.parameters.map { p =>
s"${p.label}=${p.typeclass.show(p.dereference(t))}"
}.mkString("{", ",", "}")
override def split[T](ctx: SealedTrait[Show, T]): Show[T] = (t: T) => ctx.dispatch(t) { sub => sub.typeclass.show(sub.cast(t)) }
}
case class Person(name: String, age: Int)
val personShow = implicitly[Show[Person]]
println(personShow.show(Person("John", 30)))
Debug
Known issues
No known issues recorded.
Audit
Dependencies
No dependency data recorded yet.