Skip to content

Instantly share code, notes, and snippets.

@yusuke
Created July 20, 2011 11:30
Show Gist options
  • Save yusuke/1094792 to your computer and use it in GitHub Desktop.
Save yusuke/1094792 to your computer and use it in GitHub Desktop.
#daimon.scala
package scala
object ob {
class ReversibleString(str: String) {
def reverseOrder() = {
str.split("").reverse.mkString
}
def reverseCases() = {
def reverseCase(c: Char): Char = {
c match {
case c if c.isUpper => c.toLower
case c if c.isLower => c.toUpper
case _ => c
}
}
{
for (c <- str.toCharArray) yield reverseCase(c)
}.mkString
}
}
implicit def bindReversibleMethods(str: String) = new ReversibleString(str)
def main(args: Array[String]) {
println("AbcDEf123".reverseOrder())
println("AbcDEf123".reverseCases())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment