allow subselect/filterer to remove subvals

This commit is contained in:
nathanmarz 2017-04-13 10:20:24 -04:00
parent ee56ddc1ab
commit be30e46960
3 changed files with 19 additions and 5 deletions

View file

@ -1,5 +1,6 @@
## 1.0.1-SNAPSHOT ## 1.0.1-SNAPSHOT
* `subselect`/`filterer` can remove entries in source by transforming to a smaller sequence
* Add `satisfies-protpath?` * Add `satisfies-protpath?`
* Inline cache vars are marked private so as not to interfere with tooling * Inline cache vars are marked private so as not to interfere with tooling
* Improve performance of `ALL` transform on lists by 20% * Improve performance of `ALL` transform on lists by 20%

View file

@ -847,7 +847,10 @@
Requires that the input navigators will walk the structure's Requires that the input navigators will walk the structure's
children in the same order when executed on \"select\" and then children in the same order when executed on \"select\" and then
\"transform\"." \"transform\".
If transformed sequence is smaller than input sequence, missing entries
will be filled in with NONE, triggering removal if supported by that navigator."
[& path] [& path]
(late-bound-nav [late (late-path path)] (late-bound-nav [late (late-path path)]
(select* [this structure next-fn] (select* [this structure next-fn]
@ -857,9 +860,12 @@
transformed (next-fn select-result) transformed (next-fn select-result)
values-to-insert (i/mutable-cell transformed)] values-to-insert (i/mutable-cell transformed)]
(compiled-transform late (compiled-transform late
(fn [_] (let [next-val (first (i/get-cell values-to-insert))] (fn [_] (let [vs (i/get-cell values-to-insert)]
(i/update-cell! values-to-insert rest) (if vs
next-val)) (do (i/update-cell! values-to-insert next)
(first vs))
NONE
)))
structure))))) structure)))))
(def ^{:doc "Navigate to the specified keys one after another. If navigate to NONE, (def ^{:doc "Navigate to the specified keys one after another. If navigate to NONE,
@ -952,7 +958,10 @@
(defdynamicnav filterer (defdynamicnav filterer
"Navigates to a view of the current sequence that only contains elements that "Navigates to a view of the current sequence that only contains elements that
match the given path. An element matches the selector path if calling select match the given path. An element matches the selector path if calling select
on that element with the path yields anything other than an empty sequence." on that element with the path yields anything other than an empty sequence.
If transformed sequence is smaller than input sequence, the corresponding entries
will be removed from original sequence."
[& path] [& path]
(subselect ALL (selected? path))) (subselect ALL (selected? path)))

View file

@ -1514,6 +1514,10 @@
(is (= [10] (foo 10))) (is (= [10] (foo 10)))
)) ))
(deftest filterer-remove-test
(is (= [1 :a 3 5] (setval (s/filterer even?) [:a] [1 2 3 4 5])))
)
#?(:clj #?(:clj
(do (do
(defprotocolpath FooPP) (defprotocolpath FooPP)