This email just in case any Googler's stumble across this thread searching for 
a generalized threading macro (and a happy conclusion to it). Googling for 
examples on this macro was very difficult in my experience, so maybe this might 
help someone.

As I found out via the "The case for as->> ("as-last")" thread, a generalized 
threading macro was apparently introduced in Clojure 1.5: the as-> form:

clojure.core/as->
([expr name & forms])
Macro
  Binds name to expr, evaluates the first form in the lexical context
  of that binding, then binds name to that result, repeating for each
  successive form, returning the result of the last form.

As this tweet demonstrates, here's how it looks:

        (as-> "/tmp" x (java.io.File. x) (file-seq x) (filter (memfn 
isDirectory) x) (count x))

First 'x' is bound to "/tmp" and a file is made out of it. 'x' is rebound again 
to the resulting file and a put through the 'file-seq' function, etc.

- Greg

--
Please do not email me anything that you are not comfortable also sharing with 
the NSA.

On Jul 7, 2010, at 9:02 AM, Laurent PETIT <laurent.pe...@gmail.com> wrote:

> 2010/7/7 aria42 <ari...@gmail.com>:
>> I've needed --> a few times in my code. I don't think I need it as
>> much as just -> or ->>. Most of the time I've needed it is because I
>> or someone else essentially had parameters
>> in the wrong order. Maybe it belongs in contrib along with -?> which
>> I've needed sparingly as well, but have found useful and would've been
>> non-trivial to have conjured.
> 
> -?> is particularly suitable when doing lots of java interop. I use it
> quite a lot in my own code in counterclockwise, for example.
> 
> -- 
> 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 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