I ask myself that from time to time. I tend to use (partial + 2) because I think its easier to read.
The (+ 2) bit is intressting. That would be automatic currying, you get that in other languages. It is not possible in Clojure becaus there is no limit to how many args a clojure function can take. Think about it for a moment. What should ((+ 2) 1) return? A function with the next elment add on to it? So it would return a function that adds 3 to its args or the result? How can you know what the caller wants? Thats the reason for partial. I would have liked a shorter word for partial but its not really importend. On Sep 30, 9:48 am, Ulises <ulises.cerv...@gmail.com> wrote: > Hi, > > Newbie here with a simple question: what is the preferred way of > mapping a function to a seq? Use an anonymous function or use a > partial? > > Consider this: > > user=> (map (fn [n] (+ 2 n)) [1 2 3 4 5]) > (3 4 5 6 7) > user=> (map (partial + 2) [1 2 3 4 5]) > (3 4 5 6 7) > user=> > > I know that the answer is likely to be "it depends." I am just > interested in whether one is more idiomatic/functional than the other, > performance issues that one approach may have that the other one > doesn't, etc. > > Thanks in advance, > > PS: I'm even tempted to say that if one could do (map (+ 2) [1 2 3 4 > 5]) it would look even better :) > > U -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en