Last active
May 23, 2017 16:30
-
-
Save theikkila/bd0f2e5d9992e516e51c360fe90a31da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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