Fork me on GitHub
#specter
<
2019-08-14
>
nathanmarz00:08:14

@puzzler select-one is the same as select-first except it enforces that your path navigates to at most one value

nathanmarz00:08:34

corrected the wiki entry on select-first, thanks for letting me know

nathanmarz00:08:42

you probably want select-one for your use case

puzzler05:08:00

I recall a time when you sketched out a navigator for transforming a nested map in such a way that on the way out, it would recursively delete any keys with empty maps. I can't find it in the slack logs. Do you by any chance have a handy pointer to that?

ben.mumford08:08:02

i asked a similar question here and on SO and posted nathan's answer: https://stackoverflow.com/a/57002777/1185536

puzzler08:08:14

I saw that, but it looks like the answers are all about scanning through a whole nested map structure removing nil leaves. That's not really what I want. I want things to get removed if the output of the transformation is NONE, and that causes its map to be empty, and so on.

puzzler08:08:08

So something like: (setval (keypath-remove-empties :a :c :d) NONE {:b 1, :a {:c {:d 0}}}) gives back {:b 1}

schmee08:08:55

@puzzler I believe you’re looking for compact?

user=> (sp/setval (sp/compact :a :c :d) sp/NONE {:b 1, :a {:c {:d 0}}})
{:b 1}

nathanmarz12:08:49

you probably don't want to return NONE if the top-level structure becomes empty, so something like (setval [:a (compact :c :d)] NONE data) is generally the pattern to use

lxsli14:08:54

I've finally figured out why I can't use filterer after MAP-KEYS; it expects a sequence where MAP-KEYS navigates to a view of many keyword (for me) elements

lxsli14:08:14

Which is better: (setval [MAP-KEYS #(#{"a"} (namespace %))] NONE mymap) or: (setval [(filterer [FIRST NAMESPACE #{"a"}]) MAP-KEYS] NONE mymap) please?

lxsli14:08:30

or y'know something else

lxsli14:08:41

The difference seems more substantial when using select; the latter form allows me to get the whole entries whereas the former has irrevocably descended to the keys

lxsli14:08:28

My initial attempt btw was something like (setval [MAP-KEYS (filterer NAMESPACE #{"a"})] NONE mymap)

nathanmarz15:08:55

@alee you can also do (setval [MAP-KEYS (selected? NAMESPACE (pred= "a"))] NONE mymap)