While we speak about function composition (or not), you can also use the partial function creator to obtain "point-free" (no need for anonymous function with formal argument declaration or use) code:
And with the use of comp, you could define the function without even explicitly naming any formal argument :-) : 1:7 user=> (def deep-csv (comp (partial apply println) (partial interpose ", ") seq-utils/flatten)) #'user/deep-csv 1:10 user=> (deep-csv '((1 2 3) (4 5 6))) 1 , 2 , 3 , 4 , 5 , 6 nil For one-shot expression threading, I agree with David that -> would be more approriate, though the need to enclose the anonymous function definitions in extraneous parenthesis is not so lisible, even with short forms of anonymous function definitions: (defn deep-csv [mr] (-> mr flatten (#(interpose ", " %)) (#(apply println %)))) My 0,02€, -- Laurent 2009/4/1 kkw <kevin.k....@gmail.com> > > Hi folks, > > I have some code where I wanted to: > - take a list of stuff (which includes another list inside) > - use 'seq-utils/flatten' to flatten the list > - use 'interpose' to add comma-delimiting strings between the elements > - print out the results, thereby creating comma-delimited output > > I may choose between: > > ((comp > (fn [x] (apply println x)) > (fn [x] (interpose ", " x)) > seq-utils/flatten) > mr) > > OR > > (-> mr > seq-utils/flatten > ((fn [x] (interpose ", " x))) > ((fn [x] (apply println x)))) > > And I found the "->" notation marginally easier to interpret and > understand. Apart from appearance, are there any benefits to using -> > instead of the comp function? I happily concede that there exist nicer > ways to achieve this goal, but the question I wanted to raise > concerned the benefits of using -> vs comp or vice-versa. > > Kev > > Kev > > > --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---