when-some

added
1.6

ns
clojure.core

type
macro

(when-some bindings & body)

bindings => binding-form test

When test is not nil, evaluates body with binding-form bound to the
value of test

                user=> (when-some [x 1] [x :ok])
[1 :ok]

user=> (when-some [x nil] [x :ok])
nil
            
                user=> (when-some [x "Hello"] (println x))
"Hello"
nil

user=> (when-some [x nil] (println x))
nil
            
                ;; In contrast with when-let, when-some evaluates the body for false values:
(when-some [x false] {:x x})  ; => {:x false}

;; While when-let suppresses evaluation for false values:
(when-let [x false] {:x x})   ; => nil