As a general rule, if you have something that has the semantics of a
pure function, and you can see how to implement it by banging on an
atom with swap! in a loop that consumes a sequence, then you can
transform it to use reduce.
If you have:
(defn foo [coll]
(let [x (atom bar)]
(dorun [y coll]
(swap! x f y))
@x))
you can change it to:
(defn foo [coll]
(reduce f bar coll))
:)
--
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