Type compatibility determines whether clojure.data/diff can compare two values structurally. Collections are compatible when both are arrays, sets, lists, or maps; scalar values follow = compatibility rules. section 6.7
When values are compatible, diff returns a three-part result:
- Index 0 contains values found only in the first argument. section 6.7
- Index 1 contains values found only in the second argument. section 6.7
- Index 2 contains shared values; incompatible or unrelated values produce [a b nil]. section 6.7
- Lists and vectors compare as compatible list types, while a map and a sorted map can trigger ClassCastException. section 6.7
Nested differences
(diff [1 {:a [1 2]}] [1 {:a [1 3]}]) ;; [[nil {:a [nil 2]}] ;; [nil {:a [nil 3]}] ;; [1 {:a [1]}]] Nested compatible collections preserve their structure while separating unique and common values.


