package com.mikebull94.result /** * - Rust: [Result.iter](https://doc.rust-lang.org/std/result/enum.Result.html#method.iter) */ fun Result.iterator(): Iterator { return ResultIterator(this) } /** * Rust: [Result.iter_mut](https://doc.rust-lang.org/std/result/enum.Result.html#method.iter_mut) */ fun Result.mutableIterator(): MutableIterator { return ResultIterator(this) } private class ResultIterator(private val result: Result) : MutableIterator { private var yielded = false override fun hasNext(): Boolean { if (yielded) { return false } return when (result) { is Ok -> true is Error -> false } } override fun next(): V { if (!yielded && result is Ok) { yielded = true return result.value } else { throw NoSuchElementException() } } override fun remove() { yielded = true } }