Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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