clojure.core/when-let¶
bindings => binding-form test
When test is true, evaluates body with binding-form bound to the value of test
Examples¶
Note by gstamp¶
The difference between when-let and if-let is that when-let doesn't have an else clause and and also accepts multiple forms so you don't need to use a (do...).
Note by n2o¶
The word "bindings" seems not to be correct here. In fact when-let only accepts one binding and not multiple ones.
So "bindings" might be confusing, at least it was for me.
Note by Dave Y.¶
Agreed. It ought to be "binding" for clarity.
Note by HomoEfficio¶
In the example above, test does not have to be a predicate.
test can be any value which is like (seq coll) or 3, [1 2], or so.
If test is neither false nor nil, test is bound to name.
See also¶
- clojure.core/if-let (7)
- clojure.core/when (3)
- clojure.core/when-not (5)
- clojure.core/if (2)
- clojure.core/when-first (2)
- clojure.core/when-some (3)
- clojure.core/let (7)
Content from the matching ClojureDocs page, with authors credited on each contribution.