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 9, 2024
1 parent cba1cfc commit 54fd71e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 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,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]
Expand Down

0 comments on commit 54fd71e

Please sign in to comment.