I can’t understand how the fun inside the foreach being called, like this example from kotlin documentation:
fun foo() {
listOf(1, 2, 3, 4, 5).forEach(fun(value: Int) {
if (value == 3) return // local return to the caller of the anonymous fun, i.e. the forEach loop
print(value)
})
print(" done with anonymous function")
}
[https://kotlinlang.org/docs/reference/returns.html#return-at-labels]