The Algebra of Pretty Printing

This article shows how to create a “pretty printer” in Scala 3. In the process it shows a little bit about domain modeling using ADTs using the Scala 3 enum.

From the article:

“Pretty printing is the problem of printing structured data in a user friendly manner with some constraints. Linters, code transformers and debuggers all have some form of pretty printers present in them. Pretty printing can be seen as the dual of parsing, and they both share similar complexities when trying to make reusable libraries.

Functional programming has a rather interesting take on pretty printing. Exploring a functional design of a pretty printer will be the primary focus of this article.”