Introduce 'takeUnless' function which is like 'takeIf' but with the predicate inverted.
#KT-7858
This commit is contained in:
@@ -68,6 +68,13 @@ public inline fun <T, R> T.let(block: (T) -> R): R = block(this)
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <T> T.takeIf(predicate: (T) -> Boolean): T? = if (predicate(this)) this else null
|
||||
|
||||
/**
|
||||
* Returns `this` value if it _does not_ satisfy the given [predicate] or `null`, if it does.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <T> T.takeUnless(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