4 ms·
> Nevertheless I definitely emitted some crappy code in my first few months. Stuff like: (every? #(= % “success”) (map :status (:state task))) > Which I’d
by dghf 10y ago
> Nevertheless I definitely emitted some crappy code in my first few months. Stuff like:
(every? #(= % “success”) (map :status (:state task)))
> Which I’d write like this today:
(->> task
:state
(map :status)
(every? #(= % “success”)))
While I love threading macros, I'd argue in this case readability and comprehensibility between the two examples is more or less a wash.
Personally, I find the former slightly easier to grasp at first sight. The second could be improved (again, in my personal opinion) by combining the first two lines: it seems unnecessarily granular to say, essentially, "we take a map called task, and then we get the value of its :state attribute", rather than just "we get the value of the :state attribute of the map called task".
Both could be made terser via the set-as-predicate idiom:
(->> (:state task)
(map :status)
(every? #{“success”}))