Re: comp and partial vs ->>

2016-11-03 Thread Sean Corfield
The other thing to watch out for when naming intermediate results is that you don’t hold onto the head of large sequences. It’s not a problem with these book examples but can be a problem in large scale programming. Overall tho’, the readability of these different forms is very subjective. I

Re: comp and partial vs ->>

2016-11-03 Thread Leon Grapenthin
This style is only good if you do damn good naming on your "explaining variables". So while more names can really improve readability, bad names do the opposite by adding confusion and misdirection. This pattern enforces naming for every step. Good names are difficult, so I can only recommend to

Re: comp and partial vs ->>

2016-10-31 Thread JHacks
On Sunday, October 30, 2016 at 10:50:08 PM UTC-4, Mikera wrote: > > > I actually prefer the following style to both of the above: > > (defn camel->keyword* > [s] > (let [words (str/split s #"(?<=[a-z])(?=[A-Z])") >lc-words (map str/lower-case words) >

Re: comp and partial vs ->>

2016-10-30 Thread Alan Thompson
I agree 100%. I quite frequently use the style, more than any of the alternatives. It even has a name, "Introduce Explaining Variable": http://refactoring.com/catalog/extractVariable.html ​ Alan​ On Sun, Oct 30, 2016 at 7:50 PM, Mikera wrote: > On Thursday, 27 October 2016 22:56:42 UTC+8, J

Re: comp and partial vs ->>

2016-10-30 Thread Mikera
On Thursday, 27 October 2016 22:56:42 UTC+8, JHacks wrote: > > I have some confusion about how the function `comp` works, especially as > compared to the threading macro `->>`. > > From the book *Clojure Programming* (pages 70-71 of Chapter 2: Functional > Programming), the following two functions

Re: comp and partial vs ->>

2016-10-28 Thread Mars0i
On Thursday, October 27, 2016 at 11:39:27 AM UTC-5, Alan Thompson wrote: > > I almost never use either the `comp` or the `partial` functions. I think > it is clearer to either compose the functions like Gary showed, or to use a > threading macro (my favorite is the `it->` macro from the Tupelo l

Re: comp and partial vs ->>

2016-10-28 Thread Timothy Baldridge
That was fixed in a patch that added special cases to partial when used with smaller numbers of arguments. It was never much slower, but it should be just as fast as hand made functions now. http://dev.clojure.org/jira/browse/CLJ-1430 On Fri, Oct 28, 2016 at 5:35 AM, Bobby Eickhoff wrote: > I a

Re: comp and partial vs ->>

2016-10-28 Thread Bobby Eickhoff
I agree that forms like (partial > 3) are clearer than #() forms. However, I've been avoiding partial in code bases for a while -- it was measurably slower than the alternative. Is that still the case? Has anyone else observed slowness with partial? On Thursday, October 27, 2016 at 8:44:14 P

Re: comp and partial vs ->>

2016-10-27 Thread JHacks
On Thursday, October 27, 2016 at 6:24:19 PM UTC-4, Marek Kubica wrote: > > > 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 firs

Re: comp and partial vs ->>

2016-10-27 Thread Timothy Baldridge
I use comp all the time, not only for transducers, but also for digging into maps: (map (comp first :pets) [{:pets [:fluffy]} {:pets [:spot]}]) => (:fluffy, :spot) Partial is also handy when used with a lot of sequence functions (->> [1 2 3 4 5] (filter (partial > 3))) Sure I co

Re: comp and partial vs ->>

2016-10-27 Thread Mark Engelberg
On Thu, Oct 27, 2016 at 9:39 AM, Alan Thompson wrote: > I almost never use either the `comp` or the `partial` functions. I think > it is clearer to either compose the functions like Gary showed, or to use a > threading macro (my favorite is the `it->` macro from the Tupelo library >

Re: comp and partial vs ->>

2016-10-27 Thread Marek Kubica
Hi, On Thu, 27 Oct 2016 12:34:19 -0700 (PDT) JHacks 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. Y

Re: comp and partial vs ->>

2016-10-27 Thread JHacks
Thanks, everyone, your responses are very helpful and much appreciated. On Thu 10/27/16 09:57AM, lvh wrote: > comp takes a number of functions and returns a function. Threading macros take a > number of forms (expressions) and return an expression. The threading macro does > not need a partial,

Re: comp and partial vs ->>

2016-10-27 Thread Anon Mouse
as-> is an alternative to using Tupelo's it-> as-> allows you to use a contextually meaningful identifier vs using 'it. On Thursday, October 27, 2016 at 12:39:27 PM UTC-4, Alan Thompson wrote: > > I almost never use either the `comp` or the `partial`

Re: comp and partial vs ->>

2016-10-27 Thread Alan Thompson
I almost never use either the `comp` or the `partial` functions. I think it is clearer to either compose the functions like Gary showed, or to use a threading macro (my favorite is the `it->` macro from the Tupelo library ). Alan On Thu

Re: comp and partial vs ->>

2016-10-27 Thread Gary Trakhman
Comp does its work at run-time, so you have to call functions that return functions. Threading macros do their work at compile-time, so your form literally compiles to this: > (clojure.walk/macroexpand-all '(->> (str/split s #"(?<=[a-z])(?=[A-Z])") (map str/lower-case) (int

Re: comp and partial vs ->>

2016-10-27 Thread lvh
Hi, > On Oct 27, 2016, at 9:54 AM, JHacks wrote: > > I have some confusion about how the function `comp` works, especially as > compared to the threading macro `->>`. > > From the book *Clojure Programming* (pages 70-71 of Chapter 2: Functional > Programming), the following two functions are de

comp and partial vs ->>

2016-10-27 Thread JHacks
I have some confusion about how the function `comp` works, especially as compared to the threading macro `->>`. >From the book *Clojure Programming* (pages 70-71 of Chapter 2: Functional Programming), the following two functions are described as functionally equivalent: (def camel->keyword