why does this compile : `listOf(1,2,3,4).fold("") ...
# announcements
t
why does this compile :
listOf(1,2,3,4).fold("") { acc, i -> acc }
but this doesn't
listOf(1,2,3,4).fold("") { acc, i -> { acc } }
Or put another way : How do I write fold that is multi-statements and has some variables?
r
Because your second version is returning a lambda instead of a String.
e
just like any other lambda,
Copy code
listOf(1, 2, 3, 4).fold("") { acc, i ->
    statement1
    statement2
}
(or separate them with semicolons, but why would you do that)
1
t
@Ruckus Yes.. I see that. Makes sense now. thanks
👍 1
@ephemient I could have sworn I tired that and got the same error. but clearly I didn't cuz it works 🙂 thanks