Functions that operate on Clojure maps.
Functions that operate on Clojure maps.
(assoc-in-if-present m path f)
Assocs f into m only if the path presents in m
Assocs f into m only if the path presents in m
(assoc-thunk-result-if-not-present m k thunk)
(assoc-thunk-result-if-not-present m k thunk & kvs)
Like assoc, except only adds the key-value pair if the key doesn't exist in the map
Like assoc, except only adds the key-value pair if the key doesn't exist in the map
(contains-path? m path)
Whether the specified path exists in the map
Whether the specified path exists in the map
(copy-key m from-k to-k)
(deep-merge-with f & maps)
Like merge-with, but merges maps recursively, applying the given fn only when there's a non-map at a particular level.
(deep-merge-with + {:a {:b {:c 1 :d {:x 1 :y 2}} :e 3} :f 4} {:a {:b {:c 2 :d {:z 9} :z 3} :e 100}}) -> {:a {:b {:z 3, :c 3, :d {:z 9, :x 1, :y 2}}, :e 103}, :f 4}
Like merge-with, but merges maps recursively, applying the given fn only when there's a non-map at a particular level. (deep-merge-with + {:a {:b {:c 1 :d {:x 1 :y 2}} :e 3} :f 4} {:a {:b {:c 2 :d {:z 9} :z 3} :e 100}}) -> {:a {:b {:z 3, :c 3, :d {:z 9, :x 1, :y 2}}, :e 103}, :f 4}
(dissoc-in m [k & ks :as path])
(dissoc-in m path & more-paths)
Dissociates an entry from a nested associative structure returning a new nested structure. path is a sequence of keys. Any empty maps that result will not be present in the new structure.
Dissociates an entry from a nested associative structure returning a new nested structure. path is a sequence of keys. Any empty maps that result will not be present in the new structure.
(dissoc-or-throw m & ks)
(filter-by-key pred m)
Given a predicate like (fn [k] ...) returns a map with only entries with keys that match it.
Given a predicate like (fn [k] ...) returns a map with only entries with keys that match it.
(filter-by-val pred m)
Given a predicate like (fn [v] ...) returns a map with only entries with vals that match it.
Given a predicate like (fn [v] ...) returns a map with only entries with vals that match it.
(filter-map pred m)
Given a predicate like (fn [k v] ...) returns a map with only entries that match it.
Given a predicate like (fn [k v] ...) returns a map with only entries that match it.
(for-map seq-exprs key-expr val-expr)
(for-map m-sym seq-exprs key-expr val-expr)
Like 'for' for building maps. Same bindings except the body should have a key-expression and value-expression. If a key is repeated, the last value (according to "for" semantics) will be retained. (= (for-map [i (range 2) j (range 2)] [i j] (even? (+ i j))) {[0 0] true, [0 1] false, [1 0] false, [1 1] true}) An optional symbol can be passed as a first argument, which will be bound to the transient map containing the entries produced so far.
Like 'for' for building maps. Same bindings except the body should have a key-expression and value-expression. If a key is repeated, the last value (according to "for" semantics) will be retained. (= (for-map [i (range 2) j (range 2)] [i j] (even? (+ i j))) {[0 0] true, [0 1] false, [1 0] false, [1 1] true}) An optional symbol can be passed as a first argument, which will be bound to the transient map containing the entries produced so far.
(invert-map m)
Inverts a map: key becomes value, value becomes key
Inverts a map: key becomes value, value becomes key
(keys-to-keywords m
&
{:keys [underscore-to-hyphens?]
:or {underscore-to-hyphens? true}})
Recursively transform the key of the map(could be nested) to be type of keyword
Recursively transform the key of the map(could be nested) to be type of keyword
(keywords->hyphenated-keywords m)
Transforms the keywords in map to hyphen seperated style
Transforms the keywords in map to hyphen seperated style
(keywords->underscored-keywords m)
Transforms the keywords in map to underscore seperated style
Transforms the keywords in map to underscore seperated style
(keywords->underscored-strings m)
Transforms the keywords in map to be underscored strings
Transforms the keywords in map to be underscored strings
(let-map & kvs)
Creates a hash-map which can refer to the symbols of the names of the keys declared above.
Creates a hash-map which can refer to the symbols of the names of the keys declared above.
(map-difference m1 m2)
Returns the difference of m1 and m2: the entires in m1 but not in m2 + entries in m2 but not in m1
Returns the difference of m1 and m2: the entires in m1 but not in m2 + entries in m2 but not in m1
(map-keys f m)
Build map (f k) -> v for [k v] in map m
Build map (f k) -> v for [k v] in map m
(map-over-map f m)
Given a function like (fn [k v] ...) returns a new map with each entry mapped by it.
Given a function like (fn [k v] ...) returns a new map with each entry mapped by it.
(map-values f m)
Build map k -> (f v) for [k v] in map, preserving the initial type
Build map k -> (f v) for [k v] in map, preserving the initial type
(move-key m old-key new-key)
Changes the entry's key which is old-key to new-key (the corresponding value untouched)
Changes the entry's key which is old-key to new-key (the corresponding value untouched)
(nested-dissoc data & ks)
dissoc keys from every map at every level of a nested data structure
dissoc keys from every map at every level of a nested data structure
(paths m)
Return the paths of the leaves in the map
Return the paths of the leaves in the map
(rand-select-keys m n)
Selects a subset of 'n' k/v pairs from 'm'
Selects a subset of 'n' k/v pairs from 'm'
(rmerge & maps)
Recursive merge of the provided maps.
Recursive merge of the provided maps.
(select-keys-always m ks)
(select-keys-always m ks default)
Selects the entires whose key presents in ks from m
Selects the entires whose key presents in ks from m
(select-paths m & paths)
Similar to select-keys, just the 'key' here is a path in the nested map
Similar to select-keys, just the 'key' here is a path in the nested map
(sget m k)
Safe get. Get the value of key k
from map m
only if the key really
exists, throw exception otherwise.
Safe get. Get the value of key `k` from map `m` only if the key really exists, throw exception otherwise.
(sorted-zipmap keys vals)
Returns a sorted map with the keys mapped to the corresponding vals.
Returns a sorted map with the keys mapped to the corresponding vals.
(submap? sub-map m)
Determine whether sub-map is a submap of m.
Determine whether sub-map is a submap of m.
(subpath? root-path path)
true if 'path' is a child of 'root-path'
true if 'path' is a child of 'root-path'
(subpaths path)
(transform-keywords f m)
Transforms all the keywords in the specified map using the speicified function
Transforms all the keywords in the specified map using the speicified function
(update-in-if-present m path f)
Updates the specified path in the map only if it presents
Updates the specified path in the map only if it presents
(update-in-matching m path f)
(update-in-matching m path f a1)
(update-in-matching m path f a1 a2)
(update-in-matching m path f a1 a2 a3)
(update-in-matching m path f a1 a2 a3 & args)
update-in that accept :, :-val
(update-in-matching {:foo {:bar {:baz [1]} :quz {:baz [2]}}} [:foo :-val :baz :] inc) => {:foo {:bar {:baz [2]}, :quz {:baz [3]}}}
update-in that accept :*, :*-val (update-in-matching {:foo {:bar {:baz [1]} :quz {:baz [2]}}} [:foo :*-val :baz :*] inc) => {:foo {:bar {:baz [2]}, :quz {:baz [3]}}}
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close