Reputation: 8195
In Clojure, what does calling map
with one argument, like this:
(map inc) ;=> #object[clojure.core$map$fn__4549 0x1decdb9d "clojure.core$map$fn__4549@1decdb9d"]
...do / return? Because it doesn't do auto currying as expected, so the following two expressions are not equivalent:
;; E1
((map inc) [100 200 300]) ;=> #object[clojure.core$map$fn__4549$fn__4550 0x1b0c8974 "clojure.core$map$fn__4549$fn__4550@1b0c8974"]
;; E2
((partial map inc) [100 200 300]) ;=> (101 201 301)
...and the documentation says nothing.
So what IS the mysterious function returned by (map inc)
and other similar expressions?
Upvotes: 2
Views: 185
Reputation: 91534
calling map with a single argument in clojure 1.7+ returns a transducer that can be composed with other transducers and eventually a call to into
or some other transducing thing.
I recommend this video first, and then this one
This allows you to use all the clojure sequence abstractions without the computer spending a lot of time building intermediate sequences.
In clojure less than 1.7 it will throw an arity exception
Upvotes: 4