Practical examples of use for Clojure's some-> macro

some-> can be used to "auto-guard" a threaded series of processing steps where some part in the chain (especially in the middle) might return nil which would cause a logic failure further down the chain.

Particular examples could include threading clojure functions together with java interop where you would need to guard against null pointer exceptions.


A GitHub code search turns up quite a few examples


The clojuredocs.org page on some-> has some some-> examples*:

(-> {:a 1} :b inc)
;; NullPointerException   clojure.lang.Numbers.ops (Numbers.java:942)

(some-> {:a 1} :b inc)
;; nil

* pun intended

Tags:

Clojure