A small snippet:
(or (some-> req :path-params :slug db/page html-ok) (not-found))
My gut feeling here is that this is too javascripty and not idiomatic clojure.
html-ok and not-found are rendering some html and put that into a ring response. To me this expression seems clear in isolation. Do you agree?
does html-ok return nil if no page is found?
not this is less about overall structure (which is ad-hoc at this point) and more about the general approach to do this kind of thing.
db/page returns nil
I'd use an if-let myself
which is why I used some->
instead of or ?
yeah
fetch the page in an if-let and either render ok or not-found
I think that's clearer
yeah, having the two branches of the if be the render calls makes sense to me
ah - you mean the db/page into the if-let. because it confuses the reader that this is typically the thing that will short circuit?
yes
right that makes sense ty
much better ty:
(if-let [page (some-> req :path-params :slug db/page)]
(html-ok page)
(not-found))
However in general - would or be used this way at all or should it really be thought of as evaluating to a boolean?That is kind of my bigger question. I’m used to using || and ?? in JS a ton.
const thing = maybe || default;
I use or to apply defaults, eg.
(or (f foo)
(g bar))
vs.
(if-let [result (f foo)]
result
(g bar))Right, similar to how get works
But I get that in the above case the if-let should be used
ty everyone ❤️
you could use or there, it's safe to put the html-ok call inside the some-> chain unless db/page returns false
it's a question of style of course