-
Notifications
You must be signed in to change notification settings - Fork 72
Add a SortedSeq
collection type
#132
Comments
Maps and sets have some sort of On the other hand, sequences have:
Would a sorted sequence define a new operation which places elements in a location based on the ordering? How would the new method(s) for this operation be differentiated from the existing methods, which already define an insertion location? For a mutable sorted sequence, it feels like that would collide with the methods in |
Also, without sorted maps/sets, it would be difficult to have a map/set with elements in a sorted order, as regular maps/sets have no defined order. However, sequences have a well-defined order, and have a |
Good points/questions. Though for reference, |
I had actually originally thought |
@NthPortal - |
@Ichoran ah, thanks! - I had misread it |
Rather than adding an ordering to a Seq it may be more useful to add duplicate elements to a Set, i.e. a MultiSet and SortedMultiSet. This would have to be a different basic collection type, it is neither a Seq nor a Set. |
I see we already have #133 for MultiSet (but no mention of a SortedMultiSet there) |
Actually I’ve just noticed that we have a |
Does it behave enough as a
I agree that it should probably be ported over; I'm just not sure how well it fits the |
Is that property really important? I think most of the value of a |
I'm not sure sorted things are enough like a Seq at all, even if ties are broken in a consistent way. One of the core laws for seqs as we have them now is effectively
That is, ordering is preserved across merges and splits. Of course one can allow exceptions to this, but it can yield surprising behavior when all you know is you have |
Indeed, that makes sense. So the solution is probably to use a sorted |
@Ichoran Maybe we could allow merge[CC[+_](that: Sorted[CC, A]): Sorted[CC, A] method which preserves ordering? |
@joshlemer I’s not just about I see the value of the law shown by @Ichoran but I think a more general kind of
Now the question is whether we want to introduce a new branch or not… |
I would argue that if you want a sorted sequence you primarily want efficient insertion and deletion, which you wouldn’t get with a |
As @Ichoran said, |
@NthPortal We would push down the |
I think changing the Seq hierarchy would upset too much. We have so far:
And each of the lower classes defines So, if we do want to add |
I don't think |
We have sorted maps and sets but not seqs. This one might also be handy.
The text was updated successfully, but these errors were encountered: