Skip to content

Commit 130ba91

Browse files
committed
Add formatters for Option & Map
1 parent cba1cfc commit 130ba91

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,21 @@ object Formatting {
5454
object Show extends ShowImplicits1:
5555
inline def apply[A](using inline z: Show[A]): Show[A] = z
5656

57+
given [X: Show]: Show[Option[X]] with
58+
def show(x: Option[X]) = new CtxShow:
59+
def run(using Context) = x.map(show1)
60+
end given
61+
5762
given [X: Show]: Show[Seq[X]] with
5863
def show(x: Seq[X]) = new CtxShow:
5964
def run(using Context) = x.map(show1)
6065

66+
given [K: Show, V: Show]: Show[Map[K, V]] with
67+
def show(x: Map[K, V]) = new CtxShow:
68+
def run(using Context) =
69+
x.map((k, v) => s"${show1(k)} => ${show1(v)}")
70+
end given
71+
6172
given [H: Show, T <: Tuple: Show]: Show[H *: T] with
6273
def show(x: H *: T) = new CtxShow:
6374
def run(using Context) = show1(x.head) *: Show[T].show(x.tail).ctxShow.asInstanceOf[Tuple]

0 commit comments

Comments
 (0)