Anonymous committed 78d6886

Added lazy-assoc* driver for lazy-assoc (idea and patch by Erik Söhnel)

Comments (0)

Files changed (1)


   (mapcat (fn [[k v]] [k `(delay ~v)]) (partition 2 kvs)))
+(defn lazy-assoc*
+  "<lazy-assoc*> is like <lazy-assoc> but a function and takes values as delays
+  instead of expanding into a delay of val."
+  [m & kvs]
+  (assert (even? (count kvs)))
+  (reduce (fn [m [k v]] (.lazyAssoc m k v)) m (partition 2 kvs)))
 (defmacro lazy-assoc
   "<lazy-assoc> associates new values to the given keys in the given lazy map.
   The values are not evaluated, before their first retrieval. They are
   evaluated at most once."
   [m & kvs]
-  `(reduce (fn [m# [k# v#]]
-             (. m# ~'lazyAssoc k# v#))
-           ~m (partition 2 (list ~@(quote-values kvs)))))
+  `(lazy-assoc* ~m ~@(quote-values kvs)))
 (defn lazy-hash-map*
   "<lazy-hash-map*> is the same as <lazy-hash-map> except that its a function