Created
July 20, 2011 11:30
-
-
Save yusuke/1094792 to your computer and use it in GitHub Desktop.
#daimon.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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