Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
4  
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.