auto-coerce map entries to vectors during ALL
This commit is contained in:
parent
3a38c844e6
commit
7e54757659
4 changed files with 27 additions and 8 deletions
|
|
@ -1,3 +1,6 @@
|
|||
## 0.9.3 (unreleased)
|
||||
* ALL on maps auto-coerces MapEntry to vector, enabling smoother transformation of map keys
|
||||
|
||||
## 0.9.2
|
||||
* Added VOID selector which navigates nowhere
|
||||
* Better syntax checking for defpath
|
||||
|
|
|
|||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
0.9.2
|
||||
0.9.3-SNAPSHOT
|
||||
|
|
|
|||
|
|
@ -500,19 +500,30 @@
|
|||
(assoc structure akey (next-fn (get structure akey))
|
||||
))
|
||||
|
||||
(defn all-select [structure next-fn]
|
||||
(into [] (r/mapcat next-fn structure)))
|
||||
|
||||
(defn all-transform [structure next-fn]
|
||||
(let [empty-structure (empty structure)]
|
||||
(cond (list? empty-structure)
|
||||
;; this is done to maintain order, otherwise lists get reversed
|
||||
(doall (map next-fn structure))
|
||||
|
||||
(map? structure)
|
||||
(->> structure (r/map vec) (r/map next-fn) (into empty-structure))
|
||||
|
||||
:else
|
||||
(->> structure (r/map next-fn) (into empty-structure))
|
||||
)))
|
||||
|
||||
(deftype AllStructurePath [])
|
||||
|
||||
(extend-protocol p/StructurePath
|
||||
AllStructurePath
|
||||
(select* [this structure next-fn]
|
||||
(into [] (r/mapcat next-fn structure)))
|
||||
(all-select structure next-fn))
|
||||
(transform* [this structure next-fn]
|
||||
(let [empty-structure (empty structure)]
|
||||
(if (list? empty-structure)
|
||||
;; this is done to maintain order, otherwise lists get reversed
|
||||
(doall (map next-fn structure))
|
||||
(->> structure (r/map next-fn) (into empty-structure))
|
||||
))))
|
||||
(all-transform structure next-fn)))
|
||||
|
||||
(deftype ValCollect [])
|
||||
|
||||
|
|
|
|||
|
|
@ -615,6 +615,11 @@
|
|||
)
|
||||
|
||||
|
||||
(deftest all-map-test
|
||||
(is (= {3 3} (s/transform [s/ALL s/FIRST] inc {2 3})))
|
||||
(is (= {3 21 4 31} (s/transform [s/ALL s/ALL] inc {2 20 3 30})))
|
||||
)
|
||||
|
||||
#+clj
|
||||
(deftest large-params-test
|
||||
(let [path (apply s/comp-paths (repeat 25 s/keypath))
|
||||
|
|
|
|||
Loading…
Reference in a new issue