-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Would be nice to have OrderedMap and OrderedSet be indexed #1893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'll add that it's kind of bizarre that |
Although this is outside the scope of what we could trivially do just by adding functions on top of the current internal implementation, a slightly modified implementation would could also in theory trivially make |
Hi, Conceptually, having an ordered Map or Set does not imply that you can access it by index directly. It just means that the order will be kept. You pointed out some incoherence with the For Map, ImplementationAbout the implementation of It feels weird for Do other @immutable-js/maintainers have a opinion on this ? Feel free to open a PR on this ! index in
|
Sure, the same is true of Lists of course, see linked lists like lisp lists for an example of that. But I guess my point is that, given that we can, it would be nice to have it mean that in this library, the same way that in this library, List does imply indexability due to it inheriting from
I actually mentioned So, to some degree the point of this request is somewhat about performance, in the sense that a public API would imply (or perhaps explicitly state in the documentation), that this is an expected use case of this collection and thus the performance will match your intuition (matching roughly with with List's https://runkit.com/tolmasky/indexable-orderedmap-example I'm certainly happy to file a PR, was just wondering if there was any actual pushback on being able to do this at all. I suppose one of the things I was also hoping could be discussed is whether there was any opinion from an API perspective. Is |
Order matters for these two collection types, and the collection clearly knows the indexing internally in the
_list
member (I know, implementation detail, but it would have to know somehow either way), so it is very unfortunate that you can't really treat interface with the indexes in many meaningful ways. To list two instances that I frequently run into this problem:Would of course be nice to just be able to do
orderedMap.at(index)
. This is my main gripe right now, the fact that I need to store out an almost identical separate collection that's just a List to be able to go to index -> item.Would be nice to have
index
show up in things likemap
andreduce
(filter
, etc.). Given that the API for.map
is already(item, key, collection)
, perhaps we could do(item, key, collection, index)
to not have any backwards-incompatible changes.The text was updated successfully, but these errors were encountered: