Preferences

There is a neat macro I've been using to solve problems like the nested if-lets in the post:

https://github.com/Engelberg/better-cond

  (b/cond
   :let [x (foo)]
   (not x) (do (log "foo failed") false)
   :let [y (bar x)]
   (not y) (do (log "bar failed") false)
   :let [z (baz x y)]
   (not z) (do (log "baz failed") false)
   :else (do (qux x y z) (log "it worked") true))

Have you looked into the `some->` threading macro? https://clojure.github.io/clojure/clojure.core-api.html#cloj...
Yes, it gives you short circuiting on nil values. The post mentions `some->` and laments its inability to handle varying function signatures.

You can combine `some->` with other threading macros to make it achieve the desired effect, and you can also achieve the desired effect with `if-let` as the post demonstrates, but I believe the b/cond approach to be more readable than both.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal