simplify typeclass
This commit is contained in:
parent
7f5092c396
commit
47cf808e8f
1 changed files with 10 additions and 11 deletions
|
@ -1,21 +1,20 @@
|
|||
package minisql.util
|
||||
|
||||
trait Show[T] {
|
||||
extension (v: T) {
|
||||
def show: String
|
||||
}
|
||||
}
|
||||
|
||||
object Show {
|
||||
trait Show[T] {
|
||||
def show(v: T): String
|
||||
}
|
||||
|
||||
object Show {
|
||||
def apply[T](f: T => String) = new Show[T] {
|
||||
def show(v: T) = f(v)
|
||||
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(", ")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue