add map-key
This commit is contained in:
parent
5dea8919be
commit
2423127877
3 changed files with 20 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
## 1.0.2-SNAPSHOT
|
||||
|
||||
* Added `pred=`, `pred<`, `pred>`, `pred<=`, `pred>=` for filtering using common comparisons
|
||||
* Add `map-key` navigator
|
||||
|
||||
## 1.0.1
|
||||
|
||||
|
|
|
|||
|
|
@ -868,6 +868,20 @@
|
|||
)))
|
||||
structure)))))
|
||||
|
||||
(defrichnav
|
||||
^{:doc "Navigates to the given key in the map (not to the value). Navigates regardless
|
||||
of whether the key currently exists in the map. For transforms, will assoc nil
|
||||
value if key doesn't currently exist in map."}
|
||||
map-key
|
||||
[key]
|
||||
(select* [this vals structure next-fn]
|
||||
(next-fn vals key))
|
||||
(transform* [this vals structure next-fn]
|
||||
(let [newkey (next-fn vals key)
|
||||
oldval (get structure key)]
|
||||
(-> structure (dissoc key) (assoc newkey oldval))
|
||||
)))
|
||||
|
||||
(def ^{:doc "Navigate to the specified keys one after another. If navigate to NONE,
|
||||
that element is removed from the map or vector."}
|
||||
keypath
|
||||
|
|
|
|||
|
|
@ -1527,6 +1527,11 @@
|
|||
(is (= [3 4] (select [s/ALL (s/pred>= 3)] data)))
|
||||
))
|
||||
|
||||
(deftest map-key-test
|
||||
(is (= {:b nil :c 3} (setval (s/map-key :a) :b {:c 3})))
|
||||
(is (= {:b 2} (setval (s/map-key :a) :b {:a 2})))
|
||||
)
|
||||
|
||||
#?(:clj
|
||||
(do
|
||||
(defprotocolpath FooPP)
|
||||
|
|
|
|||
Loading…
Reference in a new issue