I have a vector of maps:
[{:a 1} {:b 2 :d 4} {:c 3} {:d 4}]
and I want to find the map where :c = 3 and insert another map {:x 100} before it, resulting in [{:a 1} {:b 2 :d 4} {:x 100} {:c 3} {:d 4}]
What's the best way to accomplish this in specter?(I don't know the index I need to insert at, just the keys in the map I need to insert before )
I've been messing with INDEXED-VALS and trying to collect the index and then insert the new map, but I'm having trouble getting this to work and am not sure this is the right line of thinking or if there's a better way
@jjttjj I would do that with a select followed by a transform:
(if-let [i (select-first [INDEXED-VALS (selected? LAST :c (pred= 3)) FIRST)] data)]
(setval (before-index i) {:x 100} data))
you can also do it in a single operation using zippers
https://github.com/nathanmarz/specter/wiki/Using-Specter-With-Zippers
cool, that one works, thanks!