lambdaisland / deep-diff2

Deep diff Clojure data structures and pretty print the result
Eclipse Public License 1.0
296 stars 18 forks source link

Improve set handling #43

Closed plexus closed 1 year ago

plexus commented 1 year ago

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 1 year ago

Since order doesn't matter, I think we could also use set operations or clojure.data/diff for this.

plexus commented 1 year ago

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 1 year ago

The perils of using sets as predicates....

(filter #{5} (range 10)) ;;=> (5)
(filter #{false} [true false]) ;;=> ()