run
1
2
3
public inline fun <T, R> T.run(block: T.() -> R): R {
return block()
}
with
1
2
3
public inline fun <T, R> with(receiver: T, block: T.() -> R): R {
return receiver.block()
}
apply
1
2
3
4
public inline fun <T> T.apply(block: T.() -> Unit): T {
block()
return this
}
also
1
2
3
4
public inline fun <T> T.also(block: (T) -> Unit): T {
block(this)
return this
}
let
1
2
3
public inline fun <T, R> T.let(block: (T) -> R): R {
return block(this)
}
Scope Function의 응용 예시는 여기에서 자세하게 확인할 수 있다.