filterIndexedTo
inline fun <T, C : MutableCollection<in T>> Array<out T>.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C(source)
inline fun <C : MutableCollection<in Byte>> ByteArray.filterIndexedTo(destination: C, predicate: (index: Int, Byte) -> Boolean): C(source)
inline fun <C : MutableCollection<in Short>> ShortArray.filterIndexedTo(destination: C, predicate: (index: Int, Short) -> Boolean): C(source)
inline fun <C : MutableCollection<in Int>> IntArray.filterIndexedTo(destination: C, predicate: (index: Int, Int) -> Boolean): C(source)
inline fun <C : MutableCollection<in Long>> LongArray.filterIndexedTo(destination: C, predicate: (index: Int, Long) -> Boolean): C(source)
inline fun <C : MutableCollection<in Float>> FloatArray.filterIndexedTo(destination: C, predicate: (index: Int, Float) -> Boolean): C(source)
inline fun <C : MutableCollection<in Double>> DoubleArray.filterIndexedTo(destination: C, predicate: (index: Int, Double) -> Boolean): C(source)
inline fun <C : MutableCollection<in Boolean>> BooleanArray.filterIndexedTo(destination: C, predicate: (index: Int, Boolean) -> Boolean): C(source)
inline fun <C : MutableCollection<in Char>> CharArray.filterIndexedTo(destination: C, predicate: (index: Int, Char) -> Boolean): C(source)
inline fun <T, C : MutableCollection<in T>> Iterable<T>.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C(source)
Appends all elements matching the given predicate to the given destination.
Since Kotlin
1.0Parameters
predicate
function that takes the index of an element and the element itself and returns the result of predicate evaluation on the element.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val numbers: List<Int> = listOf(0, 1, 2, 3, 4, 8, 6)
val numbersOnSameIndexAsValue = mutableListOf<Int>()
println(numbersOnSameIndexAsValue) // []
numbers.filterIndexedTo(numbersOnSameIndexAsValue) { index, i -> index == i }
println(numbersOnSameIndexAsValue) // [0, 1, 2, 3, 4, 6]
//sampleEnd
}
inline fun <C : MutableCollection<in UInt>> UIntArray.filterIndexedTo(destination: C, predicate: (index: Int, UInt) -> Boolean): C(source)
inline fun <C : MutableCollection<in ULong>> ULongArray.filterIndexedTo(destination: C, predicate: (index: Int, ULong) -> Boolean): C(source)
inline fun <C : MutableCollection<in UByte>> UByteArray.filterIndexedTo(destination: C, predicate: (index: Int, UByte) -> Boolean): C(source)
inline fun <C : MutableCollection<in UShort>> UShortArray.filterIndexedTo(destination: C, predicate: (index: Int, UShort) -> Boolean): C(source)
Appends all elements matching the given predicate to the given destination.
Since Kotlin
1.3Parameters
predicate
function that takes the index of an element and the element itself and returns the result of predicate evaluation on the element.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val numbers: List<Int> = listOf(0, 1, 2, 3, 4, 8, 6)
val numbersOnSameIndexAsValue = mutableListOf<Int>()
println(numbersOnSameIndexAsValue) // []
numbers.filterIndexedTo(numbersOnSameIndexAsValue) { index, i -> index == i }
println(numbersOnSameIndexAsValue) // [0, 1, 2, 3, 4, 6]
//sampleEnd
}