3 ms·
FYI, a third option is mutating func next() -> Element? { //... defer { pos += 1 } return pos } Whether it's better is a matte
by jayrhynas 10y ago
FYI, a third option is
mutating func next() -> Element? {
//...
defer { pos += 1 }
return pos
}
Whether it's better is a matter of opinion
- stevetrewick 10y agoNice. That's a beautifully idiomatic implementation of the original intent of post increment, if nothing else.
- jayrhynas 10y agoI just realized there's a small typo in the above, it should be return data[pos]