For a non-OOP language like google Go, is it idiomatic to go about implementing new container types using datatypes like arrays or lists so as to implement convenient functionality like contains method which is absent from all in built container types?

| improve this question | | | | |
  • 6
    Go is object oriented, just not in the “usual” way (it doesn't use classes, but just structs and methods). – cgt Nov 25 '12 at 1:35
  • maps can be checked if they have a specific key: _, ok := m[key]. If the key was present, ok is true. Since Go doesn't let you override operators, "contains" doesn't make sense unless you have a container of builtin types. – Daniel Huckstep Nov 25 '12 at 3:31

The container package currently contains built-in objects for heaps, doubly linked lists, and circular lists. The source code for the container/list package also gives the idiomatic way to iterate over lists. With datatypes so easy to define, I don't think there is any problem in implementing new containers on your own. I would also imagine that as Go matures, it will add additional built-in data structures.

A channel is essentially a FIFO queue; see this source for help on making your own types thread-safe.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.