From 47cf808e8f67c2aaca1b01734fd4a59c8cdf9726 Mon Sep 17 00:00:00 2001 From: jilen Date: Sun, 29 Dec 2024 20:19:07 +0800 Subject: [PATCH] simplify typeclass --- src/main/scala/minisql/util/Show.scala | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/scala/minisql/util/Show.scala b/src/main/scala/minisql/util/Show.scala index b4acc97..3496caf 100644 --- a/src/main/scala/minisql/util/Show.scala +++ b/src/main/scala/minisql/util/Show.scala @@ -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(", ") }