When I use (transform [...] f data) and the path yields 0 results, so my f is never called, how can I detect that and for example throw an exception?
(let [path ...] (select-one! p data) (transform p f data)) looks weird too 😕
I guess the transform function is designed to go through a set of data and transform the found entries. And then return the result. Not sure why you might expect it to run f if the path fails to match. Could you test afterwards whether the data had been changed? Perhaps comparing it with the previous data.
you could do something like (let [vol (volatile! false)] (transform ... (fn [v] (vreset! vol true) (actual-transform-fn v)) data))
Okay yeah, works just fine.
Would you then also use the volatile trick to transform only the first match in case multiple elements are selected? I can't seem to solve the simplest stuff now 😞. E.g. can you give an example of run transform on the first even element of (range 10)
I mean I can do it with the volatile trick, but isnt there a way to do it with navigators?
Hmmm, filterer seems promising.
there's a similar example on Specter's README for incrementing the last odd number in a sequence: (transform [(filterer odd?) LAST] inc data)