If solving a more general problem first counts as elegant, then here is a solution:
(defn map-replace "Return coll but replace every element for which pred returns true with (f element replacement-element) as long as there are replacement elements in replacements" [pred f coll replacements] (lazy-seq (if (seq coll) (let [[x & xs] coll [y & ys] replacements] (if (pred x) (cons (f x y) (map-replace pred f xs ys)) (cons x (map-replace pred f xs replacements))))))) (defn nil-coalesce "Replace all occurrences of nil in coll with replacement items in replacements" [coll replacements] (map-replacements nil? (fn [x y] y) coll replacements)) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en