Fork me on GitHub
#specter
<
2016-11-23
>
caio20:11:56

failing on the following providepath:

(sp/declarepath map-walker)
(sp/providepath map-walker
                 [(sp/walker map?)
                  (sp/continue-then-stay sp/MAP-VALS map-walker)])

nathanmarz21:11:47

@caio what version of specter?

nathanmarz21:11:59

are you doing aot compilation?

caio21:11:10

[com.rpl/specter “0.13.1”]`

caio21:11:39

yep, I’m doing aot compilation

nathanmarz21:11:48

could you open an issue for this? don't have time to look at it now

bfabry22:11:47

slightly gross:

(sp/transform [:parent sp/ALL #(= :children (first %)) sp/LAST] identity {:parent {:something {}}})
=> {:parent {:something {}}}
(sp/transform [:parent sp/ALL #(= :children (first %)) sp/LAST] identity {:parent {:something {} :children 1}})
=> {:parent {:something {}, :children 1}}

shooodooken23:11:47

👍 gives me the correct result so not too gross. looks like i can drop the sp/LAST aswell.

(sp/transform [:parent sp/ALL #(= :children (first %))] identity {:parent {:something {}}})
=> {:parent {:something {}}}
(sp/transform [:parent sp/ALL #(= :children (first %))] identity {:parent {:something {} :children 1}})
=> {:parent {:something {}, :children 1}}

shooodooken23:11:11

i'm still thinking there must be a cleaner way out there

shooodooken23:11:24

must be a common enough scenario

bfabry23:11:37

I guess it defaults to this way because that's what update-in does

shooodooken23:11:12

i could have sworn i already unsuccessfully tried what i'm about to post..

(sp/transform [:parent sp/ALL (sp/selected? :children)] identity {:parent {:something {} }})
=> {:parent {:something {}}}
(sp/transform [:parent sp/ALL (sp/selected? :children)] identity {:parent {:something {},:children 1 }})
=> {:parent {:something {}, :children 1}}

shooodooken23:11:43

but it works!

bfabry23:11:28

I think the difference is the sp/ALL bit

shooodooken23:11:12

i'm looking at transform now and thinking maybe i should be wrapping everything in sp/selected?

(sp/transform [(sp/selected? :parent) (sp/selected? :children)] identity {:parent {:something {},:children 1 }})
=> {:parent {:something {}, :children 1}}

shooodooken23:11:49

so if it doesn't exist, it's not created. not sure if that's sane or not?!

shooodooken23:11:12

(sp/transform [(sp/selected? :parent) (sp/selected? :children)] identity {})
=> {}

bfabry23:11:06

not sure it's doing what you expect

(sp/transform [(sp/selected? :parent) (sp/selected? :children)] identity {})
=> {}
(sp/transform [(sp/selected? :parent) (sp/selected? :children)] identity {:parent nil})
=> {:parent nil}
(sp/transform [(sp/selected? :parent) (sp/selected? :children)] identity {:parent {:something nil}})
=> {:parent {:something nil}}
(sp/transform [(sp/selected? :parent) (sp/selected? :children)] identity {:parent {:something nil :children nil}})
=> {:parent {:something nil, :children nil}}
(sp/transform [(sp/selected? :parent) (sp/selected? :children)] (constantly 'foo) {:parent {:something nil :children nil}})
=> foo

shooodooken23:11:03

you are correct...damn.!

bfabry23:11:05

undocumented function, sp/must

bfabry23:11:19

(sp/transform [(sp/must :parent)] (constantly 'foo) {})
=> {}
(sp/transform [(sp/must :parent)] (constantly 'foo) {:parent {}})
=> {:parent foo}
(sp/transform [(sp/must :parent)] (constantly 'foo) {:parent {:children {}}})
=> {:parent foo}
(sp/transform [(sp/must :parent)] (constantly 'foo) {:parent {:children {} :foo nil
                                                              }})
=> {:parent foo}
(sp/transform [(sp/must :parent) (sp/must :children)] (constantly 'foo) {:parent {:children {} :foo nil}})
=> {:parent {:children foo, :foo nil}}
(sp/transform [(sp/must :parent) (sp/must :children)] (constantly 'foo) {:parent { :foo nil}})
=> {:parent {:foo nil}}

bfabry23:11:28

actually that's not true, it has a docstring, just not visible from core

shooodooken23:11:54

super. that's the one.