diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-11-30 15:17:14 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-11-30 16:55:59 +0100 |
commit | a190cfe4f0ece8221d8d7e4b27e4bf73ca665a56 (patch) | |
tree | 8caff7661ea7055db1359463e11d9704366a905e /library/src | |
parent | 8b7a7ea0cf25b55ea842fe1f299e1576b8bc3e5a (diff) | |
download | dotty-a190cfe4f0ece8221d8d7e4b27e4bf73ca665a56.tar.gz dotty-a190cfe4f0ece8221d8d7e4b27e4bf73ca665a56.tar.bz2 dotty-a190cfe4f0ece8221d8d7e4b27e4bf73ca665a56.zip |
Get rid of nesting implicits
Diffstat (limited to 'library/src')
-rw-r--r-- | library/src/dotty/Show.scala | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/library/src/dotty/Show.scala b/library/src/dotty/Show.scala index 123fffdc7..103341d00 100644 --- a/library/src/dotty/Show.scala +++ b/library/src/dotty/Show.scala @@ -15,7 +15,9 @@ object Show { } implicit val stringShow = new Show[String] { - //charEscapeSeq ::= ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘) + // From 2.12 spec: + // + // charEscapeSeq ::= ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘) def show(str: String) = "\"" + str @@ -54,35 +56,33 @@ object Show { }) + "'" } - object List { - implicit def showList[T](implicit st: Show[T]) = new Show[List[T]] { - def show(xs: List[T]) = - if (xs.isEmpty) "Nil" - else "List(" + xs.map(_.show).mkString(", ") + ")" - } + implicit def showList[T](implicit st: Show[T]) = new Show[List[T]] { + def show(xs: List[T]) = + if (xs.isEmpty) "Nil" + else "List(" + xs.map(_.show).mkString(", ") + ")" + } - implicit val showNil = new Show[List[Nothing]] { - def show(xs: List[Nothing]) = "Nil" - } + implicit val showNil = new Show[List[Nothing]] { + def show(xs: List[Nothing]) = "Nil" } - object Option { - implicit def showOption[T](implicit st: Show[T]) = new Show[Option[T]] { - def show(ot: Option[T]): String = ot match { - case Some(t) => "Some("+ st.show(t) + ")" - case none => "None" - } + implicit def showOption[T](implicit st: Show[T]) = new Show[Option[T]] { + def show(ot: Option[T]): String = ot match { + case Some(t) => "Some("+ st.show(t) + ")" + case none => "None" } + } - implicit val showNone = new Show[Option[Nothing]] { - def show(n: Option[Nothing]) = "None" - } + implicit val showNone = new Show[Option[Nothing]] { + def show(n: Option[Nothing]) = "None" } - object Map { - implicit def showMap[K, V](implicit sk: Show[K], sv: Show[V]) = new Show[Map[K, V]] { - def show(m: Map[K, V]) = - "Map(" + m.map { case (k, v) => sk.show(k) + " -> " + sv.show(v) } .mkString (", ") + ")" - } + implicit def showMap[K, V](implicit sk: Show[K], sv: Show[V]) = new Show[Map[K, V]] { + def show(m: Map[K, V]) = + "Map(" + m.map { case (k, v) => sk.show(k) + " -> " + sv.show(v) } .mkString (", ") + ")" + } + + implicit def showMapOfNothing = new Show[Map[Nothing, Nothing]] { + def show(m: Map[Nothing, Nothing]) = m.toString } } |