### Operations on associative structures
(deep-merge m & more)Deep merges two or more nested maps.
(deep-merge {:x {:a :a :b :b :c :c}}
{:x {:a :aa :b :bb}}
{:x {:a :aaa}})
=> {:x {:a :aaa :b :bb :c :c}}
Deep merges two or more nested maps.
```clojure
(deep-merge {:x {:a :a :b :b :c :c}}
{:x {:a :aa :b :bb}}
{:x {:a :aaa}})
=> {:x {:a :aaa :b :bb :c :c}}
```(deflatten-keys m)Builds a nested map out of a map obtained from flatten-keys.
(deflatten-keys {[:a :b :c] :x
[:a :b :d] :y})
=> {:a {:b {:c :x
:d :y}}}
Builds a nested map out of a map obtained from [[flatten-keys]].
```clojure
(deflatten-keys {[:a :b :c] :x
[:a :b :d] :y})
=> {:a {:b {:c :x
:d :y}}}
```(flatten-keys m)Transforms a nested map into a map where keys are paths through the original map and values are leafs these paths lead to.
(flatten-keys {:a {:b {:c :x
:d :y}}})
=> {[:a :b :c] :x
[:a :b :d] :y}
(flatten-keys {:a {:b {:c :x
:d :y}}})
=> {[:a :b :c] :x
[:a :b :d] :y}
Transforms a nested map into a map where keys are paths through
the original map and values are leafs these paths lead to.
```clojure
(flatten-keys {:a {:b {:c :x
:d :y}}})
=> {[:a :b :c] :x
[:a :b :d] :y}
```
(flatten-keys {:a {:b {:c :x
:d :y}}})
=> {[:a :b :c] :x
[:a :b :d] :y}(index-by f coll)(index-by f strategy coll)Like group-by except it applies a strategy to each grouped
collection.
A strategy is a function with signature key, entries) -> entry
where entry is the one that will be indexed.
The default strategy asserts there is only one entry for the given
key and returns it.
(def ms [{:a 1 :b 2} {:a 3 :b 4} {:a 5 :b 4}])
(index-by :a ms)
=> {1 {:a 1 :b 2}
3 {:a 3 :b 4}
5 {:a 5 :b 4}}
(index-by :b ms)
=> ; clojure.lang.ExceptionInfo (Duplicate entries for key 4)
(index-by :b (fn [key entries]
(last entries))
ms)
=> {2 {:a 1 :b 2}
4 {:a 5 :b 4}}
Like `group-by` except it applies a strategy to each grouped
collection.
A strategy is a function with signature `key, entries) -> entry`
where `entry` is the one that will be indexed.
The default strategy asserts there is only one entry for the given
key and returns it.
```clojure
(def ms [{:a 1 :b 2} {:a 3 :b 4} {:a 5 :b 4}])
(index-by :a ms)
=> {1 {:a 1 :b 2}
3 {:a 3 :b 4}
5 {:a 5 :b 4}}
(index-by :b ms)
=> ; clojure.lang.ExceptionInfo (Duplicate entries for key 4)
(index-by :b (fn [key entries]
(last entries))
ms)
=> {2 {:a 1 :b 2}
4 {:a 5 :b 4}}
```(map-difference m & ms)Returns a map that is the first map without elements of the remaining maps.
Returns a map that is the first map without elements of the remaining maps.
(map-keys f m)Applies f to each key of m.
Applies `f` to each key of `m`.
(map-vals f m)Applies f to each value of m.
Applies `f` to each value of `m`.
(merge-with-plan plan & maps)Like merge-with except that the combination fn of a specific pair
of entries is determined by looking up their key in plan. If not
found, falls back to the function found under key :else or if not
provided to a function that returns the value in the right-most map,
thus providing the behavior of merge.
In addition to a map, plan can also be a function accepting a key
and returning a combination fn for the two values to merge.
Like `merge-with` except that the combination fn of a specific pair of entries is determined by looking up their key in `plan`. If not found, falls back to the function found under key `:else` or if not provided to a function that returns the value in the right-most map, thus providing the behavior of `merge`. In addition to a map, `plan` can also be a function accepting a key and returning a combination fn for the two values to merge.
(split-map m & kss)Returns a series of maps built by splitting m along each sequence
of keys in kss: the first map has (first kss) as keys, the second
one (second kss), etc ... while the last map has the remaining keys
from m.
Returns a series of maps built by splitting `m` along each sequence of keys in `kss`: the first map has `(first kss)` as keys, the second one `(second kss)`, etc ... while the last map has the remaining keys from `m`.
(submap? map1 map2)Determines whether map1 is a subset, keys and values wise, of
map2.
Determines whether `map1` is a subset, keys and values wise, of `map2`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |