On Sat May 08 2010 at 08:38 am, Mark J. Reed wrote:
> But there are no doubt better ways to do it, probably built in or in
> clojure.core.
Using 'split-with' from core seems handy here:
clojure.core/split-with
([pred coll])
Returns a vector of [(take-while pred coll) (drop-while pred coll)]
So here's another option:
(defn replace-first [a b coll]
(let [[head tail] (split-with #(not= a %) coll)]
(concat head (when (seq tail)
(cons b (rest tail))))))
-Jeff
--
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