Introduce new scope function: 'also'. Works like 'apply' but with 'it' instead of 'this' inside lambda.

#KT-6903
This commit is contained in:
Ilya Gorbunov
2017-01-12 04:57:38 +03:00
parent 0ef1234f2e
commit 1ac9815d76
+7 -1
View File
@@ -48,13 +48,19 @@ public inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block
@kotlin.internal.InlineOnly
public inline fun <T> T.apply(block: T.() -> Unit): T { block(); return this }
/**
* Calls the specified function [block] with `this` value as its argument and returns `this` value.
*/
@kotlin.internal.InlineOnly
@SinceKotlin("1.1")
public inline fun <T> T.also(block: (T) -> Unit): T { block(this); return this }
/**
* Calls the specified function [block] with `this` value as its argument and returns its result.
*/
@kotlin.internal.InlineOnly
public inline fun <T, R> T.let(block: (T) -> R): R = block(this)
/**
* Executes the given function [action] specified number of [times].
*