-
Notifications
You must be signed in to change notification settings - Fork 18
/
deep_diff2.cljc
50 lines (40 loc) · 1.59 KB
/
deep_diff2.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(ns lambdaisland.deep-diff2
(:require
[lambdaisland.deep-diff2.diff-impl :as diff-impl]
[lambdaisland.deep-diff2.printer-impl :as printer-impl]
[lambdaisland.deep-diff2.minimize-impl :as minimize]))
(defn diff
"Compare two values recursively.
The result is a data structure similar to the ones passed in, but with
Insertion, Deletion, and Mismatch objects to mark differences.
When two collections are considered to be in the same type class then their
contents are compared.
Vectors, sequences, arrays and Java lists are all considered a single type
class, as are Clojure and Java maps.
Insertions/Deletions in maps are marked by wrapping the key, even though the
change applies to the whole map entry."
[expected actual]
(diff-impl/diff expected actual))
(defn printer
"Construct a Puget printer instance suitable for printing diffs.
Extra options are passed on to Puget. Extra type handlers can be provides as
`:extra-handlers` (a map from symbol to function), or by
using [[lambdaisland.deep-diff.printer/register-print-handler!]]"
([]
(printer {:print-fallback :print}))
([opts]
(printer-impl/puget-printer opts)))
(defn pretty-print
"Pretty print a diff.
Pretty print a diffed data structure, as obtained from [[diff]]. Optionally
takes a Puget printer instance, see [[printer]]."
([diff]
(pretty-print diff (printer)))
([diff printer]
(-> diff
(printer-impl/format-doc printer)
(printer-impl/print-doc printer))))
(defn minimize
"Return a minimal diff, removing any values that haven't changed."
[diff]
(minimize/minimize diff))