(diff a b)
(diff a b {:keys [algo str-diff?] :or {algo :a-star str-diff? false}})
Create an editscript to represent the transformations needed to turn a
Clojure data structure a
into another Clojure data structure b
.
This function accepts any nested Clojure data structures. In Clojure, those
implement IPersistentVector
, IPersistentMap
, IPersistentList
,
and IPersistentSet
will be treated as collections. The same are true for
the corresponding deftypes in Clojurescript, such as PersistentVector
,
PersistentMap
, and so on. Anything else are treated as atomic values.
The editscript is represented as a vector of basic operations: add :+
,
delete :-
, and replace :r
. Each operation also include a path to the
location of the operation, which is similar to the path vector in update-in
.
However, editscript path works for all above four collection types, not just
associative ones. For :+
and :r
, a new value is also required.
The following options are supported in the option map:
:algo
chooses the diff algorithm. The value can be :a-star
(default) or
:quick
; :a-star
algorithm minimize the size of the resulting editscript,
:quick
algorithm is much faster, but does not producing diff with minimal size.
:str-diff?
indicates a desire to perform string diff. It may reduce the
result size for small changes in long strings, but will incur a slight computation
cost. The value is a boolean: true
or false
(default). When enabled, the diff
algorithm will perform string diff if the changes are less than 30 percent of the
string length; otherwise, whole string replacement will be used.
Create an editscript to represent the transformations needed to turn a Clojure data structure `a` into another Clojure data structure `b`. This function accepts any nested Clojure data structures. In Clojure, those implement `IPersistentVector`, `IPersistentMap`, `IPersistentList`, and `IPersistentSet` will be treated as collections. The same are true for the corresponding deftypes in Clojurescript, such as `PersistentVector`, `PersistentMap`, and so on. Anything else are treated as atomic values. The editscript is represented as a vector of basic operations: add `:+`, delete `:-`, and replace `:r`. Each operation also include a path to the location of the operation, which is similar to the path vector in `update-in`. However, editscript path works for all above four collection types, not just associative ones. For `:+` and `:r`, a new value is also required. The following options are supported in the option map: * `:algo` chooses the diff algorithm. The value can be `:a-star` (default) or `:quick`; `:a-star` algorithm minimize the size of the resulting editscript, `:quick` algorithm is much faster, but does not producing diff with minimal size. * `:str-diff?` indicates a desire to perform string diff. It may reduce the result size for small changes in long strings, but will incur a slight computation cost. The value is a boolean: `true` or `false` (default). When enabled, the diff algorithm will perform string diff if the changes are less than 30 percent of the string length; otherwise, whole string replacement will be used.
(patch a script)
Apply the editscript script
on a
to produce b
, assuming the
script is the results of running (diff a b)
, such that
(= b (patch a (diff a b)))
is true
Apply the editscript `script` on `a` to produce `b`, assuming the script is the results of running `(diff a b)`, such that `(= b (patch a (diff a b)))` is true
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close