Thrush in Clojuredebasishg.blogspot.com 6 pointskhingebjerg16 years ago3 commentsSaveHideCopy link On HNComments−va_coder16yIsn't he looping many times in this example. In an imperative language I would loop through the records once, find savings accounts, get balance and add to total - all in one loop.−mcodik16yDont think so-- Clojure's map and filter return lazy sequences, so this code likely only iterates once (in the +).http://richhickey.github.com/clojure/clojure.core-api.html#c...−noss16yThe point of the article was likely only this Thrush feature, and not the problem of implementing accounting systems.For a small list like this I would use a fold function and accumulate up savings account amounts, all in one pass, all functional.
Comments
Isn't he looping many times in this example. In an imperative language I would loop through the records once, find savings accounts, get balance and add to total - all in one loop.
Dont think so-- Clojure's map and filter return lazy sequences, so this code likely only iterates once (in the +).
http://richhickey.github.com/clojure/clojure.core-api.html#c...
The point of the article was likely only this Thrush feature, and not the problem of implementing accounting systems.
For a small list like this I would use a fold function and accumulate up savings account amounts, all in one pass, all functional.