Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/walmartlabs/cond-let
A useful merge of cond and let
https://github.com/walmartlabs/cond-let
clojure
Last synced: 3 months ago
JSON representation
A useful merge of cond and let
- Host: GitHub
- URL: https://github.com/walmartlabs/cond-let
- Owner: walmartlabs
- License: other
- Created: 2018-10-03T15:59:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-05T21:39:59.000Z (about 6 years ago)
- Last Synced: 2024-10-12T01:39:17.526Z (4 months ago)
- Topics: clojure
- Language: Clojure
- Homepage:
- Size: 8.79 KB
- Stars: 30
- Watchers: 11
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# com.walmartlabs/cond-let
[![Clojars Project](https://img.shields.io/clojars/v/com.walmartlabs/cond-let.svg)](https://clojars.org/com.walmartlabs/cond-let)
> Like this? By publishing it, I found out about [better-cond](https://github.com/Engelberg/better-cond) which has a super-set of the features here.
Go use it with my blessing! I do!A micro-library around the useful `cond-let` macro.
`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.[API Documentation](http://walmartlabs.github.io/apidocs/cond-let/)
## Usage
An example from the Clockwork library:
```clj
(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)))
```## License
Copyright © 2018 Walmart
Distributed under the Apache Software License 2.0.