Liking cljdoc? Tell your friends :D

lambdaisland/deep-diff

CircleCI cljdoc badge Clojars Project codecov

Recursively compare Clojure data structures, and produce a colorized diff of the result.

screenshot showing REPL example

Install

Clojars Project

Use

(require '[lambdaisland.deep-diff :as ddiff])

(ddiff/pretty-print (ddiff/diff {:a 1 :b 2} {:a 1 :c 3}))

Diffing

lambdaisland.deep-diff/diff takes two arguments and returns a "diff", a data structure that contains markers for insertions, deletions, or mismatches. These are records with - and + fields.

(ddiff/diff {:a 1 :b 2} {:a 1 :b 3})
{:a 1, :b #lambdaisland.deep_diff.diff.Mismatch{:- 2, :+ 3}}

Printing

You can pass this diff to lambdaisland.deep-diff/pretty-print. This function uses Puget and Fipp to format the diff and print the result to standard out.

For fine grained control you can create a custom Puget printer, and supply it to pretty-print.

(def narrow-printer (ddiff/printer {:width 10}))

(ddiff/pretty-print (ddiff/diff {:a 1 :b 2} {:a 1 :b 3}) narrow-printer)

For more advanced uses like incorporating diffs into your own Fipp documents, see lambdaisland.deep-diff.printer/format-doc, lambdaisland.deep-diff.printer/print-doc.

You can register print handlers for new types using lambdaisland.deep-diff.printer/register-print-handler!, or by passing and :extra-handlers map to printer.

Credits

This library builds upon clj-diff, which implements a diffing algorithm for sequences, and clj-arrangements, which makes disparate types sortable.

Pretty printing and colorization are handled by Puget and Fipp.

This library was originally developed as part of the Kaocha test runner.

Another library that implements a form of data structure diffing is editscript.

License

Copyright © 2018 Arne Brasseur

Available under the terms of the Eclipse Public License 1.0, see LICENSE.txt

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close