What's going on here? Did you look under the hood?
-
-
-
I didn't need to look... what it's doing is as reasonable as what I'm doing is unreasonable: the Ordering I created considers there to be no difference in order between two Foos with the same id. The logic inside TreeSet uses that to equality-of-order to infer equality.
- Show replies
New conversation -
-
-
I'm wondering, does this imply that Ordering should always define a total order? The spec does say that compare(x, y) should return 0 when x == y, and there is a PartialOrdering trait in the library. Should the docs maybe be clearer on this to warn against these subtle bugs?
-
Yes, I think Ordering should always be total. As for the docs, though, clarity wasn't the problem. I just didn't think I needed to read them when I decided to use a TreeSet...
End of conversation
New conversation -
-
-
That ordering is fishy regardless of TreeSet—I must confess that I was also tempted to do this (in different languages). You want set semantics for the ID, plus associated data, which is the definition of a (Tree)Map.
-
Yes, agreed. But as my ID is part of my data, I wanted to eliminate the possibility of storing the data against the wrong ID. I can entertain the idea of removing the ID from the data itself, though...
- Show replies
New conversation -
-
-
The ordering is not consistent with the equality. In
@typelevel cats laws there is a rule to make sure that this is the case, so this issue would have been found by the law checks. (c == 0) == E.eqv(x, y) https://github.com/typelevel/cats/blob/master/kernel-laws/shared/src/main/scala/cats/kernel/laws/OrderLaws.scala#L15 …Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Isn't that any SortedSet? I think this is the first case sets bit me a couple years ago...
-
Maybe all the stdlib implementations, but you could implement a `SortedSet` which overrides `equals`.
- Show replies
New conversation -
-
-
how does `==` work in this case? (I knew that you put both values into the same TreeSet, the later value will replace the former one because your ordering instance defines possible "positions" in the tree. I used this fact to implement small key-value stores in memory.)
-
I didn't check, but I imagine the implementation walks both trees in parallel comparing one to the other using the Ordering to check that compare(leftElem, rightElem) == 0 for all of them.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.