Unless I’m mistaken, Specter seems to lack support for working with map-entries. I’m curious as to why this is? For example:
(into {}
(remove (comp string? key))
{:x 1
"y" 2
'z 3})
It doesn’t seem to be straight forward to achieve something like that in Specter.
Perhaps:
1. There is a simple solution I’m not aware of, or
2. It’s easy enough with just core libs so Specter isn’t needed, or
3. Some trade-off exists that makes it non-viable to support this, or
4. There is an alternative, and perhaps better ,approach to achieving the same thing, or
5. What I’m trying to do could be considered an anti-pattern
a. For example:
(let [pred (partial = 10)]
(first (filter pred (range 20))))
;; Typically used for find-by-id on sequences. However a lookup on a map is preferred.
6. or, It’s easy enough to extend Specter to support this, or
7. Something else I haven’t consideredI'm not sure what you tried that didn't work, but the following seems to work for me:
(specter/setval [specter/ALL (comp string? first)]
specter/NONE
{:x 1
"y" 2
'z 3})
;; {:x 1, z 3}
Even if that didn't work, it wouldn't be that hard to extend specter to work the way you want.key was changed to first because specter/ALL on a map seems to navigate to a selection of two element vectors instead of map entries for some reason (maybe there could be an improvement there).
Wow. rookie error. I’m not sure why I thought sp/all wouldn’t return the map-entries. Thanks 😊
it's easier to just do (setval [MAP-KEYS string?] NONE data)
That’s a nice solution too. Didn’t think of that either. Thanks