There are several 'utility' libraries for Clojure that may have something
like this already, or their authors might be willing to add such a thing:

https://github.com/Prismatic/plumbing
https://github.com/amalloy/useful

Andy


On Tue, Jun 9, 2015 at 5:00 AM, crocket <crockabisc...@gmail.com> wrote:

> It evaluates true-case only if every local binding evaluates to true values. 
> false-case has no access to local bindings.
>
> (defmacro if-let-all
>   "if-let-all evaluates every local binding sequentially and evaluates 
> true-case only if every local binding is a truthy value.
> true-case has access to all local bindings, but false-case doesn't have 
> access to local bindings."
>   [bindings true-case false-case]
>   (let [pairs (partition 2 bindings)
>         names (mapv first pairs)
>         exprs (map second pairs)
>         exprs-in-if-let (fn self [[name1 & more-names] [expr1 & more-exprs]]
>                          `(if-let [~name1 ~expr1]
>                             ~(if more-names
>                                (self more-names more-exprs)
>                                names)))
>         things (exprs-in-if-let names exprs)]
>     `(if-let [~names ~things]
>        ~true-case
>        ~false-case)))
>
> I think this macro could benefit people if I found the right project where it 
> should reside.
> Can anyone help me find the right project for if-let-all?
>
>  --
> 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