Skip to content

Instantly share code, notes, and snippets.

@maacl maacl/clj-con-map Secret
Created Apr 28, 2013

Embed
What would you like to do?
Atom Map as Java ConcurrentHashMap
(defn ^M clj-con-map []
(let [m (atom {})]
(reify M
(put [_ k v] (swap! m assoc k v))
(get [_ k] (get @m k))
(putIfAbsent [_ k v]
(swap! m #(if (get % k)
%
(assoc % k v))))
(replace [_ k v]
(swap! m #(if (get % k)
(assoc % k v)
%))))))
(definterface M
(put [k v])
(get [k])
(putIfAbsent [k v])
(replace [k v]))
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.