-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Simplify REPL #3560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify REPL #3560
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,21 +28,22 @@ object Show { | |
implicit val stringShow: Show[String] = new Show[String] { | ||
// From 2.12 spec, `charEscapeSeq`: | ||
// ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘) | ||
def show(str: String) = | ||
"\"" + { | ||
val sb = new StringBuilder | ||
str.foreach { | ||
case '\b' => sb.append("\\b") | ||
case '\t' => sb.append("\\t") | ||
case '\n' => sb.append("\\n") | ||
case '\f' => sb.append("\\f") | ||
case '\r' => sb.append("\\r") | ||
case '\'' => sb.append("\\'") | ||
case '\"' => sb.append("\\\"") | ||
case c => sb.append(c) | ||
} | ||
sb.toString | ||
} + "\"" | ||
def show(str: String) = { | ||
val sb = new StringBuilder | ||
sb.append("\"") | ||
str.foreach { | ||
case '\b' => sb.append("\\b") | ||
case '\t' => sb.append("\\t") | ||
case '\n' => sb.append("\\n") | ||
case '\f' => sb.append("\\f") | ||
case '\r' => sb.append("\\r") | ||
case '\'' => sb.append("\\'") | ||
case '\"' => sb.append("\\\"") | ||
case c => sb.append(c) | ||
} | ||
sb.append("\"") | ||
sb.toString | ||
} | ||
} | ||
|
||
implicit val intShow: Show[Int] = new Show[Int] { | ||
|
@@ -72,12 +73,12 @@ object Show { | |
|
||
implicit def showList[T](implicit st: Show[T]): Show[List[T]] = new Show[List[T]] { | ||
def show(xs: List[T]) = | ||
if (xs.isEmpty) "Nil" | ||
if (xs.isEmpty) "List()" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
else "List(" + xs.map(_.show).mkString(", ") + ")" | ||
} | ||
|
||
implicit val showNil: Show[Nil.type] = new Show[Nil.type] { | ||
def show(xs: Nil.type) = "Nil" | ||
def show(xs: Nil.type) = "List()" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is what scalac does: scala> List()
res0: List[Nothing] = List()
scala> List(1, 2)
res1: List[Int] = List(1, 2) I think it is more consistent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ¯\__(ツ)_/¯ Sounds like a debate for the ages. I'm definitely fine with the change, just wanted to know if there was some other motive beside the superficial one :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Purely superficial =) |
||
} | ||
|
||
implicit def showOption[T](implicit st: Show[T]): Show[Option[T]] = new Show[Option[T]] { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?