takeLastWhile
inline fun <T> Array<out T>.takeLastWhile(
predicate: (T) -> Boolean
): List<T>
inline fun ShortArray.takeLastWhile(
predicate: (Short) -> Boolean
): List<Short>
inline fun FloatArray.takeLastWhile(
predicate: (Float) -> Boolean
): List<Float>
inline fun DoubleArray.takeLastWhile(
predicate: (Double) -> Boolean
): List<Double>
inline fun BooleanArray.takeLastWhile(
predicate: (Boolean) -> Boolean
): List<Boolean>
@ExperimentalUnsignedTypes inline fun ULongArray.takeLastWhile(
predicate: (ULong) -> Boolean
): List<ULong>
@ExperimentalUnsignedTypes inline fun UByteArray.takeLastWhile(
predicate: (UByte) -> Boolean
): List<UByte>
@ExperimentalUnsignedTypes inline fun UShortArray.takeLastWhile(
predicate: (UShort) -> Boolean
): List<UShort>
Returns a list containing last elements satisfying the given predicate.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val chars = ('a'..'z').toList()
println(chars.take(3)) // [a, b, c]
println(chars.takeWhile { it < 'f' }) // [a, b, c, d, e]
println(chars.takeLast(2)) // [y, z]
println(chars.takeLastWhile { it > 'w' }) // [x, y, z]
//sampleEnd
}