Skip to content

Instantly share code, notes, and snippets.

@scsibug
Created February 1, 2012 23:33
Show Gist options
  • Save scsibug/1720157 to your computer and use it in GitHub Desktop.
Save scsibug/1720157 to your computer and use it in GitHub Desktop.
censor (7 languages in 7 weeks, Scala chapter)
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