Hacker News new | past | comments | ask | show | jobs | submit login

FYI, a third option is

    mutating func next() -> Element? {
        //...
        defer { pos += 1 }
        return pos
    }
Whether it's better is a matter of opinion



Nice. That's a beautifully idiomatic implementation of the original intent of post increment, if nothing else.


I just realized there's a small typo in the above, it should be

    return data[pos]




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: