simplify typeclass

This commit is contained in:
jilen 2024-12-29 20:19:07 +08:00
parent 7f5092c396
commit 47cf808e8f

View file

@ -1,21 +1,20 @@
package minisql.util
object Show {
trait Show[T] {
def show(v: T): String
trait Show[T] {
extension (v: T) {
def show: String
}
}
object Show {
def apply[T](f: T => String) = new Show[T] {
def show(v: T) = f(v)
object Show {
def apply[T](f: T => String) = new Show[T] {
extension (v: T) {
def show: String = f(v)
}
}
implicit class Shower[T](v: T)(implicit shower: Show[T]) {
def show = shower.show(v)
}
implicit def listShow[T](implicit shower: Show[T]): Show[List[T]] =
given listShow[T](using shower: Show[T]): Show[List[T]] =
Show[List[T]] {
case list => list.map(_.show).mkString(", ")
}