Semantic fix for remove of MutablePredicateIterator

This commit is contained in:
DBotThePony 2023-03-18 16:29:42 +07:00
parent 9f78291b79
commit 04c295a359
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -22,6 +22,9 @@ class PredicateIterator<T> : Iterator<T> {
private var foundValue: Any? = Companion
var once: Boolean = false
private set
override fun hasNext(): Boolean {
if (foundValue === Companion) {
while (parent.hasNext()) {
@ -29,6 +32,7 @@ class PredicateIterator<T> : Iterator<T> {
if (predicate.test(next)) {
foundValue = next
once = true
return true
}
}
@ -84,6 +88,10 @@ class MutablePredicateIterator<T> : MutableIterator<T> {
}
override fun remove() {
if (!predicateParent.once) {
throw NoSuchElementException()
}
return parent.remove()
}
}