(contains-ns-key? fm ns)Returns true if any key in map contains a namespace value
(contains-ns-key? {:hello/a 1 :hello/b 2 :there/a 3 :there/b 4} :hello) => true
Returns `true` if any key in map contains a namespace value
(contains-ns-key? {:hello/a 1 :hello/b 2
:there/a 3 :there/b 4} :hello)
=> true(flatten-keys m)takes map m and flattens the first nested layer onto the root layer.
(flatten-keys {:a {:b 2 :c 3} :e 4}) => {:a/b 2 :a/c 3 :e 4}
(flatten-keys {:a {:b {:c 3 :d 4} :e {:f 5 :g 6}} :h {:i 7} :j 8}) => {:a/b {:c 3 :d 4} :a/e {:f 5 :g 6} :h/i 7 :j 8}
takes map `m` and flattens the first nested layer onto the root layer.
(flatten-keys {:a {:b 2 :c 3} :e 4})
=> {:a/b 2 :a/c 3 :e 4}
(flatten-keys {:a {:b {:c 3 :d 4}
:e {:f 5 :g 6}}
:h {:i 7}
:j 8})
=> {:a/b {:c 3 :d 4} :a/e {:f 5 :g 6} :h/i 7 :j 8}(flatten-keys-nested m)(flatten-keys-nested m max keep-empty)(flatten-keys-nested m max keep-empty seperator)Returns a single associative map with all of the nested
keys of m flattened. If keep is added, it preserves all the
empty sets
(flatten-keys-nested {"a" {"b" {"c" 3 "d" 4} "e" {"f" 5 "g" 6}} "h" {"i" {}}}) => {"a/b/c" 3 "a/b/d" 4 "a/e/f" 5 "a/e/g" 6}
(flatten-keys-nested {"a" {"b" {"c" 3 "d" 4} "e" {"f" 5 "g" 6}} "h" {"i" {}}} -1 true) => {"a/b/c" 3 "a/b/d" 4 "a/e/f" 5 "a/e/g" 6 "h/i" {}}
Returns a single associative map with all of the nested
keys of `m` flattened. If `keep` is added, it preserves all the
empty sets
(flatten-keys-nested {"a" {"b" {"c" 3 "d" 4}
"e" {"f" 5 "g" 6}}
"h" {"i" {}}})
=> {"a/b/c" 3 "a/b/d" 4 "a/e/f" 5 "a/e/g" 6}
(flatten-keys-nested {"a" {"b" {"c" 3 "d" 4}
"e" {"f" 5 "g" 6}}
"h" {"i" {}}}
-1 true)
=> {"a/b/c" 3 "a/b/d" 4 "a/e/f" 5 "a/e/g" 6 "h/i" {}}(group-by-set f coll)Returns a map of the elements of coll keyed by the result of f on each element. The value at each key will be a set of the corresponding elements, in the order they appeared in coll.
(group-by-set even? [1 2 3 4 5]) => {false #{1 3 5}, true #{2 4}}
Returns a map of the elements of coll keyed by the result of
f on each element. The value at each key will be a set of the
corresponding elements, in the order they appeared in coll.
(group-by-set even? [1 2 3 4 5])
=> {false #{1 3 5}, true #{2 4}}(group-keys fm)(group-keys fm ns)Returns the set of keys in fm that has keyword namespace
of ns
(group-keys {:hello/a 1 :hello/b 2
:there/a 3 :there/b 4})
=> {:there #{:there/a :there/b}, :hello #{:hello/b :hello/a}}
(group-keys {:hello/a 1 :hello/b 2 :there/a 3 :there/b 4} :hello) => #{:hello/a :hello/b}
Returns the set of keys in `fm` that has keyword namespace
of `ns`
(group-keys {:hello/a 1 :hello/b 2
:there/a 3 :there/b 4})
=> {:there #{:there/a :there/b}, :hello #{:hello/b :hello/a}}
(group-keys {:hello/a 1 :hello/b 2
:there/a 3 :there/b 4} :hello)
=> #{:hello/a :hello/b}(list-ns-keys fm)Returns the set of keyword namespaces within a map
(list-ns-keys {:hello/a 1 :hello/b 2 :there/a 3 :there/b 4}) => #{:hello :there}
Returns the set of keyword namespaces within a map
(list-ns-keys {:hello/a 1 :hello/b 2
:there/a 3 :there/b 4})
=> #{:hello :there}(nest-keys m nskv)(nest-keys m nskv ex)Returns a map that takes m and extends all keys with the
nskv vector. ex is the list of keys that are not extended.
(nest-keys {:a 1 :b 2} [:hello :there]) => {:hello {:there {:a 1 :b 2}}}
(nest-keys {:there 1 :b 2} [:hello] [:there]) => {:hello {:b 2} :there 1}
Returns a map that takes `m` and extends all keys with the
`nskv` vector. `ex` is the list of keys that are not extended.
(nest-keys {:a 1 :b 2} [:hello :there])
=> {:hello {:there {:a 1 :b 2}}}
(nest-keys {:there 1 :b 2} [:hello] [:there])
=> {:hello {:b 2} :there 1}(pathify-keys-nested m)(pathify-keys-nested m max)(pathify-keys-nested m max keep-empty)(pathify-keys-nested m max keep-empty arr)converts a nested map structure into a flat map structure
(pathify-keys-nested {:a {:b {:c 1}}}) => {[:a :b :c] 1}
(pathify-keys-nested {:a {:b {:c 1}}} 2) => {[:a :b] {:c 1}}
(pathify-keys-nested {:a {:b {:c 1 :d 3 :e {}}}} -1 true) => {[:a :b :c] 1, [:a :b :d] 3, [:a :b :e] {}}
converts a nested map structure into a flat map structure
(pathify-keys-nested {:a {:b {:c 1}}})
=> {[:a :b :c] 1}
(pathify-keys-nested {:a {:b {:c 1}}} 2)
=> {[:a :b] {:c 1}}
(pathify-keys-nested {:a {:b {:c 1
:d 3
:e {}}}}
-1 true)
=> {[:a :b :c] 1, [:a :b :d] 3, [:a :b :e] {}}(treeify-keys m)Returns a nested map, expanding out the first level of keys into additional hash-maps.
(treeify-keys {:a/b 2 :a/c 3}) => {:a {:b 2 :c 3}}
(treeify-keys {:a/b {:e/f 1} :a/c {:g/h 1}}) => {:a {:b {:e/f 1} :c {:g/h 1}}}
Returns a nested map, expanding out the first
level of keys into additional hash-maps.
(treeify-keys {:a/b 2 :a/c 3})
=> {:a {:b 2 :c 3}}
(treeify-keys {:a/b {:e/f 1} :a/c {:g/h 1}})
=> {:a {:b {:e/f 1}
:c {:g/h 1}}}(treeify-keys-nested m)Returns a nested map, expanding out all levels of keys into additional hash-maps.
(treeify-keys-nested {:a/b 2 :a/c 3}) => {:a {:b 2 :c 3}}
(treeify-keys-nested {:a/b {:e/f 1} :a/c {:g/h 1}}) => {:a {:b {:e {:f 1}} :c {:g {:h 1}}}}
Returns a nested map, expanding out all
levels of keys into additional hash-maps.
(treeify-keys-nested {:a/b 2 :a/c 3})
=> {:a {:b 2 :c 3}}
(treeify-keys-nested {:a/b {:e/f 1} :a/c {:g/h 1}})
=> {:a {:b {:e {:f 1}}
:c {:g {:h 1}}}}(unnest-keys m nskv)(unnest-keys m nskv ex)The reverse of nest-keys. Takes m and returns a map
with all keys with a keyword-nsvec of nskv being 'unnested'
(unnest-keys {:hello/a 1 :hello/b 2 :there/a 3 :there/b 4} [:hello]) => {:a 1 :b 2 :there {:a 3 :b 4}}
(unnest-keys {:hello {:there {:a 1 :b 2}} :again {:c 3 :d 4}} [:hello :there] [:+]) => {:a 1 :b 2 :+ {:again {:c 3 :d 4}}}
The reverse of `nest-keys`. Takes `m` and returns a map
with all keys with a `keyword-nsvec` of `nskv` being 'unnested'
(unnest-keys {:hello/a 1
:hello/b 2
:there/a 3
:there/b 4} [:hello])
=> {:a 1 :b 2
:there {:a 3 :b 4}}
(unnest-keys {:hello {:there {:a 1 :b 2}}
:again {:c 3 :d 4}} [:hello :there] [:+])
=> {:a 1 :b 2
:+ {:again {:c 3 :d 4}}}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 |