if-some

macrosince v0.0-2261imported clojure.core/if-someEdit
(if-some bindings then)
(if-some bindings then else & oldform)

Details:

If test is not nil, evaluates then with x bound to the value of test. If not, yields else.


See Also:


Source docstring:
bindings => binding-form test

If test is not nil, evaluates then with binding-form bound to the
value of test, if not, yields else
Source code @ clojure:src/clj/clojure/core.clj
(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))))))