Skip to content

Instantly share code, notes, and snippets.

@matstani
Created December 9, 2015 04:53
Show Gist options
  • Save matstani/fa2a9fa3bbf457f9db9a to your computer and use it in GitHub Desktop.
Save matstani/fa2a9fa3bbf457f9db9a to your computer and use it in GitHub Desktop.
update nested map in clojure.
(def divisions
{:division1
{:group1 [:staff1 :staff2]
:group2 [:staff3 :staff4 :staff5]}
:division2
{:group3 [:staff6 :staff7]}})
(reduce
(fn [ds [d g staffs]]
(assoc-in ds [d g] (remove #{:staff2} staffs)))
divisions
(for [[d groups] divisions
[g staffs] groups]
[d g staffs]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment