Hi!
I’ve got specific quite case here - while it’s easy, I’d really love to see how to do this „clojure” - and thus I am asking you for advice - how will you do this?
I’ve got two vectors made of maps: old
and new
. For each item (one map) with path
acting as an unique key:
- If one map (like
{:path "/etc/foo" :content "foo"}
) is identical in bothold
andnew
, ommit it (nothing changed). - If one map changed between
old
andnew
, return it’s version fromnew
with additional:state :changed
property:{:path "/etc/bar" :content "zar" :state :changed}
- If one map from
old
is no longer present innew
, return it’s version fromold
with additional:state :deleted
property{:path "/etc/car" :content "car" :state :deleted}
.
Example:
(def old [{:path "/etc/foo"
:content "foo"}
{:path "/etc/bar"
:content "bar"}
{:path "/etc/car"
:content "car"}])
(def old [{:path "/etc/foo"
:content "foo"}
{:path "/etc/bar"
:content "zar"}])
(defn make-diff [old new]
...)
=>
[{:path "/etc/bar"
:content "zar"
:state :changed}
{:path "/etc/car"
:content "car"
:state :deleted}]
Thanks!