RosettaCodeData/Task/Mad-Libs/Scala/mad-libs.scala
2023-07-01 13:44:08 -04:00

14 lines
427 B
Scala

object MadLibs extends App{
val input = "<name> went for a walk in the park. <he or she>\nfound a <noun>. <name> decided to take it home."
println(input)
println
val todo = "(<[^>]+>)".r
val replacements = todo.findAllIn(input).toSet.map{found: String =>
found -> readLine(s"Enter a $found ")
}.toMap
val output = todo.replaceAllIn(input, found => replacements(found.matched))
println
println(output)
}