macro | since v0.0-927 | imported clojure.core/when-first | Edit |
(when-first bindings & body)
With bindings
as x
, xs
, roughly the same as (when (seq xs) (let [x (first xs)] body))
but xs
is evaluated only once.
bindings => x xs Roughly the same as (when (seq xs) (let [x (first xs)] body)) but xs is evaluated only once
(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))))