|3||replaced http://stackoverflow.com/ with https://stackoverflow.com/|
|2||Make title more specific|
Is the Set designed properly Should "Set" have a Get method?
|Question Protected by gnat|
Is the Set designed properly?
Let's have this C# class (it would be almost the same in Java)
As you can see, equality of two instances of
In a standard collection library of many languages (including C# and Java, of course) there is a
One can add items, remove items and check if the set contains an item. But why is it impossible to get a particular item from the set?
The only way to retrieve my item is to iterate over the whole collection and check all items for equality. However, this takes
I haven't found any language that supports get from a set so far. All "common" languages I know (Java, C#, Python, Scala, Haskell...) seem to be designed in the same way: you can add items, but you cannot retrieve them. Is there any good reason why all these languages do not support something that easy and obviously useful? They cannot be just all wrong, right? Are there any languages that do support it? Maybe retreiving a particular item from a set is wrong, but why?
There are a few related SO questions: