aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-30 15:17:14 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-11-30 16:55:59 +0100
commita190cfe4f0ece8221d8d7e4b27e4bf73ca665a56 (patch)
tree8caff7661ea7055db1359463e11d9704366a905e /library
parent8b7a7ea0cf25b55ea842fe1f299e1576b8bc3e5a (diff)
downloaddotty-a190cfe4f0ece8221d8d7e4b27e4bf73ca665a56.tar.gz
dotty-a190cfe4f0ece8221d8d7e4b27e4bf73ca665a56.tar.bz2
dotty-a190cfe4f0ece8221d8d7e4b27e4bf73ca665a56.zip
Get rid of nesting implicits
Diffstat (limited to 'library')
-rw-r--r--library/src/dotty/Show.scala48
-rw-r--r--library/test/dotty/ShowTests.scala8
2 files changed, 25 insertions, 31 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
}
}
diff --git a/library/test/dotty/ShowTests.scala b/library/test/dotty/ShowTests.scala
index 92539d0c4..7230106d5 100644
--- a/library/test/dotty/ShowTests.scala
+++ b/library/test/dotty/ShowTests.scala
@@ -34,7 +34,6 @@ class ShowTests {
}
@Test def showCar = {
- import Show.List._
case class Car(model: String, manufacturer: String, year: Int)
implicit val showCar = new Show[Car] {
def show(c: Car) =
@@ -51,14 +50,12 @@ class ShowTests {
}
@Test def showOptions = {
- import Show.Option._
assertEquals("None", None.show)
assertEquals("None", (None: Option[String]).show)
assertEquals("Some(\"hello opt\")", Some("hello opt").show)
}
@Test def showMaps = {
- import Show.Map._
val mp = scala.collection.immutable.Map("str1" -> "val1", "str2" -> "val2")
assertEquals("Map(\"str1\" -> \"val1\", \"str2\" -> \"val2\")", mp.show)
}
@@ -67,9 +64,6 @@ class ShowTests {
case class Car(model: String, manufacturer: String, year: Int)
assertEquals("Car(Mustang,Ford,1967)", Car("Mustang", "Ford", 1967).show)
- assertEquals(
- "Map(str1 -> val1, str2 -> val2)",
- scala.collection.immutable.Map("str1" -> "val1", "str2" -> "val2").show
- )
+ assertEquals("Map()", Map().show)
}
}