Created
March 27, 2024 04:35
-
-
Save nafg/6bcc76d15615867309928219c9e30f71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printTable[A](rows: Seq[A], header: String*)(f: A => Seq[String]) = { | |
val rowsStrings = rows.map(f) | |
val cells = header +: rowsStrings | |
val widths = cells.transpose.map(_.map(_.length).max) | |
val format = widths.map("%-" + _ + "s").mkString(" | ") | |
val headerStr = format.format(header *) | |
val separator = widths.map("-" * _).mkString("-+-", "-+-", "-") | |
val rowsStr = rowsStrings.map(format.format(_ *)).mkString("\n") | |
println(s"$headerStr\n$separator\n$rowsStr") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment