A micro library of a single macro, cond-let.
cond-let acts like a cond, but adds :let terms that are followed by a
binding form (like let).
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.
Example:
(defn ^:private has-necessary-capabilities?
"Does the worker have all the capabilities that the job needs?"
[state worker-id task]
(cond-let
:let [job-id (:job-id task)]
(nil? job-id)
true
:let [capabilities (get-in state [:jobs job-id
:clockwork/required-capabilities])]
(empty? capabilities)
true
:let [worker-capabilities (get-in state [:workers worker-id
:capabilities])]
(empty? worker-capabilities)
false
:else
;; 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))
capabilities)))
https://github.com/walmartlabs/cond-let
--
Howard M. Lewis Ship
Senior Mobile Developer at Walmart Labs
(971) 678-5210
http://howardlewisship.com
@hlship
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.