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.
 
 
 
 
openrs2/util/src/main/kotlin/org/openrs2/util/collect/IterableUtils.kt

29 lines
659 B

package org.openrs2.util.collect
public fun <T> MutableIterable<T>.removeFirst(): T {
return removeFirstOrNull() ?: throw NoSuchElementException()
}
public fun <T> MutableIterable<T>.removeFirstOrNull(): T? {
val iterator = iterator()
if (!iterator.hasNext()) {
return null
}
val element = iterator.next()
iterator.remove()
return element
}
public 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
}