-
Notifications
You must be signed in to change notification settings - Fork 21
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
Uniformly add ordered collection functions to Set module where they apply, so further harmonising collection functions #1361
Comments
Since a I think it makes sense to have these. We should seek parity between collections where possible. I'd prefer the same on Map, but its nature makes that a little less obvious. Other related: #768. |
Reading the proposed lists, is there any function where the expectation would be to utilize inner structure of the Set and gain a lot better perf characteristics compared to using |
We already have I can't think of any big performance advantage from the others - hence I think implementation could be via List or Array and quick to do. The motivation here is making the core libraries more consistent and reducing cognitive burden, rather than adding anything. FYI there is some additional functionality - not available in any other module - that for performance reasons would be desirable which is:
Both should return an option in case there are no elements meeting the condition. |
@T-Gro, I'd think about Perhaps a better question to ask is whether we should strive for parity between collections, as we've done in the past. We've managed to bring lists, seqs and arrays close together and many functions already exist in |
Sets are often really convenient, especially when you have all the items up front. Performance is not meaningfully a factor in my personal usage. For me the benefits are the ability to think in terms of sets. What would be the difference between |
The motivation is uniformity between collections and so reducing the cognitive burden of remembering (or looking up) new functions.
Probably the one new operation on Set module we should have but do not is |
Also related, binary search function (approved) for map/set: #82 |
@tomcl sweet then I support this suggestion. sounds awesome. |
@abelbraaksma re #82 good find. I was thinking of slightly different version of same thing but there is a clear need for this in terms of performance. But, if added to Set, it should also be added to Map. |
:) Great. You could up-vote the issue! More votes => more likely to happen. It looks to me as though a good procedure would be to add any outstanding approved-in-principle functions and the cloned from ordered collection functions all at one go. |
voted, thanks for reminding me :) |
I propose we extend the
Set
library module collection by adding existing ordered collection module functions, where those make sense. This is similar to the previous harmonisation of all ordered collections.Additions would be (I think):
I've omitted functions that would be non-deterministic (or rather Set implementation-dependent) for sets. But we do have such Set functions (
maxElement
,minElement
) and in order to be minimally inconsistent the following could also be added:The existing way of approaching this problem in F# is ...
Pros and Cons
The advantages of making this adjustment to F# are
Set
could be used in code whenever that is appropriate without extra code to work around lack ofSet
functions, and with the expressiveness ofSet
union and difference operators. At the moment the lack of expected (from other collections) functions discourages this and can lead to overuse ofList
simply because it has a more complete set of functions even though semantically a set is appropriate.The disadvantages of making this adjustment to F# are ...
Extra information
Estimated cost
Small, if implemented via equivalent List or Seq functions. Although not optimal the loss of speed here would be slow relative to the overhead of the Set itself.
Related suggestions: (put links to related suggestions here)
The discussion in #803 is similarly about adding to Set module in a low-cognitive-overhead way, but specifically related to total versions of non-total functions. That introduces extra issues and the (lamentable) fact that closing all F# non-total library functions by adding total equivalents would mean a large number of try-prefix functions added.
However some of the argument is identical to here. When is it worth the cost of adding library functions to reduce cognitive overhead overall?
In both cases there is less cognitive overhead if functions are added where they are expected copies (changing module, or adding
try
) of existing non-total functions.Adding less-used functions to a library module makes finding more-used functions from autocomplete list or module documentation more difficult.
Personally, I support #803, in spite of the disadvantage.
That cognitive overhead disadvantage is less extreme - in fact negative - here, it can be argued, because the larger set of functions are a subset of what we already have in the more heavily used List, Array, and Seq modules.
Affidavit (please submit!)
Please tick these items by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: