Created
February 1, 2012 23:33
-
-
Save scsibug/1720157 to your computer and use it in GitHub Desktop.
censor (7 languages in 7 weeks, Scala chapter)
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
trait Censor { | |
val replacements = Map("Shoot" -> "Pucky", | |
"Darn" -> "Beans") | |
// Censor a string with multiple words | |
def censor(s:String):String = { | |
(s /: replacements){case (a,(k,v)) => a.replaceAll(k,v)} | |
} | |
} | |
object CensorApp extends Censor { | |
def main(args: Array[String]) { | |
println(censor("Darn, I wanted to Shoot")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment