comparison org/util.org @ 164:c33a8e5fe7bc

removed hearing-init-fns requirement, changed names
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 03:29:59 -0700
parents 33278bf028e7
children deac7b708750
comparison
equal deleted inserted replaced
163:985c73659923 164:c33a8e5fe7bc
199 199
200 (defn map-vals 200 (defn map-vals
201 "Transform a map by applying a function to its values, 201 "Transform a map by applying a function to its values,
202 keeping the keys the same." 202 keeping the keys the same."
203 [f m] (zipmap (keys m) (map f (vals m)))) 203 [f m] (zipmap (keys m) (map f (vals m))))
204
205 (defn runonce
206 "Decorator. returns a function which will run only once.
207 Inspired by Halloway's version from Lancet."
208 {:author "Robert McIntyre"}
209 [function]
210 (let [sentinel (Object.)
211 result (atom sentinel)]
212 (fn [& args]
213 (locking sentinel
214 (if (= @result sentinel)
215 (reset! result (apply function args))
216 @result)))))
204 217
205 218
206 #+end_src 219 #+end_src
207 220
208 #+results: util 221 #+results: util