(if-let bindings then)
(if-let bindings then else & oldform)
bindings => binding-form test
If test is true, evaluates then with binding-form bound to the value of
test, if not, yields else
Spec
(clojure.spec.alpha/fspec
:args
(clojure.spec.alpha/cat
:bindings
(clojure.spec.alpha/and
clojure.core/vector?
:clojure.core.specs.alpha/binding)
:then
clojure.core/any?
:else
(clojure.spec.alpha/? clojure.core/any?))
:ret
clojure.core/any?
:fn
nil)
Source
(defmacro if-let
"bindings => binding-form test
If test is true, evaluates then with binding-form bound to the value of
test, if not, yields else"
{:added "1.0"}
([bindings then]
`(if-let ~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 temp#
(let [~form temp#]
~then)
~else)))))