such.maps
Various functions on key-value structures
conj-into
(conj-into original & additions)
original
is a map. additions
is a sequence of keys and values (not a map). Each key is used to identify a value within the map. That original
value is updated by conjing on the associated additions
value.
(conj-into {:a [1] :b '(1)} :a 2 :b 2) => '{:a [1 2] :b (2 1)}
If the key isn’t present in the map, it is created as a list containing the value.
(conj-into {} :a 1) => '{:a (1)}
dissoc-keypath
(dissoc-keypath map keys)
Like dissoc
, but takes a sequence of keys that describes a path to a value. There must be at least two keys in the path.
(subject/dissoc-keypath {:by-name {:name1 1}} [:by-name :name1])
=> {:by-name { }}
key-difference
(key-difference original unwanted)
Remove (as with dissoc
) all the keys in original
that are in unwanted
.
(key-difference {:a 1, :b 2} {:b ..irrelevant.., :c ..irrelevant..}) => {:a 1}
mkmap:all-keys-with-value
(mkmap:all-keys-with-value keys v)
Create a map with keys keys
. Each key will have v
as its value.
(mkmap:all-keys-with-value [:a, :b] 3) => {:a 3, :b 3}
update-each-value
(update-each-value kvs f & args)
Call f
on each value in map kvs
, passing it the value and any args
.
(update-each-value {:a 1, :b 0} + 2) => {:a 3, :b 2}