diff --git a/idea/idea-completion/testData/weighers/smart/SmartPriority.kt b/idea/idea-completion/testData/weighers/smart/SmartPriority.kt index 12408c8ca63..aa3b06f690a 100644 --- a/idea/idea-completion/testData/weighers/smart/SmartPriority.kt +++ b/idea/idea-completion/testData/weighers/smart/SmartPriority.kt @@ -23,4 +23,6 @@ class C { // ORDER: nullableX // ORDER: takeIf // ORDER: takeIf +// ORDER: takeUnless +// ORDER: takeUnless // ORDER: C diff --git a/libraries/stdlib/src/kotlin/util/Standard.kt b/libraries/stdlib/src/kotlin/util/Standard.kt index 8230397d539..ab1835108af 100644 --- a/libraries/stdlib/src/kotlin/util/Standard.kt +++ b/libraries/stdlib/src/kotlin/util/Standard.kt @@ -68,6 +68,13 @@ public inline fun T.let(block: (T) -> R): R = block(this) @SinceKotlin("1.1") public inline fun 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.takeUnless(predicate: (T) -> Boolean): T? = if (!predicate(this)) this else null + /** * Executes the given function [action] specified number of [times]. *