Skip to content

Instantly share code, notes, and snippets.

@nagat01
Created September 3, 2024 10:49
Show Gist options
  • Save nagat01/78d5401158b878ca532ec332a2ffa079 to your computer and use it in GitHub Desktop.
Save nagat01/78d5401158b878ca532ec332a2ffa079 to your computer and use it in GitHub Desktop.
import scala.deriving.Mirror
trait Show[A]:
def show(a: A): String
object Show:
def derived[A](using m: Mirror.ProductOf[A]): Show[A] =
new Show[A]:
def show(a: A): String = m.fromProduct(a.asInstanceOf[Product]).toString
case class B(name: String, age: Int) derives Show
@main def main =
println(summon[Show[B]].show(B("Scala", 3)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment