object PrintableSyntax {
implicit class PrintableOps[A](value: A) {
def format(implicit p: Printable[A]): String =
Printable.format(value)
def print(implicit p: Printable[A]): Unit =
Printable.print(value)
}
}
I'd suggest it's better to use the type class instance directly instead of depending on and mixing with Printable object which is another approach to using type class:
object PrintableSyntax {
implicit class PrintableOps[A](value: A) {
def format(implicit p: Printable[A]): String = p.format(value)
def print(implicit p: Printable[A]): Unit = println(format(p))
}
}
I think this better reflect the purpose of the exercise and the actual use case.
From PrintableSyntax solution:
I'd suggest it's better to use the type class instance directly instead of depending on and mixing with Printable object which is another approach to using type class:
I think this better reflect the purpose of the exercise and the actual use case.