I have become very partial to a simple adaptation of as-> from the Tupelo
Core <https://github.com/cloojure/tupelo> library.  I almost always like to
be explicit about the location the previous value, since either -> or ->>
can sometimes be difficult if the threading forms don't always want the arg
as the first or last parameter.  Copying the pattern of Groovy/Ruby, I
almost always name the threading placeholder "it".  Since I don't like
repetition (& I would argue that the as-> form has its params backwards!) I
created the simple it-> form:

(defmacro it->
  "A threading macro like as-> that always uses the symbol 'it' as the
placeholder for the next threaded value:
      (it-> 1
            (inc it)
            (+ it 3)
            (/ 10 it))
      ;=> 2
   "
  [expr & forms]
  `(let [~'it ~expr
         ~@(interleave (repeat 'it) forms)
   ]
     ~'it ))


Alan


On Fri, Aug 28, 2015 at 6:14 AM, Akhil Wali <akhil.wali...@gmail.com> wrote:

> ​Good one!
>
> On Fri, Aug 28, 2015 at 6:34 PM, Moe Aboulkheir <m...@nervous.io> wrote:
>
>> The function is actually shorter without cond->: (conj (if first? args
>> (vec args)) x)
>
>
>
>
>
> --
> Akhil Wali
>
> # https://github.com/darth10
> # https://darth10.github.io
>
> --
> 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.
>

-- 
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.

Reply via email to