Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap state.iterator with immutable iterator #9

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading