Skip to content

Instantly share code, notes, and snippets.

@seratch
Forked from akr4/gist:1094761
Created July 20, 2011 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seratch/1094823 to your computer and use it in GitHub Desktop.
Save seratch/1094823 to your computer and use it in GitHub Desktop.
Scala 練習問題 #daimonscala
class StringSupport(s: String) {
def reverseOrder: String = s.toList.foldLeft(Nil: List[Char])((result, c) => c :: result).mkString
def reverseCase: String = s.toList.map {
case c if c.isUpper => c.toLower
case c if c.isLower => c.toUpper
case c => c
}.mkString
}
object StringSupport {
implicit def convert(s: String): StringSupport = new StringSupport(s)
}
import StringSupport._
println("AbcDEf123".reverseOrder)
println("AbcDEf123".reverseCase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment