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.
30 lines
659 B
30 lines
659 B
4 years ago
|
package org.openrs2.util.collect
|
||
4 years ago
|
|
||
4 years ago
|
public fun <T> MutableIterable<T>.removeFirst(): T {
|
||
4 years ago
|
return removeFirstOrNull() ?: throw NoSuchElementException()
|
||
|
}
|
||
|
|
||
4 years ago
|
public fun <T> MutableIterable<T>.removeFirstOrNull(): T? {
|
||
4 years ago
|
val iterator = iterator()
|
||
|
if (!iterator.hasNext()) {
|
||
|
return null
|
||
|
}
|
||
|
|
||
|
val element = iterator.next()
|
||
|
iterator.remove()
|
||
|
|
||
|
return element
|
||
|
}
|
||
|
|
||
4 years ago
|
public inline fun <T> MutableIterable<T>.removeFirst(predicate: (T) -> Boolean): Boolean {
|
||
4 years ago
|
val iterator = iterator()
|
||
|
for (element in iterator) {
|
||
|
if (predicate(element)) {
|
||
|
iterator.remove()
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
}
|