Skip to content

Commit 54fd71e

Browse files
committed
Add formatters for Option & Map
1 parent cba1cfc commit 54fd71e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,22 @@ 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 match
60+
case Some(x) => i"Some($x)"
61+
case None => "None"
62+
end given
63+
5764
given [X: Show]: Show[Seq[X]] with
5865
def show(x: Seq[X]) = new CtxShow:
5966
def run(using Context) = x.map(show1)
6067

68+
given [X: Show, Y: Show]: Show[Map[X, Y]] with
69+
def show(x: Map[X, Y]) = new CtxShow:
70+
def run(using Context) = x.map((x, y) => i"$x => $y")
71+
end given
72+
6173
given [H: Show, T <: Tuple: Show]: Show[H *: T] with
6274
def show(x: H *: T) = new CtxShow:
6375
def run(using Context) = show1(x.head) *: Show[T].show(x.tail).ctxShow.asInstanceOf[Tuple]

0 commit comments

Comments
 (0)