From 54fd71e9e37bea1aeaf8e8d855b7de3d2f0176ed Mon Sep 17 00:00:00 2001 From: Hamza REMMAL Date: Fri, 9 Feb 2024 14:51:24 +0100 Subject: [PATCH] Add formatters for Option & Map --- .../src/dotty/tools/dotc/printing/Formatting.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/printing/Formatting.scala b/compiler/src/dotty/tools/dotc/printing/Formatting.scala index 02f470324e8a..590d20716768 100644 --- a/compiler/src/dotty/tools/dotc/printing/Formatting.scala +++ b/compiler/src/dotty/tools/dotc/printing/Formatting.scala @@ -54,10 +54,22 @@ 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 match + case Some(x) => i"Some($x)" + case None => "None" + end given + given [X: Show]: Show[Seq[X]] with def show(x: Seq[X]) = new CtxShow: def run(using Context) = x.map(show1) + given [X: Show, Y: Show]: Show[Map[X, Y]] with + def show(x: Map[X, Y]) = new CtxShow: + def run(using Context) = x.map((x, y) => i"$x => $y") + 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]