filter Not
inline fun <T> Array<out T>.filterNot(predicate: (T) -> Boolean): List<T>
Content copied to clipboard
inline fun ShortArray.filterNot(predicate: (Short) -> Boolean): List<Short>
Content copied to clipboard
inline fun FloatArray.filterNot(predicate: (Float) -> Boolean): List<Float>
Content copied to clipboard
inline fun DoubleArray.filterNot(predicate: (Double) -> Boolean): List<Double>
Content copied to clipboard
inline fun BooleanArray.filterNot(predicate: (Boolean) -> Boolean): List<Boolean>
Content copied to clipboard
Returns a list containing all elements not matching the given predicate.
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
val numbers: List<Int> = listOf(1, 2, 3, 4, 5, 6, 7)
val evenNumbers = numbers.filter { it % 2 == 0 }
val notMultiplesOf3 = numbers.filterNot { number -> number % 3 == 0 }
assertPrints(evenNumbers, "[2, 4, 6]")
assertPrints(notMultiplesOf3, "[1, 2, 4, 5, 7]")
//sampleEnd
}
inline fun ULongArray.filterNot(predicate: (ULong) -> Boolean): List<ULong>
Content copied to clipboard
inline fun UByteArray.filterNot(predicate: (UByte) -> Boolean): List<UByte>
Content copied to clipboard
inline fun UShortArray.filterNot(predicate: (UShort) -> Boolean): List<UShort>
Content copied to clipboard
Returns a list containing all elements not matching the given predicate.
Since Kotlin
1.3
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
val numbers: List<Int> = listOf(1, 2, 3, 4, 5, 6, 7)
val evenNumbers = numbers.filter { it % 2 == 0 }
val notMultiplesOf3 = numbers.filterNot { number -> number % 3 == 0 }
assertPrints(evenNumbers, "[2, 4, 6]")
assertPrints(notMultiplesOf3, "[1, 2, 4, 5, 7]")
//sampleEnd
}
inline fun <K, V> Map<out K, V>.filterNot(predicate: (Map.Entry<K, V>) -> Boolean): Map<K, V>
Content copied to clipboard
Returns a new map containing all key-value pairs not matching the given predicate.
The returned map preserves the entry iteration order of the original map.
Samples
import samples.*
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
val originalMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3)
val filteredMap = originalMap.filterNot { it.value < 3 }
assertPrints(filteredMap, "{key3=3}")
// original map has not changed
assertPrints(originalMap, "{key1=1, key2=2, key3=3}")
val matchAllPredicate: ((Map.Entry<String, Int>)) -> Boolean = { it.value > 0 }
val emptyMap = originalMap.filterNot(matchAllPredicate)
assertPrints(emptyMap, "{}")
//sampleEnd
}