You're viewing version 1.2.0 of when-first. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16



  • (when-first bindings & body)
bindings => x xs

Same as (when (seq xs) (let [x (first xs)] body))

1 Example top

  • user=> (when-first [a [1 2 3]] a)
    user=> (when-first [a []] a)
    user=> (when-first [a nil] a)
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3558 top

(defmacro when-first
  "bindings => x xs

  Same as (when (seq xs) (let [x (first xs)] body))"
  {:added "1.0"}
  [bindings & body]
  (assert-args when-first
     (vector? bindings) "a vector for its binding"
     (= 2 (count bindings)) "exactly 2 forms in binding vector")
  (let [[x xs] bindings]
    `(when (seq ~xs)
       (let [~x (first ~xs)]
Vars in clojure.core/when-first: = count defmacro let vector? apply concat first list seq vector when
Used in 0 other vars

Comments top

No comments for when-first. Log in to add a comment.