Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created February 13, 2013 23:46
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 alandipert/4949466 to your computer and use it in GitHub Desktop.
Save alandipert/4949466 to your computer and use it in GitHub Desktop.
(defn invert
[g]
(let [maps (map (fn [[name groups]] (zipmap groups (repeat #{name}))) g)]
(reduce (partial merge-with into) maps)))
(comment
(invert {"sally" #{"shipping"}, "joe" #{"shipping" "receiving"}})
;=> {"shipping" #{"joe" "sally"}, "receiving" #{"joe"}}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment