specter

Latest version: 1.1.3
nathanmarz 2019-08-14T00:33:14.022800Z

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

nathanmarz 2019-08-14T00:36:34.023200Z

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

nathanmarz 2019-08-14T00:38:42.023500Z

you probably want select-one for your use case

puzzler 2019-08-14T05:02:00.025Z

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.mumford 2019-08-14T08:10:02.025600Z

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

puzzler 2019-08-14T08:12:14.027Z

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.

puzzler 2019-08-14T08:14:08.028900Z

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

schmee 2019-08-14T08:58:55.029400Z

@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}

puzzler 2019-08-14T11:27:34.029700Z

@schmee Yes, thanks!

nathanmarz 2019-08-14T12:48:49.030900Z

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

lxsli 2019-08-14T14:18:54.031700Z

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

lxsli 2019-08-14T14:20:14.033300Z

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

lxsli 2019-08-14T14:20:30.033500Z

or y'know something else

lxsli 2019-08-14T14:25:41.034600Z

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

lxsli 2019-08-14T14:26:28.035400Z

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

nathanmarz 2019-08-14T15:42:55.035900Z

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