This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-25
Channels
- # announcements (4)
- # babashka (3)
- # beginners (79)
- # biff (4)
- # calva (17)
- # cider (18)
- # clj-kondo (21)
- # cljdoc (45)
- # cljs-dev (14)
- # cljsrn (9)
- # clojure (90)
- # clojure-europe (86)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-portugal (1)
- # clojure-uk (9)
- # clojurescript (20)
- # code-reviews (23)
- # conjure (14)
- # cursive (12)
- # datascript (12)
- # emacs (5)
- # events (2)
- # fulcro (13)
- # gratitude (1)
- # holy-lambda (9)
- # lambdaisland (2)
- # malli (6)
- # nbb (1)
- # nextjournal (2)
- # nrepl (30)
- # off-topic (63)
- # pathom (1)
- # portal (24)
- # reagent (5)
- # reitit (13)
- # releases (2)
- # remote-jobs (1)
- # sci (90)
- # shadow-cljs (49)
- # spacemacs (5)
- # sql (13)
- # testing (20)
- # tools-build (17)
- # xtdb (27)
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.
I'd use an if-let myself
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?
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?I use or
to apply defaults, eg.
(or (f foo)
(g bar))
vs.
(if-let [result (f foo)]
result
(g bar))
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