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.

ospatil (2) [Avatar] Offline
#1
The following example in the section "Passing in code so that we still honor DRY" in Chapter 3 seems incorrect -

And finally, we can express op inside fold as this...
[pre]
def foldLeft(list:Array[Int], acc:Int, op):Int = {
if (list.isEmpty) return acc
foldLeft(op(list.head), acc, list.tail, op)
}
[/pre]
While foldLeft only accepts three arguments, the recursive call on the the last line in above snippet is passing four arguments to it.
aslam.khan (50) [Avatar] Offline
#2
Re: Chapter 3 p.83 - incorrect foldLeft example
Thank you for spotting that error. The correct code is

[pre]
def foldLeft(list:Array[Int], acc:Int, op):Int = {
if (list.isEmpty) return acc
foldLeft(list.tail, op(list.head,acc), op)
}
[/pre]