when-first

macrosince v0.0-927imported clojure.core/when-firstEdit
(when-first bindings & body)

Details:

With bindings as x, xs, roughly the same as (when (seq xs) (let [x (first xs)] body)) but xs is evaluated only once.


Source docstring:
bindings => x xs

Roughly the same as (when (seq xs) (let [x (first xs)] body)) but xs is evaluated only once
Source code @ clojure:src/clj/clojure/core.clj
(defmacro when-first
  {:added "1.0"}
  [bindings & body]
  (assert-args
     (vector? bindings) "a vector for its binding"
     (= 2 (count bindings)) "exactly 2 forms in binding vector")
  (let [[x xs] bindings]
    `(when-let [xs# (seq ~xs)]
       (let [~x (first xs#)]
           ~@body))))