Swanand Keskar
02/15/2021, 1:41 PMRoukanken
02/15/2021, 1:56 PMinline fun <T> decorator(crossinline block: () -> T): T {
println("Before")
val result = block()
println("After, returned $result")
return result
}
fun decorated() = decorator {
println("function!")
4
}
decorated()
eg smth like this would return 4 and print
Before
function!
After, returned 4
(crossinline stops it from being able to cut the "after" part of decorator with return)Swanand Keskar
02/15/2021, 2:00 PMAnimesh Sahu
02/15/2021, 2:57 PMdecorated()
here.Animesh Sahu
02/15/2021, 2:59 PM