Return in lambda expression

Hi,
I’m working on lambda expression

I wrote this code :

val calcul:(Int, Int)->Int={x: Int, y: Int -> val z = x+y
z}

exverything is OK
Now I try to use return as in the doc

val calcul:(Int, Int)->Int={x: Int, y: Int -> val z = x+y
return@calcul z}

I have got an error :
ERROR ‘return’ is not allowed here (Line_83.kts:2:1)

Why this error?

It doesn’t create an implicit label in this case, you have to create it explicitly:

val calcul:(Int, Int)->Int= calcul@ {x: Int, y: Int -> val z = x+y
return@calcul z}
2 Likes