
org.fernice.std.List.kt Maven / Gradle / Ivy
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.fernice.std
fun List.asReversedSequence(): Sequence {
return ReversedListSequence(this)
}
private class ReversedListSequence(
private val list: List,
) : Sequence {
override fun iterator(): Iterator {
return object : Iterator {
private val iterator = list.listIterator(list.size)
override fun hasNext(): Boolean = iterator.hasPrevious()
override fun next(): T = iterator.previous()
}
}
}
fun List.resized(): List {
return ArrayList(this)
}
fun MutableCollection.drain(): List {
val list = toList()
clear()
return list
}
fun MutableList.truncate(size: Int) {
if (this.size > size){
subList(size, this.size).clear()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy