Hi,
I appreciate the comparison to Ruby on page 15, but I find it rather misleading, as you can solve the problem of number of lines in file in a manner much closer to the proposed Scala solution by simply doing a:
src = File.new("someFile.txt")
count = (src.lines.map { |x| 1 }).inject(:+)
or, if you want, as the following one-liner:
count = (File.new("someFile.txt").lines.map {1}).inject(:+)
Thanks.
Morten
|