Collection of useful Clojure utilities.
Collection of useful Clojure utilities.
(->map & ks)
Like {}
but can omit keys when you want it to be the same as the symbol
bound to the value. Useful for avoiding unnecessary repetition during map
construction. At >9 key-value pairs, switches from an array-map to
a hash-map just like {}
.
(let [[a b c d] (range)]
(->map a b :c1 c d))
;; => {:a 0, :b 1, :c1 2, :d 3}
Like `{}` but can omit keys when you want it to be the same as the symbol bound to the value. Useful for avoiding unnecessary repetition during map construction. At >9 key-value pairs, switches from an array-map to a hash-map just like `{}`. (let [[a b c d] (range)] (->map a b :c1 c d)) ;; => {:a 0, :b 1, :c1 2, :d 3}
(assoc* m & kvs)
Like clojure.core/assoc
, but won't assoc if key or val is nil.
Like `clojure.core/assoc`, but won't assoc if key or val is nil.
(contrast op)
(contrast op obj & objs)
Contrast multiple comparable objects with each other with op. (Wrapper
around clojure.core/compare
.) Example ops: < > <= >= = not=
Contrast multiple comparable objects with each other with op. (Wrapper around `clojure.core/compare`.) Example ops: < > <= >= = not=
(deep-merge & colls)
Like clojure.core/merge
, but recursively merges maps.
Like `clojure.core/merge`, but recursively merges maps.
(deep-merge-with _ coll)
(deep-merge-with f c1 c2)
(deep-merge-with f c1 c2 & cs)
Like clojure.core/merge-with
, but recursively merges maps.
Like `clojure.core/merge-with`, but recursively merges maps.
(derefable? ref)
Returns true if clojure.core/deref
can be called on ref.
Returns true if `clojure.core/deref` can be called on ref.
(dissoc-in m [k & ks])
Dissociates an entry from a nested associative structure returning a new nested structure. ks is a sequence of keys. Any empty maps that result will not be present in the new structure.
Dissociates an entry from a nested associative structure returning a new nested structure. ks is a sequence of keys. Any empty maps that result will not be present in the new structure.
(expect data pred)
(expect data pred msg)
Perform an assertion against a predicate. Returns data
on success.
(-> {:status 200, :body "Foo bar"} (expect (comp #{200 201 202} :status) "HTTP response status code was not successful.") :body)
Perform an assertion against a predicate. Returns `data` on success. (-> {:status 200, :body "Foo bar"} (expect (comp #{200 201 202} :status) "HTTP response status code was not successful.") :body)
(expect' pform pval msg)
Implementation detail of the expect
macro. Do not use this directly.
Implementation detail of the `expect` macro. Do not use this directly.
(expectation pred)
(expectation pred msg)
Constructs and returns an assertion function that checks input against a predicate, returns given input on success.
(def successful-resp? #(<= 200 % 299))
(def fetch
(comp :body (expectation successful-resp?) http/get))
(-> "https://example.com" fetch :body)
Constructs and returns an assertion function that checks input against a predicate, returns given input on success. (def successful-resp? #(<= 200 % 299)) (def fetch (comp :body (expectation successful-resp?) http/get)) (-> "https://example.com" fetch :body)
(in? coll elm)
Returns true if coll contains elm.
Returns true if coll contains elm.
(macro-body-opts [opts & body :as params])
Helper for creating macros that accept an optional map of options in their body. Call this function in your macro on the rest-body param and it will return a vector containing the option map and the rest of the body.
An option map will be found if there were more than one form in the body and the first form is a map.
Helper for creating macros that accept an optional map of options in their body. Call this function in your macro on the rest-body param and it will return a vector containing the option map and the rest of the body. An option map will be found if there were more than one form in the body and the first form is a map.
(read-edn-resource path)
(read-edn-resource path opts)
Read an EDN file at path from JVM resources.
Read an EDN file at path from JVM resources.
(regexp? x)
Returns true if x is a Java regular expression pattern.
Returns true if x is a Java regular expression pattern.
Alias to cljs.core/regexp?
. This exists purely to make writing *.cljc
files that need regexp?
easier.
Alias to `cljs.core/regexp?`. This exists purely to make writing *.cljc files that need `regexp?` easier.
(submap? map1 map2)
Returns true if map1 is a subset of map2.
Returns true if map1 is a subset of map2.
(trim-end s substr)
Trim substr from the end of s.
Trim substr from the end of s.
(trim-start s substr)
Trim substr from the start of s.
Trim substr from the start of s.
(when-let* bindings & body)
Short circuiting version of clojure.core/when-let
on multiple binding
forms.
Short circuiting version of `clojure.core/when-let` on multiple binding forms.
(with-gensyms syms & body)
Bulk generate "gensym" values and bind them to each symbol in "syms".
Bulk generate "gensym" values and bind them to each symbol in "syms".
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close