20 lines
571 B
Kotlin
20 lines
571 B
Kotlin
package dev.inmo.postssystem.client
|
|
|
|
import org.w3c.dom.Storage
|
|
import org.w3c.dom.get
|
|
|
|
class StorageIterator(private val storage: Storage) : Iterator<Pair<String, String>> {
|
|
private var index = 0
|
|
|
|
override fun hasNext(): Boolean = index < storage.length
|
|
|
|
override fun next(): Pair<String, String> {
|
|
val k = storage.key(index) ?: error("Key for index $index was not found")
|
|
val v = storage[k] ?: error("Key for index $index was not found")
|
|
index++
|
|
return k to v
|
|
}
|
|
}
|
|
|
|
operator fun Storage.iterator() = StorageIterator(this)
|