Introduce new function 'takeIf' to replace value with null if it doesn't match the predicate.
#KT-7858
This commit is contained in:
@@ -61,6 +61,13 @@ public inline fun <T> T.also(block: (T) -> Unit): T { block(this); return this }
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T, R> T.let(block: (T) -> R): R = block(this)
|
||||
|
||||
/**
|
||||
* Returns `this` value if it satisfies the given [predicate] or `null`, if it doesn't.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <T> T.takeIf(predicate: (T) -> Boolean): T? = if (predicate(this)) this else null
|
||||
|
||||
/**
|
||||
* Executes the given function [action] specified number of [times].
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user