Fork me on GitHub
#specter
<
2016-10-17
>
nahuel21:10:40

is possible to use specter to dissoc? ej, transform {:a {:b 1 :c 2}} to {:a {:c 2}} ?

nathanmarz21:10:29

@nahuel You can just do (transform :a #(dissoc % :b) data)

nathanmarz21:10:52

I have a utility function to help with it: (defn dissocer [k] (fn [m] (dissoc m k)))

nathanmarz21:10:06

so you can do (transform :a (dissocer :b) data)

nathanmarz21:10:49

there's also some thought about extending ALL and keypath to be able to remove elements on this issue https://github.com/nathanmarz/specter/issues/117

nathanmarz21:10:10

but you could always just make your own navigator with that functionality

nahuel21:10:38

nathanmarz: thanks

nahuel21:10:41

why this doesnt work? (setval [:a #{1 2} ] :y {:a {1 :z 2 :z 3 :z }}) .. I expected {:a {1 :y, 2 :y, 3 :z}} but the map is unchanged (I'm trying to use the set as a predicate)

nathanmarz21:10:54

sets are interpreted as filter predicates

nathanmarz21:10:16

(#{1 2} {1 :z 2 :z 3 :z }) is false, so it stops navigation at that point

nathanmarz21:10:47

@nahuel you should do this: (setval [:a (multi-path (keypath 1) (keypath 2))] :y {:a {1 :z 2 :z 3 :z }})

nahuel21:10:14

but what if the keys are stored in a set? (it can be variable)

nathanmarz22:10:13

probably the easiest is to do (setval [:a (apply multi-path #{1 2})] ...)

nahuel22:10:10

mm, my set can be very big, I think there is some limitation for apply on the number of arguments

nathanmarz22:10:20

(apply + (range 100000)) => 4999950000

nathanmarz22:10:13

actually the code I gave you isn't quite right, it should be (setval [:a (apply multi-path (map keypath #{1 2}))] ...)

nahuel22:10:31

oh, thanks