filterNotTo

inline fun <T, C : MutableCollection<in T>> Array<out T>.filterNotTo(destination: C, predicate: (T) -> Boolean): C(source)
inline fun <C : MutableCollection<in Byte>> ByteArray.filterNotTo(destination: C, predicate: (Byte) -> Boolean): C(source)
inline fun <C : MutableCollection<in Short>> ShortArray.filterNotTo(destination: C, predicate: (Short) -> Boolean): C(source)
inline fun <C : MutableCollection<in Int>> IntArray.filterNotTo(destination: C, predicate: (Int) -> Boolean): C(source)
inline fun <C : MutableCollection<in Long>> LongArray.filterNotTo(destination: C, predicate: (Long) -> Boolean): C(source)
inline fun <C : MutableCollection<in Float>> FloatArray.filterNotTo(destination: C, predicate: (Float) -> Boolean): C(source)
inline fun <C : MutableCollection<in Double>> DoubleArray.filterNotTo(destination: C, predicate: (Double) -> Boolean): C(source)
inline fun <C : MutableCollection<in Boolean>> BooleanArray.filterNotTo(destination: C, predicate: (Boolean) -> Boolean): C(source)
inline fun <C : MutableCollection<in Char>> CharArray.filterNotTo(destination: C, predicate: (Char) -> Boolean): C(source)
inline fun <T, C : MutableCollection<in T>> Iterable<T>.filterNotTo(destination: C, predicate: (T) -> Boolean): C(source)

Appends all elements not matching the given predicate to the given destination.

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val numbers: List<Int> = listOf(1, 2, 3, 4, 5, 6, 7)
val evenNumbers = mutableListOf<Int>()
val notMultiplesOf3 = mutableListOf<Int>()

println(evenNumbers) // []

numbers.filterTo(evenNumbers) { it % 2 == 0 }
numbers.filterNotTo(notMultiplesOf3) { number -> number % 3 == 0 }

println(evenNumbers) // [2, 4, 6]
println(notMultiplesOf3) // [1, 2, 4, 5, 7] 
   //sampleEnd
}

inline fun <C : MutableCollection<in UInt>> UIntArray.filterNotTo(destination: C, predicate: (UInt) -> Boolean): C(source)
inline fun <C : MutableCollection<in ULong>> ULongArray.filterNotTo(destination: C, predicate: (ULong) -> Boolean): C(source)
inline fun <C : MutableCollection<in UByte>> UByteArray.filterNotTo(destination: C, predicate: (UByte) -> Boolean): C(source)
inline fun <C : MutableCollection<in UShort>> UShortArray.filterNotTo(destination: C, predicate: (UShort) -> Boolean): C(source)

Appends all elements not matching the given predicate to the given destination.

Since Kotlin

1.3

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val numbers: List<Int> = listOf(1, 2, 3, 4, 5, 6, 7)
val evenNumbers = mutableListOf<Int>()
val notMultiplesOf3 = mutableListOf<Int>()

println(evenNumbers) // []

numbers.filterTo(evenNumbers) { it % 2 == 0 }
numbers.filterNotTo(notMultiplesOf3) { number -> number % 3 == 0 }

println(evenNumbers) // [2, 4, 6]
println(notMultiplesOf3) // [1, 2, 4, 5, 7] 
   //sampleEnd
}

inline fun <K, V, M : MutableMap<in K, in V>> Map<out K, V>.filterNotTo(destination: M, predicate: (Map.Entry<K, V>) -> Boolean): M(source)

Appends all entries not matching the given predicate into the given destination.

Since Kotlin

1.0

Return

the destination map.

Samples

import kotlin.test.*
import java.util.*

fun main() { 
   //sampleStart 
   val originalMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3)
val destinationMap = mutableMapOf("key40" to 40, "key50" to 50)

val filteredMap = originalMap.filterNotTo(destinationMap) { it.value < 3 }
//destination map instance has been updated
println("destinationMap === filteredMap is ${destinationMap === filteredMap}") // true
println(destinationMap) // {key40=40, key50=50, key3=3}
// original map has not changed
println(originalMap) // {key1=1, key2=2, key3=3}

val anotherDestinationMap = mutableMapOf("key40" to 40, "key50" to 50)
val matchAllPredicate: ((Map.Entry<String, Int>)) -> Boolean = { it.value > 0 }
val filteredMapWithEverythingMatched = originalMap.filterNotTo(anotherDestinationMap, matchAllPredicate)
println(filteredMapWithEverythingMatched) // {key40=40, key50=50} 
   //sampleEnd
}