4 ms·
Does mapv not do exactly what the author needs? Ie an unlazy map? https://clojuredocs.org/clojure.core/mapv https://clojuredocs.org/clojure.core/mapv
by zdkl 9y ago
Does mapv not do exactly what the author needs? Ie an unlazy map?
https://clojuredocs.org/clojure.core/mapv https://clojuredocs.org/clojure.core/mapv
- Zak 9y agoIt can, but using it that way is considered non-idiomatic in Clojure. The intent of using variants of map is to produce a collection with each element transformed. Someone who reads the code might reasonably expect not to find side effects inside any variety of map. Clojure provides doseq and run! for side effects on collections, and both return nil. One might get the impression that these design choices are intended to discourage the programmer from complecting transformations of sequences with performing side effects on their elements. Most of the time, you can replace one with another, such as pmap (lazy, parallel) and have the program behave the same way. Using mapv for side effects breaks this assumption.