Skip to content

Instantly share code, notes, and snippets.

Created March 15, 2013 16:45
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 anonymous/5171258 to your computer and use it in GitHub Desktop.
Save anonymous/5171258 to your computer and use it in GitHub Desktop.
tag expansion
(defn expand-tags
"Expands set of tags using mapping of sets of base tags to
other (single) tags, example:
{#{:tomatoes :potatoes :legumes} :culinary-vegetables
#{:peanuts :lentils} :legumes
#{:tomatoes :legumes} :botanical-fruits}"
[tags expansions]
(let [matches (filter (fn [[base-set _]] (some base-set tags)) expansions)
new-tags (mapcat to-coll (map val matches))
expanded (set (concat tags new-tags))]
(if (= tags expanded)
tags
(recur expanded expansions))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment