Files
blitz-kt/src/main/kotlin/blitz/collections/ListOps.kt
2024-06-06 10:52:30 +02:00

30 lines
656 B
Kotlin

package blitz.collections
fun <T> MutableList<T>.removeFirst(count: Int) {
repeat(count) {
removeFirst()
}
}
fun <T> MutableList<T>.removeFirstInto(count: Int, dest: MutableList<T> = mutableListOf()): MutableList<T> {
repeat(count) {
dest.add(removeFirst())
}
return dest
}
fun <T> MutableList<T>.removeLast(count: Int) {
repeat(count) {
removeLast()
}
}
fun <T> MutableList<T>.removeLastInto(count: Int, dest: MutableList<T> = mutableListOf()): MutableList<T> {
repeat(count) {
dest.add(removeLast())
}
return dest
}
fun <T> MutableList<T>.addFront(value: T) =
add(0, value)