macro | since v0.0-1798 | imported clojure.core/some->> | Edit |
(some->> expr & forms)
When expr
is not nil, threads it into the first form (via ->>
), and when
that result is not nil, through the next, etc.
This is a safe navigation operator.
When expr is not nil, threads it into the first form (via ->>), and when that result is not nil, through the next etc
(defmacro some->>
{:added "1.5"}
[expr & forms]
(let [g (gensym)
steps (map (fn [step] `(if (nil? ~g) nil (->> ~g ~step)))
forms)]
`(let [~g ~expr
~@(interleave (repeat g) (butlast steps))]
~(if (empty? steps)
g
(last steps)))))