A micro-library around the useful
cond-let acts like a
cond, but adds
:let terms that are followed by a binding form (like
This allows conditional code to introduce new local symbols; the result is clearer, more linear code, that doesn't make a march for the right margin.
An example from the Clockwork library:
(defn ^:private has-necessary-capabilities?
"Does the worker have all the capabilities that the job needs?"
[state worker-id task]
:let [job-id (:job-id task)]
:let [capabilities (get-in state [:jobs job-id :clockwork/required-capabilities])]
:let [worker-capabilities (get-in state [:workers worker-id :capabilities])]
;; It's ok for the worker to have *more* capabilities than are specified.
;; For each required capability, we need an exact match.
(= (select-keys worker-capabilities (keys capabilities))
Copyright © 2018 Walmart
Distributed under the Apache Software License 2.0.