(reductions + [1 2 4 8])
==> (1 3 7 15)
Chris
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
On top of that, both the OP's algorithms are quadratic.
(defn scanl2 [f seed coll]
(loop [ttl seed [fst & rst] coll acc []]
(let [ttl (f ttl fst)
acc (conj acc ttl)]
(if rst
(recur ttl rst acc)
acc))))
is not, but it's not lazy. The above loop can be transformed
relatively trivially into a lazy-seq use that would be lazy;
reductions may be implemented similarly to such a lazy-seq use.