Skip to content

Instantly share code, notes, and snippets.

Created Mar 15, 2013

What would you like to do?
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)
(recur expanded expansions))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.