W3cubDocs

/Kotlin

dropWhile

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
inline fun <T> Array<out T>.dropWhile(
    predicate: (T) -> Boolean
): List<T>
inline fun ByteArray.dropWhile(
    predicate: (Byte) -> Boolean
): List<Byte>
inline fun ShortArray.dropWhile(
    predicate: (Short) -> Boolean
): List<Short>
inline fun IntArray.dropWhile(
    predicate: (Int) -> Boolean
): List<Int>
inline fun LongArray.dropWhile(
    predicate: (Long) -> Boolean
): List<Long>
inline fun FloatArray.dropWhile(
    predicate: (Float) -> Boolean
): List<Float>
inline fun DoubleArray.dropWhile(
    predicate: (Double) -> Boolean
): List<Double>
inline fun BooleanArray.dropWhile(
    predicate: (Boolean) -> Boolean
): List<Boolean>
inline fun CharArray.dropWhile(
    predicate: (Char) -> Boolean
): List<Char>
inline fun <T> Iterable<T>.dropWhile(
    predicate: (T) -> Boolean
): List<T>
@ExperimentalUnsignedTypes inline fun UIntArray.dropWhile(
    predicate: (UInt) -> Boolean
): List<UInt>
@ExperimentalUnsignedTypes inline fun ULongArray.dropWhile(
    predicate: (ULong) -> Boolean
): List<ULong>
@ExperimentalUnsignedTypes inline fun UByteArray.dropWhile(
    predicate: (UByte) -> Boolean
): List<UByte>
@ExperimentalUnsignedTypes inline fun UShortArray.dropWhile(
    predicate: (UShort) -> Boolean
): List<UShort>

Returns a list containing all elements except first elements that satisfy the given predicate.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val chars = ('a'..'z').toList()
println(chars.drop(23)) // [x, y, z]
println(chars.dropLast(23)) // [a, b, c]
println(chars.dropWhile { it < 'x' }) // [x, y, z]
println(chars.dropLastWhile { it > 'c' }) // [a, b, c]
//sampleEnd
}

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/drop-while.html