Skip to content

Minimize removes all newly added/removed collection items under newly added/removed map keys #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kajism opened this issue Apr 7, 2025 · 3 comments

Comments

@kajism
Copy link

kajism commented Apr 7, 2025

(ddiff/diff {:a 1} {:a 1 :items [{:x 3}]})
=> {#lambdaisland.deep_diff2.diff_impl.Insertion{:+ :items} [{:x 3}], :a 1}

(->> (ddiff/diff {:a 1} {:a 1 :items [{:x 3}]})
       (ddiff/minimize))
=> {#lambdaisland.deep_diff2.diff_impl.Insertion{:+ :items} []}


So all such big differences are hidden.

@kajism
Copy link
Author

kajism commented Apr 7, 2025

New tests below demonstrate it. Tests 1 and 3 with scalar value are passing now. Tests 2 and 4 are failing, because empty vector is returned:

    (testing "adding new map keys with scalar value"
      (is (= (ddiff/minimize
               (ddiff/diff {:a 1} {:a 1 :b 2}))
             {(diff/->Insertion :b) 2})))

    (testing "adding new map keys with collection"
      (is (= (ddiff/minimize
               (ddiff/diff {:a 1} {:a 1 :b [1 2]}))
             {(diff/->Insertion :b) [1 2]})))

    (testing "removing map keys with scalar value"
      (is (= (ddiff/minimize
               (ddiff/diff {:a 1 :b 2} {:a 1}))
             {(diff/->Deletion :b) 2})))

    (testing "removing map keys with collection"
      (is (= (ddiff/minimize
               (ddiff/diff {:a 1 :b [1 2]} {:a 1}))
             {(diff/->Deletion :b) [1 2]})))`

@kajism
Copy link
Author

kajism commented Apr 8, 2025

(testing "adding new map keys with nested collection"
      (is (= (ddiff/minimize
               (ddiff/diff {:a 1} {:a 1 :b [{:x 1} {:x 2}]}))
             {(diff/->Insertion :b) [{:x 1} {:x 2}]})))

(testing "removing map keys with nested collection"
      (is (= (ddiff/minimize
               (ddiff/diff {:a 1 :b [{:x 1} {:x 2}]} {:a 1}))
             {(diff/->Deletion :b) [{:x 1} {:x 2}]})))

@kajism
Copy link
Author

kajism commented Apr 8, 2025

I have created a different version of minimize which suits my needs. Postwalk is replaced by recursion to pass the above tests: https://github.com/kajism/deep-diff2/blob/main/src/lambdaisland/deep_diff2/minimize_impl.cljc

But is is not 100% backwards compatibile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant