-
Notifications
You must be signed in to change notification settings - Fork 61
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
Distinguish between ordered and unordered sets and maps (urgent; can only be implemented before beta releases) #197
Comments
Are you using
Not really, no. The whole point is that things only appear once. Order can still be an important characteristic for collections regardless of whether items can only appear once or not. Java just added explicitly-ordered sets under the name "sequenced" two versions ago, but of course it had sets which preserve order as implementation detail basically forever as well. |
Yes, it would've been
Fair enough. |
Indeed, whether For such changes or proposals, usually the best thing to focus on is to start with the problems being solved and the desired effect (aka answering why the solution should be the way it is and what kind of an actual programmer's problem is being solved). W.r.t the ordered thing -- it is consistent with the standard library, where the default behaviour of |
The problem here is that using |
The current implementation of sets and maps being 'ordered by default' is unintuitive as it isn't actually 'by default'; One would expect a persistent set to count as a persistent set, regardless of its order-ness.
Additionally, why do ordered sets even exist? Isn't the whole point of sets that they're unordered, unlike lists? Regardless, why are they default? Why are ordered maps the default too, for that matter? They're slower, and orderness isn't a part of maps' and sets' contracts; sure, it is a nice option sometimes, but then you could just explicitly use ordered variants; but for most use cases, wouldn't it make more sense to prioritize speed over a feature that isn't a part of the contract?
My solution
I'm assuming in both that the soon-to-be released beta will break backwards compatibility completely, as #185 talks mainly about public API changes. An educated guess tells me this is because this library is being merged into the stdlib, which means we can change the functionality of existing methods.
orderedPersistent
(toOrderedPersistentSet
,orderedPersistentMapOf()
, etc.; orpersistentOrdered
, doesn't really matter).persistent
builders (for both set and map; this is just an example), except for a tiny difference in implementation; Instead of:TL;DR of the solution:
As for "but what about other implementations?" --
sealed
to prevent implementations that allow mutations #147PersistentOrdered
andPersistentHash
(or immutable versions of them) interfaces; but it's impossible this symmetric with mutable collections without hacking the type system even further, because of Java.The text was updated successfully, but these errors were encountered: