Skip to content

Commit d43670e

Browse files
committed
doc update
1 parent eefef25 commit d43670e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ public inline fun <T> T.takeUnless(predicate: (T) -> Boolean): T? {
285285
if (it.name == "Alice") return@forEach
286286
}
287287

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+
288299
## infix
289300
* In an infix call, the method name is placed immediately between the target object
290301
name and the parameter, with no extra separators

0 commit comments

Comments
 (0)