Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare data structures in clojure and highlight differences

Is there a nice way to print out differences in clojure data structures? In Perl for example there is Test::Differences which helps a lot.

like image 716
Kungi Avatar asked Dec 14 '13 17:12

Kungi


2 Answers

Fanciest diff what I saw is deep-diff

It produces nice colorful diff like this

enter image description here

There also mention of nice editscript lib whick produce diff as array of patches.

like image 177
Dima Fomin Avatar answered Sep 19 '22 11:09

Dima Fomin


Differ is a recent library that seems to do a nice job:

(def person-map {:name "Robin"
                 :age 25
                 :sex :male
                 :phone {:home 99999999
                         :work 12121212})

(def person-diff (differ/diff person-map {:name "Robin Heggelund Hansen"
                                          :age 26
                                          :phone {:home 99999999})

;; person-diff will now be [{:name "Robin Heggelund Hansen"
;;                           :age 26}
;;                          {:sex 0
;;                           :phone {:work 0}]

EDITED: fix Differ repo URL that change from gitlab to GitHub

like image 24
Jérémie Avatar answered Sep 23 '22 11:09

Jérémie