macro | since v0.0-2261 | imported clojure.core/if-some | Edit |
(if-some bindings then)
(if-some bindings then else & oldform)
If test
is not nil, evaluates then
with x
bound to the value of test
. If
not, yields else
.
bindings => binding-form test If test is not nil, evaluates then with binding-form bound to the value of test, if not, yields else
(defmacro if-some
{:added "1.6"}
([bindings then]
`(if-some ~bindings ~then nil))
([bindings then else & oldform]
(assert-args
(vector? bindings) "a vector for its binding"
(nil? oldform) "1 or 2 forms after binding vector"
(= 2 (count bindings)) "exactly 2 forms in binding vector")
(let [form (bindings 0) tst (bindings 1)]
`(let [temp# ~tst]
(if (nil? temp#)
~else
(let [~form temp#]
~then))))))