Skip to content

Commit

Permalink
Wrap state.iterator with immutable iterator (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm authored Mar 18, 2024
1 parent a214b8d commit 70d39d8
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ public sealed class State<N: Number, T: State<N, T>>(
final override val size: Int get() = P_LEN
final override fun isEmpty(): Boolean = false
final override operator fun contains(element: N): Boolean = state.contains(element)
final override fun iterator(): Iterator<N> = state.iterator()
final override fun iterator(): Iterator<N> = object : Iterator<N> {
private val delegate = state.iterator()

override fun hasNext(): Boolean = delegate.hasNext()
override fun next(): N = delegate.next()

override fun equals(other: Any?): Boolean = delegate == other
override fun hashCode(): Int = delegate.hashCode()
override fun toString(): String = delegate.toString()
}
final override fun containsAll(elements: Collection<N>): Boolean {
elements.forEach { n ->
if (!state.contains(n)) return false
Expand Down

0 comments on commit 70d39d8

Please sign in to comment.