16

Clojure and EDN diff tool

 1 year ago
source link: https://blog.klipse.tech/clojure/2020/10/08/edn-diff.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Clojure and EDN diff tool

Oct 8, 2020 • Yehonathan Sharvit

Compare recursively two Clojure data structures a and b.

Comparison is updated as you type…

xxxxxxxxxx
(def a {:only-in-a 1
        :both-in-a-and-b 3}) 
the evaluation will appear here (soon)...
xxxxxxxxxx
(def b {:only-in-b 2
        :both-in-a-and-b 3}) 
xxxxxxxxxx
the evaluation will appear here (soon)...

Full comparison:

xxxxxxxxxx
(def full-comparison (clojure.data/diff a b)) 
xxxxxxxxxx
the evaluation will appear here (soon)...

Things only in a:

xxxxxxxxxx
(first full-comparison)
xxxxxxxxxx
the evaluation will appear here (soon)...

Things only in b:

xxxxxxxxxx
(second full-comparison)
xxxxxxxxxx
the evaluation will appear here (soon)...

Things in both a and b:

xxxxxxxxxx
(last full-comparison)
xxxxxxxxxx
the evaluation will appear here (soon)...

Comparison rules:

  • For equal a and b, return [nil nil a].
  • Maps are subdiffed where keys match and values differ.
  • Sets are never subdiffed.
  • All sequential things are treated as associative collections by their indexes, with results returned as vectors.
  • Everything else (including strings!) is treated as an atom and compared for equality.

Explore more examples on ClojureDocs.

If you enjoy this kind of interactive articles would you consider a (small) donation💸 on Patreon or at least giving a star⭐ for the Klispe repo on Github?

to stay up-to-date with the coolest interactive articles around the world.

Discover more cool interactive articles about javascript, clojure[script], python, ruby, scheme, c++ and even brainfuck!

Give Klipse a Github star to express how much you appreciate Code Interactivity.

Subscribe to the Klipse newsletter:

Feel free to email me [email protected] for getting practical tips and tricks in writing your first interactive blog post.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK