On Aug 17, 4:42 pm, Alan <[email protected]> wrote:
> Devious! The OP wanted to handle underflow of the subs collection
> though, so you need a tweak:
> (apply assoc v (interleave (positions nil? v)
> (concat subs (repeat nil))))
interleave stops once either collection is exhausted. In your modified
version, nils replace nils when there are fewer substitutions than nil
positions, which is unnecessary. Unless I'm missing something...which
is entirely possible.
It does fail when subs is empty, though. So:
(defn nil-coalesce [v subs]
(if (empty? subs) v
(apply assoc v (interleave (positions nil? v) subs))))
Off the golf course, I would probably use something like Meikel's or
ataggart's. I agree with Meikel that the lazy-seq approach is straight-
forward to understand, assuming you're familiar with lazy-seq idioms.
Justin
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en