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
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en