Skip to content

Commit 7729c87

Browse files
committed
Add documentation to Show
1 parent 6eb448d commit 7729c87

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

library/src/dotty/Show.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,27 @@ trait Show[-T] {
77
def show(t: T): String
88
}
99

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+
*/
1014
object Show {
1115
private[this] val defaultShow = new Show[Any] {
1216
def show(x: Any) = x.toString
1317
}
1418

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+
*/
1523
implicit class ShowValue[V](val v: V) extends AnyVal {
1624
def show(implicit ev: Show[V] = defaultShow): String =
1725
ev.show(v)
1826
}
1927

2028
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‘ | ‘"‘ | ‘'‘ | ‘\‘)
2431
def show(str: String) =
2532
"\"" + {
2633
val sb = new StringBuilder

0 commit comments

Comments
 (0)