aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-30 16:07:02 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-11-30 16:56:00 +0100
commit214258f54ebc7f8d9118aa3f84902d3b186742f7 (patch)
tree2efd3d8e42973a532e99e65c53241ec0f4a58d66 /library
parent8a754cfdef89a57a9c0139c3cc767b1f5351f1db (diff)
downloaddotty-214258f54ebc7f8d9118aa3f84902d3b186742f7.tar.gz
dotty-214258f54ebc7f8d9118aa3f84902d3b186742f7.tar.bz2
dotty-214258f54ebc7f8d9118aa3f84902d3b186742f7.zip
Add documentation to `Show`
Diffstat (limited to 'library')
-rw-r--r--library/src/dotty/Show.scala13
1 files changed, 10 insertions, 3 deletions
diff --git a/library/src/dotty/Show.scala b/library/src/dotty/Show.scala
index 2febda0e7..21f80c7c5 100644
--- a/library/src/dotty/Show.scala
+++ b/library/src/dotty/Show.scala
@@ -7,20 +7,27 @@ trait Show[-T] {
def show(t: T): String
}
+/** Ideally show would only contain `defaultShow` and the pimped generic class,
+ * but since we can't change the current stdlib, we're stuck with providing
+ * default instances in this object
+ */
object Show {
private[this] val defaultShow = new Show[Any] {
def show(x: Any) = x.toString
}
+ /** This class implements pimping of all types to provide a show method.
+ * Currently it is quite permissive, if there's no instance of `Show[T]` for
+ * any `T`, we default to `T#toString`.
+ */
implicit class ShowValue[V](val v: V) extends AnyVal {
def show(implicit ev: Show[V] = defaultShow): String =
ev.show(v)
}
implicit val stringShow = new Show[String] {
- // From 2.12 spec:
- //
- // charEscapeSeq ::= ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘)
+ // From 2.12 spec, `charEscapeSeq`:
+ // ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘)
def show(str: String) =
"\"" + {
val sb = new StringBuilder