Skip to content

Instantly share code, notes, and snippets.

@philcali
Created August 6, 2012 16:05
Show Gist options
  • Save philcali/3275967 to your computer and use it in GitHub Desktop.
Save philcali/3275967 to your computer and use it in GitHub Desktop.
val Dollar = """\$\s*(\d+\.\d+)\s*""".r
import Dollar.{ findFirstMatchIn => line }
import io.Source.{ fromFile => open}
val sum = (0.00 /: open("expenses.txt").getLines)(_ + line(_).map(_.group(1).toDouble).getOrElse(0.0))
println("Total is: $%.2f" format sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment