Fork me on GitHub
#announcements
<
2018-10-03
>
hlship16:10:36

com.walmartlabs/cond-let 1.0.0 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

👍 28
hlship20:10:58

It isn't. Wasn't aware of the other.

danielneal13:10:06

❤️ better cond, and this idea. I like how it stops the rightward drift. I do keep trying to sneak it into projects but usually get shut down because it's an additional dependency