Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates a clojure bimap from an map atom
(defn bimap [map-atom]
(let [inv-atom (atom {})]
(add-watch map-atom :bimap
(fn [k r old cur]
(let [o (set (keys old))
n (set (keys cur))]
(doseq [removed (difference o n)]
(swap! inv-atom dissoc (old removed)))
(doseq [added (difference n o)]
(swap! inv-atom assoc (cur added) added)))))
inv-atom))
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.