Skip to content

Commit 25a8937

Browse files
committed
Add echo method to printers.
It's often useful to print a value as it is returned. This method avoids the temporary variable to hold the vaue before it is printed and then return. I.e. printer.echo(msg, expr) instead of val x = expr printer.println(msg + x) x
1 parent 7eaee33 commit 25a8937

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/dotty/tools/dotc/config/Printers.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ object Printers {
44

55
class Printer {
66
def println(msg: => String): Unit = System.out.println(msg)
7+
def echo[T](msg: => String, value: T): T = { println(msg + value); value }
78
}
89

910
object noPrinter extends Printer {
1011
override def println(msg: => String): Unit = ()
12+
override def echo[T](msg: => String, value: T): T = value
1113
}
1214

1315
val default: Printer = new Printer

0 commit comments

Comments
 (0)