Added NAME and NAMESPACE navigators
This commit is contained in:
parent
3dbc775334
commit
48efea55ab
2 changed files with 37 additions and 0 deletions
|
|
@ -959,6 +959,32 @@
|
||||||
(transform* [this structure next-fn]
|
(transform* [this structure next-fn]
|
||||||
(with-meta structure (next-fn (meta structure)))))
|
(with-meta structure (next-fn (meta structure)))))
|
||||||
|
|
||||||
|
(defnav ^{:doc "Navigates to the name portion of the keyword or symbol"}
|
||||||
|
NAME
|
||||||
|
[]
|
||||||
|
(select* [this structure next-fn]
|
||||||
|
(next-fn (name structure)))
|
||||||
|
(transform* [this structure next-fn]
|
||||||
|
(let [new-name (next-fn (name structure))
|
||||||
|
ns (namespace structure)]
|
||||||
|
(cond (keyword? structure) (keyword ns new-name)
|
||||||
|
(symbol? structure) (symbol ns new-name)
|
||||||
|
:else (i/throw-illegal "NAME can only be used on symbols or keywords - " structure)
|
||||||
|
))))
|
||||||
|
|
||||||
|
(defnav ^{:doc "Navigates to the name portion of the keyword or symbol"}
|
||||||
|
NAMESPACE
|
||||||
|
[]
|
||||||
|
(select* [this structure next-fn]
|
||||||
|
(next-fn (name structure)))
|
||||||
|
(transform* [this structure next-fn]
|
||||||
|
(let [name (name structure)
|
||||||
|
new-ns (next-fn (namespace structure))]
|
||||||
|
(cond (keyword? structure) (keyword new-ns name)
|
||||||
|
(symbol? structure) (symbol new-ns name)
|
||||||
|
:else (i/throw-illegal "NAMESPACE can only be used on symbols or keywords - " structure)
|
||||||
|
))))
|
||||||
|
|
||||||
(defdynamicnav
|
(defdynamicnav
|
||||||
^{:doc "Adds the result of running select with the given path on the
|
^{:doc "Adds the result of running select with the given path on the
|
||||||
current value to the collected vals."}
|
current value to the collected vals."}
|
||||||
|
|
|
||||||
|
|
@ -1408,3 +1408,14 @@
|
||||||
(s/selected? (collected? [n] (even? n))))
|
(s/selected? (collected? [n] (even? n))))
|
||||||
[4 2 3])))
|
[4 2 3])))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(deftest name-namespace-test
|
||||||
|
(= :a (setval s/NAME "a" :e))
|
||||||
|
(= :a/b (setval s/NAME "b" :a/e))
|
||||||
|
(= 'a (setval s/NAME "a" 'e))
|
||||||
|
(= 'a/b (setval s/NAME "b" 'a/e))
|
||||||
|
(= :a/e (setval s/NAMESPACE "a" :e))
|
||||||
|
(= :a/e (setval s/NAMESPACE "a" :f/e))
|
||||||
|
(= 'a/e (setval s/NAMESPACE "a" 'e))
|
||||||
|
(= 'a/e (setval s/NAMESPACE "a" 'f/e))
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue