Skip to content

Instantly share code, notes, and snippets.

@nagat01
Created September 2, 2024 12:00
Show Gist options
  • Select an option

  • Save nagat01/13e99fb17d4080da6be75e0953c8052c to your computer and use it in GitHub Desktop.

Select an option

Save nagat01/13e99fb17d4080da6be75e0953c8052c to your computer and use it in GitHub Desktop.
trait Show[T]:
def show(value: T): String
given Show[Int] with
def show(value: Int) = s"Int: $value"
given Show[String] with
def show(value: String) = s"String: $value"
class Printer1[T](value: T)(using ctx: Show[T]):
println(ctx.show(value))
class Printer2[T: Show](value: T):
println(summon[Show[T]].show(value))
@main def main = {
Printer1(42)
Printer2("Scala 3")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment