ClojureDocs

Nav

Namespaces

when-some

clojure.core

Available since 1.6 (source)
  • (when-some bindings & body)
bindings => binding-form test
  When test is not nil, evaluates body with binding-form bound to the
 value of test
3 Examples
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
See Also

bindings => binding-form test If test is not nil, evaluates then with binding-form bound to the ...

Added by timgilbert

bindings => binding-form test When test is true, evaluates body with binding-form bound to the va...

Added by brunchboy

Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is...

Added by MicahElliott

binding => binding-form init-expr binding-form => name, or destructuring-form destructuring-form...

Added by MicahElliott

Evaluates test. If logical true, evaluates body in an implicit do.

Added by MicahElliott
0 Notes
No notes for when-some