-
Notifications
You must be signed in to change notification settings - Fork 19
add remove-unchanged API #42
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
120e9d7
add remove-unchanged API
humorless cb9f987
change strip namespace to manipulate
humorless e3e1f0a
replace cond to when
humorless 337924d
change wordings in CHANGELOG
humorless e8027e5
improve remove-unchanged
humorless 5793228
Improve handling for sets and maps
plexus 41d3153
Clean up and rework minimize implementation
plexus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(ns lambdaisland.deep-diff2.strip | ||
"Provide API for manipulate the diff structure data " | ||
(:require [clojure.walk :refer [postwalk]] | ||
#?(:clj [lambdaisland.deep-diff2.diff-impl] | ||
:cljs [lambdaisland.deep-diff2.diff-impl :refer [Mismatch Deletion Insertion]])) | ||
#?(:clj (:import [lambdaisland.deep_diff2.diff_impl Mismatch Deletion Insertion]))) | ||
|
||
(defn diff-item? | ||
"Checks if x is a Mismatch, Deletion, or Insertion" | ||
[x] | ||
(or (instance? Mismatch x) | ||
(instance? Deletion x) | ||
(instance? Insertion x))) | ||
|
||
(defn extend-flatten | ||
"Flatten, which can apply on hashmap" | ||
[x] | ||
humorless marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(filter (complement coll?) | ||
(rest (tree-seq coll? seq x)))) | ||
|
||
(defn has-diff-item? | ||
"Checks if there are any diff items in x or sub-tree of x" | ||
humorless marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[x] | ||
(some | ||
#(or (= :- %) (= :+ %)) | ||
(extend-flatten x))) | ||
|
||
(defn remove-unchanged | ||
"Postwalk diff, removing values that are unchanged" | ||
[diff] | ||
(postwalk | ||
(fn [x] | ||
(cond | ||
(map-entry? x) (cond | ||
(diff-item? (key x)) (do | ||
;(println "cond 1, keep" x) | ||
x) | ||
(has-diff-item? (val x)) (do | ||
;(println "cond 2, keep" x) | ||
x)) | ||
humorless marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:else x)) | ||
diff)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(ns lambdaisland.deep-diff2.strip-test | ||
(:require [clojure.test :refer [deftest testing is are]] | ||
[lambdaisland.deep-diff2.diff-impl :as diff] | ||
[lambdaisland.deep-diff2.strip :as strip] | ||
[lambdaisland.deep-diff2 :as ddiff])) | ||
|
||
(deftest strip-test | ||
(testing "removing the same items" | ||
(let [x {:a 1 :b 2 :d {:e 1} :g [:e [:k 14 :g 15]]} | ||
y {:a 1 :c 3 :d {:e 15} :g [:e [:k 14 :g 15]]}] | ||
(is (= (ddiff/diff x y) | ||
{:a 1 | ||
(diff/->Deletion :b) 2 | ||
:d {:e (diff/->Mismatch 1 15)} | ||
:g [:e [:k 14 :g 15]] | ||
(diff/->Insertion :c) 3})))) | ||
(testing "removing the same items" | ||
(let [x {:a 1 :b 2 :d {:e 1} :g [:e [:k 14 :g 15]]} | ||
y {:a 1 :c 3 :d {:e 15} :g [:e [:k 14 :g 15]]}] | ||
(is (= (strip/remove-unchanged (ddiff/diff x y)) | ||
{(diff/->Deletion :b) 2 | ||
:d {:e (diff/->Mismatch 1 15)} | ||
(diff/->Insertion :c) 3}))))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.