Re: [go-nuts] Awkwardness around built in containers and user containers

70 views
Skip to first unread message

Ian Lance Taylor

unread,
Jun 17, 2020, 8:45:45 PM6/17/20
to hunter...@gmail.com, golang-nuts
On Wed, Jun 17, 2020 at 9:35 AM <hunter...@gmail.com> wrote:
>
> How do I write a function that can take any container? Either a built in container or a user defined structure? Java is awkward when deciding to accept arrays or the List type — is go fated to repeat this awkwardness?

It is as you fear: Go does not have a unified syntax for looping over
either builtin containers or user containers. In Go this rarely comes
up due to the absence of generics.

Ian

David Riley

unread,
Jun 17, 2020, 9:40:04 PM6/17/20
to Ian Lance Taylor, hunter...@gmail.com, golang-nuts
I might object to the use of "rarely" here: there's no convenient construct in Go to iterate over any non-fixed container but a channel, and while you can make an iterator/generator out of a channel, it is awkward and fraught with peril because of some of the peculiarities around hanging channels. This comes up rather a lot for me, actually.


- Dave
Reply all
Reply to author
Forward
0 new messages