Skip to content

Instantly share code, notes, and snippets.

@vehas
Created May 7, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vehas/47661b9aa40f1f91d1c45fc88e782272 to your computer and use it in GitHub Desktop.
Save vehas/47661b9aa40f1f91d1c45fc88e782272 to your computer and use it in GitHub Desktop.
group-location solution for the problem in clojure in thai FB group
(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