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

This looks like a very complicated way of solving something for which there is already a solution: channels and contexts. Here's the pattern I often use:

https://go.dev/play/p/mrQFLAc11QU

It should be doable to express this somewhat simpler using a (genericized) helper function to take out some of the work of writing the ListItems function.

Since there is already a way to do this I don't think the language should be cluttered with more ways to essentially do the same thing. It is better to push people to develop a vocabulary of idioms that uses fewer features rather than introduce "more stuff".



Using a channel for something is using a mutex for it. Nobody should suggest a mutex as a solution for implementing iterators.


This does not solve the problem. With channels you are preparing things (even just one thing) ahead of time and you have to do it in a separate goroutine. One could possibly (haven't tried or given more than 2s of thought) implement a channel (or at least part of it) using iterators.




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

Search: