specter

Samuel Ludwig 2025-04-14T16:03:16.782679Z

trying to test myself with some (contrived) practice problems, would appreciate feedback on solutions (and also if you think I should just use vanilla clojure for the given situation), I still have a lot of blindspots I'm trying to illuminate: current problem: lifting a nested map into its parent, more or less 'flattening' it I feel like I might be using collect-one and view too much as a crutch (i even have a (def collect-view (comp collect-one view)) defined a few lines up), unsure if its the best way

Samuel Ludwig 2025-04-14T16:03:34.154939Z

Samuel Ludwig 2025-04-14T17:36:59.836639Z

maybe the function in the second view would be better as #(setval [:three :andmore] NONE %) so that its path matches the one the in collect-one, meaning I can parameterize it a little neater like so

(defn lift [m apath]
    (transform [(collect-one apath)
                (view #(setval apath NONE %))]
      merge m))

nathanmarz 2025-04-14T17:42:33.018279Z

Specter is for targeted queries/transforms to data structures, but what you're doing here I would classify as "restructuring"

❤️ 1
nathanmarz 2025-04-14T17:43:08.895529Z

Specter can certainly help for use cases like this, but it won't be like the super concise paths for other use cases

Samuel Ludwig 2025-04-14T17:46:04.144079Z

this makes sense! I appreciate that clarification a lot, that helps define some boundaries for me and give me a little bit more of a hold on reality.

Samuel Ludwig 2025-04-14T20:14:25.803139Z

ah i actually like this

(defn lift [apath m]
  (->> m
    (transform (collect-one apath) merge)
    (setval apath NONE)))