Introduce 'takeUnless' function which is like 'takeIf' but with the predicate inverted.
#KT-7858
This commit is contained in:
@@ -23,4 +23,6 @@ class C {
|
|||||||
// ORDER: nullableX
|
// ORDER: nullableX
|
||||||
// ORDER: takeIf
|
// ORDER: takeIf
|
||||||
// ORDER: takeIf
|
// ORDER: takeIf
|
||||||
|
// ORDER: takeUnless
|
||||||
|
// ORDER: takeUnless
|
||||||
// ORDER: C
|
// ORDER: C
|
||||||
|
|||||||
@@ -68,6 +68,13 @@ public inline fun <T, R> T.let(block: (T) -> R): R = block(this)
|
|||||||
@SinceKotlin("1.1")
|
@SinceKotlin("1.1")
|
||||||
public inline fun <T> T.takeIf(predicate: (T) -> Boolean): T? = if (predicate(this)) this else null
|
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].
|
* Executes the given function [action] specified number of [times].
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user