Created
September 3, 2024 10:49
-
-
Save nagat01/78d5401158b878ca532ec332a2ffa079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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