I have two examples of foldLeft that I cannot really grasp the logic.
First example:
val donuts: List[String] = List("Plain", "Strawberry", "Glazed")
println(donuts.foldLeft("")((acc, curr) => s" $acc, $curr Donut ")) // acc for accumulated, curr for current
This will give
, Plain Donut , Strawberry Donut , Glazed Donut
Does not foldLeft accumulate value that was earlier?
I was expecting the result to be
, Plain Donut , Plain Strawberry Donut , Strawberry Glazed Donut
Second example:
def multi(num:Int,num1:Int):Int=num*10
(1 until 3).foldLeft(1)(multi)
Can someone explain what is happening in every step? I cannot see how this can become 100. Also, the second argument multi is a function. Why does it not take any input variables (num and num1)?