added must navigator
This commit is contained in:
parent
9d2a5ed46f
commit
b4b2200377
4 changed files with 34 additions and 2 deletions
|
|
@ -1,3 +1,6 @@
|
|||
## 0.10.1 (unreleased)
|
||||
* Added `must` navigator
|
||||
|
||||
## 0.10.0
|
||||
* Make codebase bootstrap cljs compatible
|
||||
* Remove usage of reducers in cljs version in favor of transducers (thanks @StephenRudolph)
|
||||
|
|
|
|||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
0.10.0
|
||||
0.10.1-SNAPSHOT
|
||||
|
|
|
|||
|
|
@ -269,13 +269,28 @@
|
|||
next-val))
|
||||
structure)))))
|
||||
|
||||
(defpath keypath [key]
|
||||
(defpath
|
||||
^{:doc "Navigates to the specified key, navigating to nil if it does not exist."}
|
||||
keypath
|
||||
[key]
|
||||
(select* [this structure next-fn]
|
||||
(next-fn (get structure key)))
|
||||
(transform* [this structure next-fn]
|
||||
(assoc structure key (next-fn (get structure key)))
|
||||
))
|
||||
|
||||
(defpath
|
||||
^{:doc "Navigates to the key only if it exists in the map."}
|
||||
must
|
||||
[k]
|
||||
(select* [this structure next-fn]
|
||||
(next-fn (get structure k)))
|
||||
(transform* [this structure next-fn]
|
||||
(if (contains? structure k)
|
||||
(assoc structure k (next-fn (get structure k)))
|
||||
structure
|
||||
)))
|
||||
|
||||
(defpath view [afn]
|
||||
(select* [this structure next-fn]
|
||||
(next-fn (afn structure)))
|
||||
|
|
|
|||
|
|
@ -244,6 +244,19 @@
|
|||
(s/transform (s/view afn) identity i)
|
||||
)))
|
||||
|
||||
(defspec must-test
|
||||
(for-all+
|
||||
[k1 gen/int
|
||||
k2 (gen/such-that #(not= k1 %) gen/int)
|
||||
m (gen-map-with-keys gen/int gen/int k1)
|
||||
op (gen/elements [inc dec])
|
||||
]
|
||||
(let [m (dissoc m k2)]
|
||||
(and (= (s/transform (s/must k1) op m)
|
||||
(s/transform (s/keypath k1) op m))
|
||||
(= (s/transform (s/must k2) op m) m)
|
||||
))))
|
||||
|
||||
(defspec parser-test
|
||||
(for-all+
|
||||
[i gen/int
|
||||
|
|
@ -835,3 +848,4 @@
|
|||
(seq? l2) ; Transformed lists are only guaranteed to impelment ISeq
|
||||
(= q1 q2)
|
||||
(= (type q1) (type q2))))))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue