specter

caleb.macdonaldblack 2023-06-16T18:13:41.854919Z

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 considered

phronmophobic 2023-06-16T18:24:34.075099Z

I'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.

🎉 1
phronmophobic 2023-06-16T18:26:31.700259Z

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).

caleb.macdonaldblack 2023-06-16T18:27:23.160249Z

Wow. rookie error. I’m not sure why I thought sp/all wouldn’t return the map-entries. Thanks 😊

👍 1
nathanmarz 2023-06-16T22:00:36.230169Z

it's easier to just do (setval [MAP-KEYS string?] NONE data)

😊 1
caleb.macdonaldblack 2023-06-17T01:58:55.214439Z

That’s a nice solution too. Didn’t think of that either. Thanks