(cond+ & clauses)Cond on steroids.
Define new variables between conditions:
(cond+ false :false :let [x 1] (= 1 x) (str x)) ; => "1"
Insert imperative code:
(cond+ (= 1 a) :false :do (println a) ; will print 1 :else :true)
Declare variables inside conditions, just like if+:
(cond+ (and (= 1 1) :let [x 2, y (+ x 1)] (> y x)) [x y]) ;; => [2 3]
Cond on steroids.
Define new variables between conditions:
(cond+
false :false
:let [x 1]
(= 1 x) (str x)) ; => "1"
Insert imperative code:
(cond+
(= 1 a) :false
:do (println a) ; will print 1
:else :true)
Declare variables inside conditions, just like if+:
(cond+
(and
(= 1 1)
:let [x 2, y (+ x 1)]
(> y x))
[x y]) ;; => [2 3](if+ cond then)(if+ cond then else)Allows sharing local variables between condition and then clause.
Use :let [...] form (not nested!) inside and condition and its bindings
will be visible in later and clauses and inside then branch:
(if+ (and (= 1 2) ;; same :let syntax as in doseq/for :let [x 3 y (+ x 4)] ;; x and y visible downstream (> y x))
;; “then” branch: x and y visible here!
(+ x y 5)
;; “else” branch: no x nor y
6)
Allows sharing local variables between condition and then clause.
Use `:let [...]` form (not nested!) inside `and` condition and its bindings
will be visible in later `and` clauses and inside `then` branch:
(if+ (and
(= 1 2)
;; same :let syntax as in doseq/for
:let [x 3
y (+ x 4)]
;; x and y visible downstream
(> y x))
;; “then” branch: x and y visible here!
(+ x y 5)
;; “else” branch: no x nor y
6)(when+ cond & body)Allows sharing local variables between condition and body clause.
Use :let [...] form (not nested!) inside and condition and its bindings
will be visible in later and clauses and inside body:
(when+ (and (= 1 2) ;; same :let syntax as in doseq/for :let [x 3 y (+ x 4)] ;; x and y visible downstream (> y x))
;; “then” branch: x and y visible here!
(+ x y 5))
Allows sharing local variables between condition and body clause.
Use `:let [...]` form (not nested!) inside `and` condition and its bindings
will be visible in later `and` clauses and inside body:
(when+ (and
(= 1 2)
;; same :let syntax as in doseq/for
:let [x 3
y (+ x 4)]
;; x and y visible downstream
(> y x))
;; “then” branch: x and y visible here!
(+ x y 5))cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |