Improve set handling
plexus opened this issue · 3 comments
plexus commented
We currently handle sets with the same logic that we use for sequential collection, but sets have no ordering, leading to issues. For instance, even when comparing a set with itself ddiff may imagine there are differences.
(let [s #{false 5}]
(ddiff/diff s s))
;; => #{{:- 5} false {:+ 5}}I think we want to add a separate diff-set function, which loops over the keys of set A, marking any element that's absent in set B as a deletion, and then runs over any remaining elemnts in set B, marking them as additions. We don't mark any as replacements.
alysbrooks commented
Since order doesn't matter, I think we could also use set operations or clojure.data/diff for this.
plexus commented
I'm working on a fix. Same for maps:
(let [s {false 0, 0 0}]
(ddiff/diff s s))
;; => {{:+ 0} 0, false 0, {:- 0} 0}plexus commented
The perils of using sets as predicates....
(filter #{5} (range 10)) ;;=> (5)
(filter #{false} [true false]) ;;=> ()