// Created on savesnippets.com · https://savesnippets.com/J7k6p3yhPxa12f // Without `inline` — every call allocates a Function object for the lambda fun runIfTrue(condition: Boolean, action: () -> Unit) { if (condition) action() } // With `inline` — the lambda body is inlined at the call site inline fun runIfTrueFast(condition: Boolean, action: () -> Unit) { if (condition) action() } // Non-local return: only legal in inline lambdas fun findUser(users: List): String? { users.forEach { name -> // forEach is inline in stdlib if (name.startsWith("a")) return name // returns from findUser! } return null } // `crossinline` if you can\'t allow non-local return inline fun delayed(crossinline action: () -> Unit) { Thread { action() }.start() // can't `return` out of action here } fun main() { runIfTrueFast(true) { println("hello") } println(findUser(listOf("bob", "alice", "carol"))) // alice }