Created
May 7, 2018 09:37
-
-
Save vehas/47661b9aa40f1f91d1c45fc88e782272 to your computer and use it in GitHub Desktop.
group-location solution for the problem in clojure in thai FB group
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 local | |
[{:province :a, :district :b, :amphoe :c} | |
{:province :a, :district :k, :amphoe :g} ]) | |
(defn group-by-fn | |
([func groupping] | |
(fn [hmap] | |
(group-by-fn func groupping hmap))) | |
([func groupping hmap] | |
(->> hmap | |
(group-by groupping) | |
(map (fn [[k v]] [k (func v)])) | |
(into {})))) | |
(def group-location | |
(-> #(mapv :district %) | |
(group-by-fn :amphoe) | |
(group-by-fn :province))) | |
(group-location local) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment