Introduce 'takeUnless' function which is like 'takeIf' but with the predicate inverted.

#KT-7858
This commit is contained in:
Ilya Gorbunov
2017-02-09 22:24:45 +03:00
parent 9e1afe71f2
commit fee676a281
2 changed files with 9 additions and 0 deletions
@@ -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].
*