This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-06
Channels
- # announcements (2)
- # beginners (97)
- # boot (3)
- # cider (23)
- # clara (9)
- # cljs-dev (40)
- # cljsrn (6)
- # clojure (107)
- # clojure-finland (2)
- # clojure-india (3)
- # clojure-italy (15)
- # clojure-nl (2)
- # clojure-spec (107)
- # clojure-uk (91)
- # clojurescript (28)
- # cursive (10)
- # data-science (4)
- # datomic (26)
- # duct (1)
- # emacs (6)
- # events (9)
- # figwheel-main (4)
- # fulcro (4)
- # graphql (2)
- # jobs (3)
- # jobs-discuss (12)
- # juxt (7)
- # kaocha (6)
- # off-topic (8)
- # onyx (2)
- # parinfer (13)
- # pedestal (32)
- # portkey (1)
- # re-frame (58)
- # reagent (17)
- # reitit (21)
- # ring-swagger (3)
- # shadow-cljs (35)
- # spacemacs (1)
- # tools-deps (33)
- # yada (13)
I'm guessing this is the best place to ask about https://github.com/lambdaisland/deep-diff Is there a way to only print out the changes between a diff? I've been looking at a custom printer but not sure if that's a dead end.
hi @shaun-mahood, a custom printer should not be necessary, instead traverse the results of diff
and remove the stuff that isn't a Insertion
/`Deletion`/`Mismatch`
(defn difference? [o]
(some #(instance? % o) #{Mismatch Deletion Insertion}))
(defn contains-difference? [o]
(cond
(difference? o)
true
(map? o)
(some contains-difference? (concat (keys o) (vals o)))
(sequential? o)
(some contains-difference? o)
:else
false))
(defn only-differences [diff]
(cond
(difference? diff)
diff
(vector? diff)
(into []
(comp (map only-differences)
(filter contains-difference?))
diff)
(map? diff)
(into {}
(comp (map (fn [[k v]] [k (only-differences v)]))
(filter (fn [[k v]] (some contains-difference? [k v]))))
diff)
(sequential? diff)
(sequence (comp (map only-differences)
(filter contains-difference?))
diff)
:else
diff))
@plexus Thanks - I thought I might be able to avoid traversing the collections if there was an easy way to change it on the printer side, but that's probably easier. If I get something that works well do you want me to submit it as a PR, or is that out of scope for what you want in the library?