Hi, On Thu, 27 Oct 2016 12:34:19 -0700 (PDT) JHacks <jhackswo...@gmail.com> wrote:
> For `comp`, at runtime, `(map str/lower-case)` and `(interpose \-)` > will return > transducers, and `partial` is needed to create the intended function, > e.g., `str/lower-case` bound to `map` and expecting a collection > argument. You're almost correct. This has nothing to do with transducers and was possible before there were transducers in Clojure (though composition of transducers works in a similar way) What `partial` does is to create anonymous functions out of functions and arguments. It inserts these arguments starting from left to right into the function. This process is sometimes called currying. So with your example you want a function which takes a string and converts every letter to a word. So you could write an anonymous function like (fn [coll] (map str/lower-case coll)) But that is rather verbose and naming the `coll` argument is kinda pointless, so you can simplify it to #(map str/lower-case %) And as you see, have a function which calls a function (`map`) with the first n arguments (in this case 1) pre-set (`str/lower-case`). Therefore you can use `partial` do do just that: (partial map str/lower-case) All of these functions are equivalent and you can use them in the `comp` call. There are some stylistic disagreements whether `#()` or `partial` is nicer, but that's a story for another time :) regards, Marek -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.