On Mon, Oct 22, 2018 at 2:41 AM Eric Raymond <e...@thyrsus.com> wrote:
> There's an obvious, clumsy way to do this by having a factory pass back a stateful iterator object: > > for iterator := IteratorFactory(selector); iterator.Continue();iterator.Next(){ > DoSomethingWith(iterator.Value()) > } > > What one would really like to be able to do, though, is much more concise: > > for i, v := range iteratorFunction() { > DoSomethingWith(i, v) > } > The 'obvious' way is not something I'd consider. The 'concise' way works today, provided iterator function returns a slice or a map. I'd probably write something like for item := someSetup(selector); item.Next(); { DoSomethingWith(item) } Item type can be whatever is needed, like `struct{i, v int}` or something much more complex. I don't think that this calls for a language change. -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.