I think

(->> things
    (map wrangle)
    (map pacify)
    (filter effable)
    (map #(aggravate % :bees :sharks))
    (reduce mapinate {})

is optimal for the following reason:


If you're doing "map" and "map alone", i.e.

(->> things
  (map f1)
  (map f2)
  (map f3)
  (map f4))

then you can do:

(map #(f4 (f3 (f2 (f1 %)))) things)


Now, if you're not doing pure maps, i.e. maps + filters

Then for each function call, from an information theoretic
perspective, you have to, at the very least, specify:

  (*) the function to be called
  (*) whether it's a filter or a map

in this case,

what you initially have is optimal.

On Fri, Feb 7, 2014 at 6:33 AM, Korny Sietsma <ko...@sietsma.com> wrote:
> I tend to agree, I think.  I certainly can't think of a syntax that would
> make me happy.  It just feels like a bit of a smell that I keep using ->> to
> process sequences in similar ways.
>
> The data.zip "xml->" macro is an example of something like what I'm thinking
> about - it lets you process sequences of xml data nicely:
> http://clojure.github.io/data.zip/#clojure.data.zip.xml/xml->
>
> ... but I can't see a way to use something similar for the sort of data I'm
> processing.  I'll let this percolate, and stick to just using lots of (map)
> and (filter) instead.
>
> - Korny
>
>
> On 6 February 2014 18:34, Jozef Wagner <jozef.wag...@gmail.com> wrote:
>>
>> I agree with Colin, the cognitive load is greater than benefits of such
>> approach. BTW you can use comp to chain consecutive map transformation
>> functions. (map (comp pacify wrangle) things)
>>
>> JW
>>
>>
>> On Thu, Feb 6, 2014 at 3:40 PM, Korny Sietsma <ko...@sietsma.com> wrote:
>>>
>>> Hi folks,
>>>
>>> I seem to regularly find myself writing ->> threaded code that follows
>>> similar patterns:
>>>
>>> (->> things
>>>     (map wrangle)
>>>     (map pacify)
>>>     (filter effable)
>>>     (map #(aggravate % :bees :sharks))
>>>     (reduce mapinate {})
>>>
>>> i.e. all stages of the code actually operate on a collection rather than
>>> a single value - usually with a call to "map" at each stage.  This example
>>> is over simplified - often many of the calls to map are inline functions,
>>> which makes this even more verbose.
>>>
>>> I wonder if there would be value in (yet another) variant on '->' that
>>> assumes you are threading a collection and calling 'map' by default.  I'm
>>> not sure of the syntax that would work though.  Something like:
>>>
>>> ([]-> things
>>>         wrangle
>>>         pacify
>>>         [:filter effable]
>>>         (aggravate :bees :sharks)
>>>         [:reduce mapinate {}])
>>>
>>> I'm not sure about the syntax for non-map functions, I'm not even sure if
>>> this is worthwhile.  Thoughts?
>>>
>>> - Korny
>>>
>>> --
>>> Kornelis Sietsma  korny at my surname dot com http://korny.info
>>> .fnord { display: none !important; }
>>>
>>> --
>>> 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/groups/opt_out.
>>
>>
>> --
>> 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/groups/opt_out.
>
>
>
>
> --
> Kornelis Sietsma  korny at my surname dot com http://korny.info
> .fnord { display: none !important; }
>
> --
> 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/groups/opt_out.

-- 
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/groups/opt_out.

Reply via email to