Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Aren't we talking about standardizing iterators? That makes the compiler slightly more complex, I guess, but for the language it makes it much easier to read and more approachable imo. That's the reason that range exists in the first place.

I don't see why the author's implimentation is so complicated. I really just want an interface that works with the range operator, and to call it a day.

    type Iterable[T any] interface {
        Next() (T, bool)
    }
so that

    for _, el := range someIterable {
    }
is essentially the same as

    for el, ok := someIterable.Next(); ok; el, ok := someIterable.Next() {
    }
I certainly think the first is more clear btw.


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

Search: