File tree 1 file changed +10
-3
lines changed
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -7,20 +7,27 @@ trait Show[-T] {
7
7
def show (t : T ): String
8
8
}
9
9
10
+ /** Ideally show would only contain `defaultShow` and the pimped generic class,
11
+ * but since we can't change the current stdlib, we're stuck with providing
12
+ * default instances in this object
13
+ */
10
14
object Show {
11
15
private [this ] val defaultShow = new Show [Any ] {
12
16
def show (x : Any ) = x.toString
13
17
}
14
18
19
+ /** This class implements pimping of all types to provide a show method.
20
+ * Currently it is quite permissive, if there's no instance of `Show[T]` for
21
+ * any `T`, we default to `T#toString`.
22
+ */
15
23
implicit class ShowValue [V ](val v : V ) extends AnyVal {
16
24
def show (implicit ev : Show [V ] = defaultShow): String =
17
25
ev.show(v)
18
26
}
19
27
20
28
implicit val stringShow = new Show [String ] {
21
- // From 2.12 spec:
22
- //
23
- // charEscapeSeq ::= ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘)
29
+ // From 2.12 spec, `charEscapeSeq`:
30
+ // ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘)
24
31
def show (str : String ) =
25
32
" \" " + {
26
33
val sb = new StringBuilder
You can’t perform that action at this time.
0 commit comments