This repository was archived by the owner on Jul 13, 2020. It is now read-only.
SparseArray as sequence returns list which doesn't match its size #240
Closed
Description
private class SparseArraySequence<T>(private val a: SparseArray<T>) : Sequence<T> {
override fun iterator() = SparseArrayIterator()
private inner class SparseArrayIterator : Iterator<T> {
private var index = 0
private val size = a.size()
override fun hasNext() = size > index
override fun next(): T {
if (a.size() != size) throw ConcurrentModificationException()
return a.get(index++)
}
}
}
As it currently is, toSequence()
seems to only return values with positive indices, while returning the original size
As a result, you cannot use filter(aggregate)
on such sparse array sequences unless you specify that it
might be null.
Instead of get(index++)
it should use valueAt(index++)