Clojure has a great standard library. Even so, some things could be easier than they are.
clj-foundation supplies namespaces making additional simple things easy and hard things possible in Clojure for functions needed across all Clojure projects at Brad's Deals.
The following describe our core goals/values for clj-foundation:
The folowing is a small sample of clj-foundation's features:
(let-map [meaning 42
secrets (io/read-file "/etc/passwd")])
==>
{:meaning 42
:secrets "nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false\nroot:*:0:0:System Administrator:/var/root:/bin/sh\n...."}
;; Replace a nil value with a default
(replace-nil (:first-name customer) "John")
;; Returns value if non-nil else throws IllegalArgumentException naming the nil value
(not-nil (:first-name customer) "First name")
;; Expect a condition specified by a predicate to become true within timeout-millis.
;; Throws IllegalStateException on failure with the specified message.
(expect-within
(millis/<-seconds 5)
(fn [] (= (meaning-of-life) 42))
"Couldn't compute the meaning of life.")
;; Retry x times, with millis puase interval a specified function that is failure-prone
(retry 5 (millis/<-seconds 10) some-unreliable-io-operation)
;; Given:
(def content "Say hello to ${NAME}")
;; Then:
(templates/subst<- content :NAME "Jack")
==>
"Say hello to Jack"
(subst<- content :ZIP "46989")
==>
ExceptionInfo Not found: '${NAME}' clojure.core/ex-info
(interpolation-vars content)
==>
(:NAME)
;; Return a Jar resource as a string
(resource-as-string "config.txt")
;; Return a Jar resource as a string, but allow the ALT_CONFIG_LOCATION Java system or O/S environment
;; variable to redirect reading to an external configuration file instead.
(resource-as-string "ALT_CONFIG_LOCATION" "config.txt")
;; Return a Jar resource as a string, interpolating any template variables inside the Jar resource
;; using the supplied interpolation variables and the override rules defined by the template language.
(read-template "config.properties" :NAME "Jack")
;; Return a Jar resource as a string, possibly overridden by the environment variable ALT_CONFIG_LOCATION
;; per the template engine's precedence rules. Any template variables in the file will also be substuted
;; using the supplied key/value pairs and/or matching environment variables per the template engine's
;; precedence rules.
(read-template "ALT_CONFIG_LOCATION" "config.properties" :NAME "Jack")
:user {:repositories [["jitpack" "https://jitpack.io"]]
:dependencies [[com.github.shopsmart/clj-foundation "version"]]}
where "version" currently is "".
<repositories>
<repository>
<id>jitpack.io</id>
<name>Jitpack repo</name>
<url>https://jitpack.io</url>
</repository>
</repositories>
# Build
$ lein jar
# Test
$ lein with-profile test test
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close