I implemented a scan function, that is a function like reduce but that
returns a list of the intermediate results not just the last one.
(defn scan
([f coll]
(scan f (first coll) (rest coll)))
([f val coll]
(when (not (empty? coll))
(let [new-val (f val (first coll))]
(lazy-seq
(cons new-val
(scan f new-val (rest coll))))))))
Is this best way to implement that or is there already a Clojure
function that does this that I've missed?
Thanks,
Jim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---