@@ -21,12 +21,16 @@ object trace {
21
21
}
22
22
23
23
@ inline
24
- def apply [T ](question : => String , printer : Printers .Printer , show : Boolean )(op : => T )(implicit ctx : Context ): T = {
24
+ def apply [T ](question : => String , printer : Printers .Printer , showOp : Any => String )(op : => T )(implicit ctx : Context ): T = {
25
25
def op1 = op
26
26
if (! Config .tracingEnabled || printer.eq(config.Printers .noPrinter)) op1
27
- else doTrace[T ](question, printer, show )(op1)
27
+ else doTrace[T ](question, printer, showOp )(op1)
28
28
}
29
29
30
+ @ inline
31
+ def apply [T ](question : => String , printer : Printers .Printer , show : Boolean )(op : => T )(implicit ctx : Context ): T =
32
+ apply[T ](question, printer, if (show) showShowable(_) else alwaysToString)(op)
33
+
30
34
@ inline
31
35
def apply [T ](question : => String , printer : Printers .Printer )(op : => T )(implicit ctx : Context ): T =
32
36
apply[T ](question, printer, false )(op)
@@ -39,16 +43,21 @@ object trace {
39
43
def apply [T ](question : => String )(op : => T )(implicit ctx : Context ): T =
40
44
apply[T ](question, Printers .default, false )(op)
41
45
42
- private def doTrace [T ](question : => String , printer : Printers .Printer = Printers .default, show : Boolean = false )
43
- (op : => T )(implicit ctx : Context ): T = {
44
- def resStr (res : Any ): String = res match {
45
- case res : printing.Showable if show => res.show
46
- case _ => String .valueOf(res)
47
- }
46
+ private def showShowable (x : Any )(implicit ctx : Context ) = x match {
47
+ case x : printing.Showable => x.show
48
+ case _ => String .valueOf(x)
49
+ }
50
+
51
+ private val alwaysToString = (x : Any ) => String .valueOf(x)
52
+
53
+ private def doTrace [T ](question : => String ,
54
+ printer : Printers .Printer = Printers .default,
55
+ showOp : Any => String = alwaysToString)
56
+ (op : => T )(implicit ctx : Context ): T = {
48
57
// Avoid evaluating question multiple time, since each evaluation
49
58
// may cause some extra logging output.
50
59
lazy val q : String = question
51
- apply[T ](s " ==> $q? " , (res : Any ) => s " <== $q = ${resStr (res)}" )(op)
60
+ apply[T ](s " ==> $q? " , (res : Any ) => s " <== $q = ${showOp (res)}" )(op)
52
61
}
53
62
54
63
def apply [T ](leading : => String , trailing : Any => String )(op : => T )(implicit ctx : Context ): T =
0 commit comments