(assoc-in-new m ks v)
only assoc-in if the value in the original map is nil
(assoc-in-new {} [:a :b] 2) => {:a {:b 2}}
(assoc-in-new {:a {:b 1}} [:a :b] 2) => {:a {:b 1}}
only assoc-in if the value in the original map is nil (assoc-in-new {} [:a :b] 2) => {:a {:b 2}} (assoc-in-new {:a {:b 1}} [:a :b] 2) => {:a {:b 1}}
(assoc-in-nnil m arr v)
assoc-in a nested key/value pair to a map only on non-nil values
(assoc-in-nnil {} [:a :b] 1) => {:a {:b 1}}
(assoc-in-nnil {} [:a :b] nil) => {}
assoc-in a nested key/value pair to a map only on non-nil values (assoc-in-nnil {} [:a :b] 1) => {:a {:b 1}} (assoc-in-nnil {} [:a :b] nil) => {}
(assoc-new m k v)
(assoc-new m k v & more)
only assoc if the value in the original map is nil
(assoc-new {:a 1} :b 2) => {:a 1 :b 2}
(assoc-new {:a 1} :a 2 :b 2) => {:a 1 :b 2}
only assoc if the value in the original map is nil (assoc-new {:a 1} :b 2) => {:a 1 :b 2} (assoc-new {:a 1} :a 2 :b 2) => {:a 1 :b 2}
(assoc-nnil m k v)
(assoc-nnil m k v & more)
assoc key/value pairs to the map only on non-nil values
(assoc-nnil {} :a 1) => {:a 1}
(assoc-nnil {} :a 1 :b nil) => {:a 1}
assoc key/value pairs to the map only on non-nil values (assoc-nnil {} :a 1) => {:a 1} (assoc-nnil {} :a 1 :b nil) => {:a 1}
(dissoc-in m [k & ks])
(dissoc-in m [k & ks] keep)
disassociates keys from a nested map. Setting keep
to true
will
not remove a empty map after dissoc
(dissoc-in {:a {:b 10 :c 20}} [:a :b]) => {:a {:c 20}}
(dissoc-in {:a {:b 10}} [:a :b]) => {}
(dissoc-in {:a {:b 10}} [:a :b] true) => {:a {}}
disassociates keys from a nested map. Setting `keep` to `true` will not remove a empty map after dissoc (dissoc-in {:a {:b 10 :c 20}} [:a :b]) => {:a {:c 20}} (dissoc-in {:a {:b 10}} [:a :b]) => {} (dissoc-in {:a {:b 10}} [:a :b] true) => {:a {}}
(filter-keys pred m)
filters map based upon map keys
(filter-keys even? {0 :a 1 :b 2 :c}) => {0 :a, 2 :c}
filters map based upon map keys (filter-keys even? {0 :a 1 :b 2 :c}) => {0 :a, 2 :c}
(filter-vals pred m)
filters map based upon map values
(filter-vals even? {:a 1 :b 2 :c 3}) => {:b 2}
filters map based upon map values (filter-vals even? {:a 1 :b 2 :c 3}) => {:b 2}
(into-nnil to from)
like into but filters nil values for both key/value pairs and sequences
(into-nnil [] [1 nil 2 3]) => [1 2 3]
(into-nnil {:a 1} {:b nil :c 2}) => {:a 1 :c 2}
like into but filters nil values for both key/value pairs and sequences (into-nnil [] [1 nil 2 3]) => [1 2 3] (into-nnil {:a 1} {:b nil :c 2}) => {:a 1 :c 2}
(map-entries f m)
manipulates a map given the function
(map-entries (fn [[k v]] [(keyword (str v)) (name k)]) {:a 1 :b 2 :c 3}) => {:1 "a", :2 "b", :3 "c"}
manipulates a map given the function (map-entries (fn [[k v]] [(keyword (str v)) (name k)]) {:a 1 :b 2 :c 3}) => {:1 "a", :2 "b", :3 "c"}
(map-keys f m)
changes the keys of a map
(map-keys inc {0 :a 1 :b 2 :c}) => {1 :a, 2 :b, 3 :c}
changes the keys of a map (map-keys inc {0 :a 1 :b 2 :c}) => {1 :a, 2 :b, 3 :c}
(map-vals f m)
changes the values of a map
(map-vals inc {:a 1 :b 2 :c 3}) => {:a 2, :b 3, :c 4}
changes the values of a map (map-vals inc {:a 1 :b 2 :c 3}) => {:a 2, :b 3, :c 4}
(merge-new)
(merge-new m)
(merge-new m1 m2)
(merge-new m1 m2 & more)
only merge if the value in the original map is nil
(merge-new {:a 1} {:b 2}) => {:a 1 :b 2}
(merge-new {:a 1} {:a 2}) => {:a 1}
only merge if the value in the original map is nil (merge-new {:a 1} {:b 2}) => {:a 1 :b 2} (merge-new {:a 1} {:a 2}) => {:a 1}
(merge-nnil)
(merge-nnil m)
(merge-nnil m1 m2)
(merge-nnil m1 m2 & more)
merges key/value pairs into a single map only if the value exists
(merge-nnil {:a nil :b 1}) => {:b 1}
(merge-nnil {:a 1} {:b nil :c 2}) => {:a 1 :c 2}
(merge-nnil {:a 1} {:b nil} {:c 2}) => {:a 1 :c 2}
merges key/value pairs into a single map only if the value exists (merge-nnil {:a nil :b 1}) => {:b 1} (merge-nnil {:a 1} {:b nil :c 2}) => {:a 1 :c 2} (merge-nnil {:a 1} {:b nil} {:c 2}) => {:a 1 :c 2}
(retract-in m rels)
reversed the changes by transform-in
(retract-in {:b 2, :c {:d 1}} {[:c :d] [:a]}) => {:a 1 :b 2}
reversed the changes by transform-in (retract-in {:b 2, :c {:d 1}} {[:c :d] [:a]}) => {:a 1 :b 2}
(select-keys-nnil m ks)
selects only the non-nil key/value pairs from a map
(select-keys-nnil {:a 1 :b nil} [:a :b]) => {:a 1}
(select-keys-nnil {:a 1 :b nil :c 2} [:a :b :c]) => {:a 1 :c 2}
selects only the non-nil key/value pairs from a map (select-keys-nnil {:a 1 :b nil} [:a :b]) => {:a 1} (select-keys-nnil {:a 1 :b nil :c 2} [:a :b :c]) => {:a 1 :c 2}
(transform-in m rels)
moves values around in a map according to a table
(transform-in {:a 1 :b 2} {[:c :d] [:a]}) => {:b 2, :c {:d 1}}
moves values around in a map according to a table (transform-in {:a 1 :b 2} {[:c :d] [:a]}) => {:b 2, :c {:d 1}}
(transpose m)
sets the vals and keys and vice-versa
(transpose {:a 1 :b 2 :c 3}) => {1 :a, 2 :b, 3 :c}
sets the vals and keys and vice-versa (transpose {:a 1 :b 2 :c 3}) => {1 :a, 2 :b, 3 :c}
(unique m1 m2)
returns a map of all key/value pairs that differ from a second map
(unique {:a 1} {:a 2}) => {:a 1}
(unique {:a 1 :b 2} {:b 2}) => {:a 1}
(unique {:b 2} {:b 2 :a 1}) => nil
returns a map of all key/value pairs that differ from a second map (unique {:a 1} {:a 2}) => {:a 1} (unique {:a 1 :b 2} {:b 2}) => {:a 1} (unique {:b 2} {:b 2 :a 1}) => nil
(update-in-nnil m arr f & args)
update-in a nested key/value pair only if the value exists
(update-in-nnil {:a {:b 1}} [:a :b] inc) => {:a {:b 2}}
(update-in-nnil {} [:a :b] inc) => {}
update-in a nested key/value pair only if the value exists (update-in-nnil {:a {:b 1}} [:a :b] inc) => {:a {:b 2}} (update-in-nnil {} [:a :b] inc) => {}
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close