assoc-in-new ^
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 ^
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 ^
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 ^
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}
clean-nested ^
returns a associative with nils and empty hash-maps removed.
(clean-nested {:a {:b {:c {}}}})
=> {}
(clean-nested {:a {:b {:c {} :d 1 :e nil}}})
=> {:a {:b {:d 1}}}
dissoc-in ^
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 {}}
dissoc-nested ^
returns `m` without all nested keys in `ks`.
(dissoc-nested {:a {:b 1 :c {:b 1}}} [:b])
=> {:a {:c {}}}
filter-keys ^
filters map based upon map keys
(filter-keys even? {0 :a 1 :b 2 :c})
=> {0 :a, 2 :c}
filter-vals ^
filters map based upon map values
(filter-vals even? {:a 1 :b 2 :c 3})
=> {:b 2}
into-nnil ^
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}
key-paths ^
the set of all paths in a map, governed by a max level of nesting
(key-paths {:a {:b 1} :c {:d 1}})
=> (contains [[:c :d] [:a :b]] :in-any-order)
(key-paths {:a {:b 1} :c {:d 1}} 1)
=> (contains [[:c] [:a]] :in-any-order)
keys-nested ^
the set of all nested keys in a map
(keys-nested {:a {:b 1 :c {:d 1}}})
=> #{:a :b :c :d}
map-entries ^
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 ^
changes the keys of a map
(map-keys inc {0 :a 1 :b 2 :c})
=> {1 :a, 2 :b, 3 :c}
map-vals ^
changes the values of a map
(map-vals inc {:a 1 :b 2 :c 3})
=> {:a 2, :b 3, :c 4}
merge-nested ^
merges nested values from left to right.
(merge-nested {:a {:b {:c 3}}} {:a {:b 3}})
=> {:a {:b 3}}
(merge-nested {:a {:b {:c 1 :d 2}}}
{:a {:b {:c 3}}})
=> {:a {:b {:c 3 :d 2}}}
merge-new ^
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-new-nested ^
merges nested values from left to right, provided the merged value does not exist
(merge-new-nested {:a {:b 2}} {:a {:c 2}})
=> {:a {:b 2 :c 2}}
(merge-new-nested {:b {:c :old}} {:b {:c :new}})
=> {:b {:c :old}}
merge-nnil ^
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 ^
reversed the changes by transform-in
(retract-in {:b 2, :c {:d 1}}
{[:c :d] [:a]})
=> {:a 1 :b 2}
select-keys-nnil ^
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 ^
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 ^
sets the vals and keys and vice-versa
(transpose {:a 1 :b 2 :c 3})
=> {1 :a, 2 :b, 3 :c}
unique ^
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
unique-nested ^
all nested values in `m1` that are unique to those in `m2`.
(unique-nested {:a {:b 1}}
{:a {:b 1 :c 1}})
=> {}
(unique-nested {:a {:b 1 :c 1}}
{:a {:b 1}})
=> {:a {:c 1}}
update-in-nnil ^
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-keys-in ^
updates all keys in a map with given function
(update-keys-in {:x {["a" "b"] 1 ["c" "d"] 2}} [:x] string/joinl)
=> {:x {"ab" 1 "cd" 2}}
(update-keys-in {:a {:c 1} :b {:d 2}} 2 name)
=> {:b {"d" 2}, :a {"c" 1}}
update-vals-in ^
updates all values in a map with given function
(update-vals-in {:a 1 :b 2} [] inc)
=> {:a 2 :b 3}
(update-vals-in {:a {:c 1} :b 2} [:a] inc)
=> {:a {:c 2} :b 2}
(update-vals-in {:a {:c 1} :b {:d 2}} 2 inc)
=> {:a {:c 2} :b {:d 3}}
(update-vals-in {:a 1 :b 2} 1 inc)
=> {:a 2, :b 3}