take Last While
inline fun <T> Array<out T>.takeLastWhile(predicate: (T) -> Boolean): List<T>
Content copied to clipboard
inline fun ByteArray.takeLastWhile(predicate: (Byte) -> Boolean): List<Byte>
Content copied to clipboard
inline fun ShortArray.takeLastWhile(predicate: (Short) -> Boolean): List<Short>
Content copied to clipboard
inline fun IntArray.takeLastWhile(predicate: (Int) -> Boolean): List<Int>
Content copied to clipboard
inline fun LongArray.takeLastWhile(predicate: (Long) -> Boolean): List<Long>
Content copied to clipboard
inline fun FloatArray.takeLastWhile(predicate: (Float) -> Boolean): List<Float>
Content copied to clipboard
inline fun DoubleArray.takeLastWhile(predicate: (Double) -> Boolean): List<Double>
Content copied to clipboard
inline fun BooleanArray.takeLastWhile(predicate: (Boolean) -> Boolean): List<Boolean>
Content copied to clipboard
inline fun CharArray.takeLastWhile(predicate: (Char) -> Boolean): List<Char>
Content copied to clipboard
Returns a list containing last elements satisfying the given predicate.
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
val chars = ('a'..'z').toList()
assertPrints(chars.take(3), "[a, b, c]")
assertPrints(chars.takeWhile { it < 'f' }, "[a, b, c, d, e]")
assertPrints(chars.takeLast(2), "[y, z]")
assertPrints(chars.takeLastWhile { it > 'w' }, "[x, y, z]")
//sampleEnd
}
inline fun UIntArray.takeLastWhile(predicate: (UInt) -> Boolean): List<UInt>
Content copied to clipboard
inline fun ULongArray.takeLastWhile(predicate: (ULong) -> Boolean): List<ULong>
Content copied to clipboard
inline fun UByteArray.takeLastWhile(predicate: (UByte) -> Boolean): List<UByte>
Content copied to clipboard
inline fun UShortArray.takeLastWhile(predicate: (UShort) -> Boolean): List<UShort>
Content copied to clipboard
Returns a list containing last elements satisfying the given predicate.
Since Kotlin
1.3
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
val chars = ('a'..'z').toList()
assertPrints(chars.take(3), "[a, b, c]")
assertPrints(chars.takeWhile { it < 'f' }, "[a, b, c, d, e]")
assertPrints(chars.takeLast(2), "[y, z]")
assertPrints(chars.takeLastWhile { it > 'w' }, "[x, y, z]")
//sampleEnd
}