diff options
author | Martin Odersky <odersky@gmail.com> | 2014-10-17 15:28:17 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-10-26 16:24:00 +0100 |
commit | 25a8937f115ed2ac1af33c41c73a621dab4ee712 (patch) | |
tree | 2448efa9ddd72cea1f76635964567e7c3a638a79 | |
parent | 7eaee332674c16179221d12cba202d430bc3d5a3 (diff) | |
download | dotty-25a8937f115ed2ac1af33c41c73a621dab4ee712.tar.gz dotty-25a8937f115ed2ac1af33c41c73a621dab4ee712.tar.bz2 dotty-25a8937f115ed2ac1af33c41c73a621dab4ee712.zip |
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
-rw-r--r-- | src/dotty/tools/dotc/config/Printers.scala | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/config/Printers.scala b/src/dotty/tools/dotc/config/Printers.scala index 3926be59b..f8d7f8de5 100644 --- a/src/dotty/tools/dotc/config/Printers.scala +++ b/src/dotty/tools/dotc/config/Printers.scala @@ -4,10 +4,12 @@ object Printers { class Printer { def println(msg: => String): Unit = System.out.println(msg) + def echo[T](msg: => String, value: T): T = { println(msg + value); value } } object noPrinter extends Printer { override def println(msg: => String): Unit = () + override def echo[T](msg: => String, value: T): T = value } val default: Printer = new Printer |