Skip to content

Commit

Permalink
Add formatters for Option & Map
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Feb 12, 2024
1 parent cba1cfc commit 130ba91
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,21 @@ object Formatting {
object Show extends ShowImplicits1:
inline def apply[A](using inline z: Show[A]): Show[A] = z

given [X: Show]: Show[Option[X]] with
def show(x: Option[X]) = new CtxShow:
def run(using Context) = x.map(show1)
end given

given [X: Show]: Show[Seq[X]] with
def show(x: Seq[X]) = new CtxShow:
def run(using Context) = x.map(show1)

given [K: Show, V: Show]: Show[Map[K, V]] with
def show(x: Map[K, V]) = new CtxShow:
def run(using Context) =
x.map((k, v) => s"${show1(k)} => ${show1(v)}")
end given

given [H: Show, T <: Tuple: Show]: Show[H *: T] with
def show(x: H *: T) = new CtxShow:
def run(using Context) = show1(x.head) *: Show[T].show(x.tail).ctxShow.asInstanceOf[Tuple]
Expand Down

0 comments on commit 130ba91

Please sign in to comment.