Last active
May 7, 2018 08:29
-
-
Save visibletrap/2fdfdb7e039743f7a66f92eecb9e8152 to your computer and use it in GitHub Desktop.
Input: [{:province :a, :district :b, :amphoe :c}, {:province :a, :district :k, :amphoe :g}], Output: {:a {:c [:b], :g [:k]}}
This file contains 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
(defn group-amphoes [locations] | |
(->> locations | |
(group-by :amphoe) | |
(map (juxt first (comp #(mapv :district %) second))) | |
(into {}))) | |
(defn group-provinces [locations] | |
(->> locations | |
(group-by :province) | |
(map (juxt first (comp group-amphoes second))) | |
(into {}))) | |
(group-provinces [{:province :a, :district :b, :amphoe :c}, {:province :a, :district :k, :amphoe :g}]) | |
;=> {:a {:c [:b], :g [:k]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment