okay, so the workaround is sort!(collect(Set([1,2,3])))
probably this is still slower than directly constructing the vector in a sorted manner
and it looks very error-prone, like you really don’t want to see this in end-user code, something which should be put into another function like sortset(set) = sort!(collect(set)).
Hence again I would guess that there should be something for this in Base
where an alternative solution is to use PriorityQueue, but that of course does not make too much sense in this context where I want to sort the keys from a Dict
This is what I meant. I think this is very unambiguous when it appears in code, so it can easily be in Base. If any special data-structures have better ways to implement this, they can overload more specific AbstractSet implementations. I invite you to pull-request that on base/sort.jl
How would that work? If you were implementing this, what container would you use as the intermediate while sorting? (Sets do not preserve order, so you can’t “reorder” them.) Or how would you implement a container-free sort? (sounds basically impossible for anything other than toy examples)
An alternative to implementing sort(::Set) would be to throw a more descriptive error. I agree that we should do one of these (either implement the method, or implement the error).
I am not sure why you find this error prone, and it is a too small of a tidbit to be in a function in my opinion.
I think this is only relevant if you are doing this step for multiple Sets without keeping the sorted vector long-term (i.e., you can reuse the vector). Then the best is to: