Re:Clojure 1.4 released
by simonb on Wednesday April 18, 2012 @09:58AM
(#3857924)
mapv and reduce-kv are a great addition; not so much as a feature per se, but rather as a testament of the core team being on the lookout for design patterns that are actually symptoms of lacks in the language [http://c2.com/cgi/wiki?AreDesignPatternsMissingLanguageFeatu...].
[ Parent
| on HN ]
Re:Clojure 1.4 released
by spacemanaki on Wednesday April 18, 2012 @02:59PM
(#3859642)
I'm not really sure what you mean... unless I'm missing something mapv is the same as (into [] (map ...)), and based on the source that appears to be exactly what it is. reduce-kv is a bit more complicated but it's not really a huge leap from reduce. Nice additions, to be sure, but are either really design patterns that indicate some lack in Clojure 1.3?
Codebases were littered with (vec (map ...)) and (reduce (fn [acc [k v]] ...)) patterns which are nothing but noise. This change removes the need for that, makes the intention clearer and in the case of reduce-kv removes the need for lambdas in some cases (where it was used only for destructuring).
I think it's more that everyone previously had the same helper function/macro in their code base with a different name. If everyone needs the exact same thing, the standard library is a better place for it.
They are actually much more efficient because they have type-specific implementations that operate directly on the underlying data structures, rather than constructing intermediate MapEntry objects and then mapping/reducing across those.