3 ms·
My apologies for the slightly dumb question, and perhaps this is the wrong place to ask, but: These sound like a really good thing, but what if I want to use m
by nialo 14y ago
My apologies for the slightly dumb question, and perhaps this is the wrong place to ask, but:
These sound like a really good thing, but what if I want to use map and not reduce? Is Clojure smart enough to understand that some other function not named reduce should be transformed the same way?
- chongli 14y agoGo ahead and use map (just make sure you use the one from the clojure.core.reducers namespace). The reducers library provides implementations for many functions including map, mapcat, filter, flatten, take-while etc.
- chc 14y agoIt's not intelligently transforming your functions — it's providing alternate functions. The clojure.core.reducers namespace includes reducer-based functions named map, reduce, filter, etc. and you can pick and choose any of them you like. Just list the ones you want in your ns form like you would with any other library.
- alexott 14y agoclojure.core.reducers namespace provides implementation for many functions: map, flatten, filter, etc.
- jballanc 14y agoThe brilliance of the reducers library is that map is implemented in terms of reduce. Namely, mapping a->b in a collection is the same as reducing the collection (starting with an empty collection) by appending the converted form a->b to the accumulated collection.