Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
638 B
29 lines
638 B
package dev.openrs2.util.collect
|
|
|
|
fun <T> MutableIterable<T>.removeFirst(): T {
|
|
return removeFirstOrNull() ?: throw NoSuchElementException()
|
|
}
|
|
|
|
fun <T> MutableIterable<T>.removeFirstOrNull(): T? {
|
|
val iterator = iterator()
|
|
if (!iterator.hasNext()) {
|
|
return null
|
|
}
|
|
|
|
val element = iterator.next()
|
|
iterator.remove()
|
|
|
|
return element
|
|
}
|
|
|
|
inline fun <T> MutableIterable<T>.removeFirst(predicate: (T) -> Boolean): Boolean {
|
|
val iterator = iterator()
|
|
for (element in iterator) {
|
|
if (predicate(element)) {
|
|
iterator.remove()
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|