given
[{:id 1
:some {:nested {:value 11}}}
{:id 2
:some {:nested {:value 3}}}]
I want to remove all top-level objects where [:some :nested :value] is greater than 10. How do I do that?not correct:
(transform
(subselect ALL :some :nested :value #(> % 10))
NONE
data)
gives:
[{:id 1, :some {:nested {}}} {:id 2, :some {:nested {:value 3}}}]
but I want:
[{:id 2, :some {:nested {:value 3}}}]
this is close, but I feel I’m missing something
(transform
[ALL (fn [x]
(> (-> x :some :nested :value) 10))]
NONE
data)
=> [nil {:id 2, :some {:nested {:value 3}}}]this does what i need:
(setval
[ALL (fn [x]
(> (-> x :some :nested :value) 10))]
NONE
data)
but I am expecting there to be something I can replace the function with. like:
(setval
[ALL (something [:some :nested :value #(> % 10)])]
NONE
data)(setval (filterer :some :nested :value (pred> 10)) [] data)
aha pred I see. why empty vector?
filterer works on a collection, it returns the filtered collection like filter
i don't think pred is necessary here, you can use your function directly
hmm, have to think on this. still don’t grok this. thanks!
but i'm surprised that (setval (subselect ALL :some :nested :value (pred> 10)) [] data) doesn't work though
just though of something that you might prefer: (setval [ALL (if-path [:some :nested :value #(> % 10)] STAY)] NONE data). btw you could simply use filter/remove here, with selected-any? if you want to use specter for the path, or is it inside a nested structure too ?
And even if the beginning is a path, it's just a select operation select-one (filterer :some :nested :value #(< % 10))