On Feb 5, 2:20 pm, Niels Aan de Brugh <niels...@gmail.com> wrote:
> Hi there.
>
> A quick question about cond and condp. The latter has a nice feature
> that allows the re-use of a test-expression result in the result part
> of a clause. I figure it can be quite handy in the cond macro as well.
> For example:
>
>     (cond
>        ;; ...
>       (some (fn [[k v]] (some-test v)) col) :>> first
>        ;; ...
>     )
>
> This code would return the key of the first element in col that passes
> some-test. If no such value exists, 'some' returns nil and the check
> further down are processed.
>
> I could of course write:
>
>     (condp (fn [x _] x) nil
>       ;; clauses here, optionally using :>>
>     )
>
> to get the same effect.
>
>   user> (condp (fn [x _] x) nil false 2 3 :>> inc :else -1)
>   4
>
> But is there a more idiomatic way? Is there perhaps something in
> contrib that I should be aware of?
>
> Niels

I believe there was some talk of adding :>> to cond.  Short of that, I
frequently use 'some with 'or as the else:

(or (some inc [2]) -1)

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

Reply via email to