I have the following data structure (two Vectors of Maps I believe)
{ :put [{:listId "myList", :entryId "1", :dateTime 1434637074},
{:listId "myList", :entryId "2", :dateTime 1434637075}],
:delete [{:listId "myList", :entryId "1"}]}
and would like to remove any :put entries for which the keys listId and entryId already exist inside :delete. The result should therefore be:
{ :put [{:listId "myList", :entryId "2", :dateTime 1434637075}],
:delete [{:listId "myList", :entryId "1"}]}
I have tried the following but 1) it's not idiomatic Clojure and 2) it doesn't delete the duplicate entry.
(defn remove-add-if-duplicate [requests]
(doseq [delete (seq (:delete requests))]
(doseq [put (seq (:put requests))
:when (and (= (:listId delete) (:listId put))
(= (:entryId delete) (:entryId put))]
(disj (set (:put requests)) put)))
requests))
(remove-add-if-duplicate
{ :put [{:listId "myList", :entryId "1", :dateTime 1434637074},
{:listId "myList", :entryId "2", :dateTime 1434637075}],
:delete [{:listId "myList", :entryId "1"}]})
Can you help me fix my code or show me a nice way of doing this?