How to collect values from a channel into a slice in Go? (I want a utility method, maybe from go-funk)

I guess we all have different opinions. From my perspective, the question would be “why depend on a library when I can write seven lines?”

Not to get into an argument, but considering that in @heidi’s last post, they said:

I think it might be relevant to quote one of the Go proverbs: “A little copying is better than a little dependency”.

That being said, I am not aware of any library that does this, but some of the projects that aim to make Go more functional might accept a PR. In Go 1.18 and later, you could create your own package and put a generic version of the code I put above and then reference it from your other projects so that you don’t have to write it again.

3 Likes