Hi,

Am 28.12.2009 um 02:36 schrieb Conrad:

> => (left-total [3 5 10 1 2 7])
> ([3 0] [5 3] [10 8] [1 18] [2 19] [7 21])

If in doubt, use lazy-seq.

(defn left-total
  [accum-fn accum s]
  (lazy-seq
    (when-let [[f & r] (seq s)]
        (cons [f accum] (left-total accum-fn (accum-fn accum f) r)))))

user=> (left-total + 0 [3 5 10 1 2 7])
([3 0] [5 3] [10 8] [1 18] [2 19] [7 21])

Since you said, that + is more complicated in your specific case, you might 
want this more general form. Otherwise the above can of course be simplified…

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to