filterIndexedTo
所在位置是kotlin.collections.filterIndexedTo
,其相關用法介紹如下。
用法:
inline fun <T, C : MutableCollection<in T>> Array<out T>.filterIndexedTo(
destination: C,
predicate: (index: Int, T) -> Boolean
): C
inline fun <C : MutableCollection<in Byte>> ByteArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Byte) -> Boolean
): C
inline fun <C : MutableCollection<in Short>> ShortArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Short) -> Boolean
): C
inline fun <C : MutableCollection<in Int>> IntArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Int) -> Boolean
): C
inline fun <C : MutableCollection<in Long>> LongArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Long) -> Boolean
): C
inline fun <C : MutableCollection<in Float>> FloatArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Float) -> Boolean
): C
inline fun <C : MutableCollection<in Double>> DoubleArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Double) -> Boolean
): C
inline fun <C : MutableCollection<in Boolean>> BooleanArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Boolean) -> Boolean
): C
inline fun <C : MutableCollection<in Char>> CharArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Char) -> Boolean
): C
inline fun <T, C : MutableCollection<in T>> Iterable<T>.filterIndexedTo(
destination: C,
predicate: (index: Int, T) -> Boolean
): C
@ExperimentalUnsignedTypes inline fun <C : MutableCollection<in UInt>> UIntArray.filterIndexedTo(
destination: C,
predicate: (index: Int, UInt) -> Boolean
): C
@ExperimentalUnsignedTypes inline fun <C : MutableCollection<in ULong>> ULongArray.filterIndexedTo(
destination: C,
predicate: (index: Int, ULong) -> Boolean
): C
@ExperimentalUnsignedTypes inline fun <C : MutableCollection<in UByte>> UByteArray.filterIndexedTo(
destination: C,
predicate: (index: Int, UByte) -> Boolean
): C
@ExperimentalUnsignedTypes inline fun <C : MutableCollection<in UShort>> UShortArray.filterIndexedTo(
destination: C,
predicate: (index: Int, UShort) -> Boolean
): C
將與給定 predicate 匹配的所有元素附加到給定 destination 。
例子:
import kotlin.test.*
fun main(args: Array<String>) {
//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
}
輸出:
[] [0, 1, 2, 3, 4, 6]
參數
相關用法
- Kotlin filterIndexedTo用法及代碼示例
- Kotlin filterIndexed用法及代碼示例
- Kotlin filterIsInstance用法及代碼示例
- Kotlin filterIsInstanceTo用法及代碼示例
- Kotlin filterNot用法及代碼示例
- Kotlin filterNotTo用法及代碼示例
- Kotlin filterKeys用法及代碼示例
- Kotlin filterTo用法及代碼示例
- Kotlin filterNotNull用法及代碼示例
- Kotlin filterNotNullTo用法及代碼示例
- Kotlin filterValues用法及代碼示例
- Kotlin filter用法及代碼示例
- Kotlin findLast用法及代碼示例
- Kotlin find用法及代碼示例
- Kotlin firstNotNullOf用法及代碼示例
- Kotlin firstNotNullOfOrNull用法及代碼示例
- Kotlin flatten用法及代碼示例
- Kotlin forEach用法及代碼示例
- Kotlin flatMap用法及代碼示例
- Kotlin fold用法及代碼示例
- Kotlin foldTo用法及代碼示例
- Kotlin flatMapIndexed用法及代碼示例
- Kotlin associateBy用法及代碼示例
- Kotlin all用法及代碼示例
- Kotlin map用法及代碼示例
注:本文由純淨天空篩選整理自kotlinlang.org大神的英文原創作品 kotlin.collections.filterIndexedTo。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。