Miscelaneous utility (pure) functions/language extensions. A.K.A. "things that should be in clojure.core
".
Miscelaneous utility (pure) functions/language extensions. A.K.A. "things that should be in `clojure.core`".
(assoc-if m k v & more)
Associates only truthy values.
=> (assoc-if {:a 1} :b nil :c false :d :truthy) {:a 1 :d :truthy}
Associates only truthy values. => (assoc-if {:a 1} :b nil :c false :d :truthy) {:a 1 :d :truthy}
(assoc-in-if m ks v & more)
Associates-in only truthy values. Same as assoc-if
, but for nested maps.
=> (misc/assoc-in-if {} [:a] 1 [:b] nil [:c] (fn-that-returns-false) [:d] :truthy [:e :f] true) {:a 1 :d :truthy :e {:f true}}
Associates-in only truthy values. Same as `assoc-if`, but for nested maps. => (misc/assoc-in-if {} [:a] 1 [:b] nil [:c] (fn-that-returns-false) [:d] :truthy [:e :f] true) {:a 1 :d :truthy :e {:f true}}
(dissoc-if m k pred & more)
Dissociates only if pred is truthy.
=> (with-redefs [should-dissoc-key? (constantly true)] (misc/dissoc-if {:a 1 :b 2} :b (should-dissoc-key? :b))) {:a 1}
Dissociates only if pred is truthy. => (with-redefs [should-dissoc-key? (constantly true)] (misc/dissoc-if {:a 1 :b 2} :b (should-dissoc-key? :b))) {:a 1}
(dissoc-in m ks & kss)
Dissociates a value in a nested data structure.
=> (misc/dissoc-in {:a {:b 1 :c 2}} [:a :c]) {:a {:b 1}}
Dissociates a value in a nested data structure. => (misc/dissoc-in {:a {:b 1 :c 2}} [:a :c]) {:a {:b 1}}
(dissoc-in-if m ks pred & more)
Dissociates-in only if pred is truthy. Same as dissoc-if
but for nested maps.
=> (dissoc-in-if {:a {:b 1 :c 2}} [:a :b] true [:a :c] false) {:a {:c 2}}
Dissociates-in only if pred is truthy. Same as `dissoc-if` but for nested maps. => (dissoc-in-if {:a {:b 1 :c 2}} [:a :b] true [:a :c] false) {:a {:c 2}}
(map-keys f m)
Applies function f
to every key in map m
.
=> (map-keys {:a 1 :b 2}) {":a" 1 ":b" 2}
Applies function `f` to every key in map `m`. => (map-keys {:a 1 :b 2}) {":a" 1 ":b" 2}
(map-vals f m)
Applies function f
to every value in map m
.
=> (map-vals {:a 1 :b 2}) {:a "1" :b "2"}
Applies function `f` to every value in map `m`. => (map-vals {:a 1 :b 2}) {:a "1" :b "2"}
(update-if m k f & more)
Updates only truthy values. If you want to update also non-truthy values, just use #'clojure.core/update
.
=> (update-if {:a 1 :b nil} :a inc :b inc) {:a 2 :b nil}
Updates only truthy values. If you want to update also non-truthy values, just use `#'clojure.core/update`. => (update-if {:a 1 :b nil} :a inc :b inc) {:a 2 :b nil}
(update-in-if m ks f & more)
Updates-in only truthy values. Same as update-if
but for nested maps.
If you want to update-in also non-truthy values, just use #'clojure.core/update-in
.
=> (update-in-if {:a {:b 2 :c false}} [:a :b] inc [:a :c] dec) {:a {:b 3 :c false}}
Updates-in only truthy values. Same as `update-if` but for nested maps. If you want to update-in also non-truthy values, just use `#'clojure.core/update-in`. => (update-in-if {:a {:b 2 :c false}} [:a :b] inc [:a :c] dec) {:a {:b 3 :c false}}
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close