Utility functions for handling keywords.
Functions are memoized in situations where they handle at most one or two keywords directly (at a time, that is), as opposed to operating on collections.
Utility functions for handling keywords. Functions are memoized in situations where they handle at most one or two keywords directly (at a time, that is), as opposed to operating on collections.
(as-tuple kw)
Split a keyword into a tuple of [ns body], both keywords. Examples:
(mapv ns/as-tuple [:some-ns/some-kw :some.kw nil])
=> [[:some-ns :some-kw]
[nil :some.kw]
[nil nil]]
Split a keyword into a tuple of [ns body], both keywords. Examples: ```clojure (mapv ns/as-tuple [:some-ns/some-kw :some.kw nil]) => [[:some-ns :some-kw] [nil :some.kw] [nil nil]] ```
(flatten-join m)
(flatten-join path m)
Flatten a nested map into a single-level map indexed by composite keywords.
May provide a base path as a vector; see examples.
Example:
(def some-map
{:a {:m {:n 1
:l 2}}
:b {:x 3
:y 4}})
(flatten-join some-map)
=> {:a/m.n 1
:a/m.l 2
:b/x 3
:b/y 4}
(flatten-join [:some.ns] some-map)
=> {:some.ns/a.m.n 1
:some.ns/a.m.l 2
:some.ns/b.x 3
:some.ns/b.y 4}
Flatten a nested map into a single-level map indexed by composite keywords. May provide a base path as a vector; see examples. Example: ```clojure (def some-map {:a {:m {:n 1 :l 2}} :b {:x 3 :y 4}}) (flatten-join some-map) => {:a/m.n 1 :a/m.l 2 :b/x 3 :b/y 4} (flatten-join [:some.ns] some-map) => {:some.ns/a.m.n 1 :some.ns/a.m.l 2 :some.ns/b.x 3 :some.ns/b.y 4} ```
(join kws)
(join kw-ns & kws)
Join a vector of keywords into a composite keyword.
The following forms are equivalent:
; :a/b.c.d
(join :a :b :c :d)
(join [:a :b :c :d])
(join :a [:b :c :d])
Join a vector of keywords into a composite keyword. The following forms are equivalent: ```clojure ; :a/b.c.d (join :a :b :c :d) (join [:a :b :c :d]) (join :a [:b :c :d]) ```
(member? ns k)
Checks that a symbol or keyword is a member of the given namespace.
Namespace can be given as either a string or a keyword.
Checks that a symbol or keyword is a member of the given namespace. Namespace can be given as either a string or a keyword.
(name x)
Like [[core/name]], but returns a keyword, and is nil
-safe.
Example:
(mapv kw/name [:a/b :c nil])
=> [:b :c nil]
Like [[core/name]], but returns a keyword, and is `nil`-safe. Example: ```clojure (mapv kw/name [:a/b :c nil]) => [:b :c nil] ```
(namespace x)
Like [[core/namespace]], but returns a keyword, and is nil
-safe.
Example:
(mapv kw/namespace [:a/b :c nil])
=> [:a nil nil]
Like [[core/namespace]], but returns a keyword, and is `nil`-safe. Example: ```clojure (mapv kw/namespace [:a/b :c nil]) => [:a nil nil] ```
(qualify ns)
(qualify ns kw)
Qualify a keyword with a given namespace, overwriting an existing ns.
If ns
is a qualified keyword, uses its namespace.
Returns a partial when no keyword is provided.
Qualify a keyword with a given namespace, overwriting an existing ns. If `ns` is a qualified keyword, uses its namespace. Returns a partial when no keyword is provided.
(qualify-all ns)
(qualify-all ns v)
Prefix a vector of keywords with a given namespace.
Prefix a vector of keywords with a given namespace.
(qualify-keys ns)
(qualify-keys ns m)
Qualify each key in a map with a given namespace.
If only the namespace is provided, returns a transducer suitable for use in
(into {} xf m)
.
Qualify each key in a map with a given namespace. If only the namespace is provided, returns a transducer suitable for use in `(into {} xf m)`.
(share-ns? x y)
Checks that two symbols or keywords are part of the same namespace.
Checks that two symbols or keywords are part of the same namespace.
(split kw)
(split kw delim)
Splits a keyword into a vector of keywords where the first element is the
namespace or nil, and the rest is the body of the keyword split by re
;
defaults to splitting on '.'.
:some/big.keyword => [:some :big :keyword]
Does not split keyword namespace. Also works for strings delimited by '.', or indeed for symbols as well, probably.
Splits a keyword into a vector of keywords where the first element is the namespace or nil, and the rest is the body of the keyword split by `re`; defaults to splitting on '.'. :some/big.keyword => [:some :big :keyword] Does not split keyword namespace. Also works for strings delimited by '.', or indeed for symbols as well, probably.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close