Skip to content

Instantly share code, notes, and snippets.

@theikkila
Last active May 23, 2017 16:30
Show Gist options
  • Save theikkila/bd0f2e5d9992e516e51c360fe90a31da to your computer and use it in GitHub Desktop.
Save theikkila/bd0f2e5d9992e516e51c360fe90a31da to your computer and use it in GitHub Desktop.
(def defaults {:a ["default-a"]
:b ["default-b"]
:c ["default-c"]
:d ["default-d"]})
(def ex1 [:a 1 2 :b 4 5 :c :d])
(defn kw-ob [hm item]
(if (keyword? item)
(assoc hm :key item)
(update-in hm [:result (:key hm)] conj item)))
(merge
defaults
(:result (reduce kw-ob {:key nil :result {}} ex1)))
(def output {:a [1 2]
:b [4 5]
:c ["default-c"]
:d ["default-d"]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment