File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -285,6 +285,17 @@ public inline fun <T> T.takeUnless(predicate: (T) -> Boolean): T? {
285
285
if (it.name == "Alice") return@forEach
286
286
}
287
287
288
+ * Anonymous functions: local returns by default
289
+ fun lookForAlice(people: List<Person >) {
290
+ people.forEach(fun (person) {
291
+ if (person.name == "Alice") return // “return” refers to the closest function: an anonymous function
292
+ println("${person.name} is not Alice")
293
+ })
294
+ }
295
+ * The rule is simple: return returns
296
+ from the closest function declared using the fun keyword. Lambda expressions don’t use the
297
+ fun keyword, so a return in a lambda returns from the outer function.
298
+
288
299
## infix
289
300
* In an infix call, the method name is placed immediately between the target object
290
301
name and the parameter, with no extra separators
You can’t perform that action at this time.
0 commit comments