The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

mortenjohs (1) [Avatar] Offline
#1
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
wfreeman (1) [Avatar] Offline
#2
Re: Misleading Ruby Example?
Yeah, and the scala example doesn't seem the best either.

val count = scala.io.Source.fromFile("test.txt").getLines().size
nraychaudhuri (19) [Avatar] Offline
#3
Re: Misleading Ruby Example?
My intention was not showing how much better Scala is from Ruby but rather that it could be very similar to Ruby but still be statically typed checked. I hope that was clear from the text. Thanks for the input. I will make sure I use the right now for the 2nd edition.