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
|
package minisql.util
|
||||||
|
|
||||||
object Show {
|
trait Show[T] {
|
||||||
trait Show[T] {
|
extension (v: T) {
|
||||||
def show(v: T): String
|
def show: String
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
object Show {
|
object Show {
|
||||||
def apply[T](f: T => String) = new Show[T] {
|
|
||||||
def show(v: T) = f(v)
|
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]) {
|
given listShow[T](using shower: Show[T]): Show[List[T]] =
|
||||||
def show = shower.show(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
implicit def listShow[T](implicit shower: Show[T]): Show[List[T]] =
|
|
||||||
Show[List[T]] {
|
Show[List[T]] {
|
||||||
case list => list.map(_.show).mkString(", ")
|
case list => list.map(_.show).mkString(", ")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue