Option
is implicitly convertible to an Iterable
- but why does it not just just implement Iterable
directly:
def iterator = new Iterator[A] {
var end = !isDefined
def next() = {
val n = if (end) throw new NoSuchElementException() else get
end = true
n
}
def hasNext = !end
}
EDIT: In fact it's even weider than that because in 2.8 Option
does declare an iterator
method:
def iterator: Iterator[A] =
if (isEmpty) Iterator.empty else Iterator.single(this.get)