This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-13
Channels
- # announcements (1)
- # babashka (28)
- # beginners (72)
- # biff (6)
- # calva (15)
- # clerk (14)
- # clj-otel (4)
- # cljdoc (4)
- # clojure (121)
- # clojure-europe (61)
- # clojure-nl (2)
- # clojure-norway (63)
- # clojure-uk (5)
- # datahike (35)
- # datalevin (37)
- # datomic (7)
- # emacs (2)
- # fulcro (6)
- # gratitude (1)
- # honeysql (2)
- # hyperfiddle (38)
- # malli (9)
- # matrix (24)
- # meander (4)
- # off-topic (10)
- # polylith (8)
- # reagent (2)
- # releases (1)
- # shadow-cljs (8)
- # spacemacs (4)
- # specter (1)
- # squint (5)
- # tools-deps (3)
Could someone point me in the right direction with Meander as I try to learn it. Is there a way of matching both map and sub map data in a manner that returns a combined result? Essentially I have a case of
{:important-key1 "test"
:important-key2 "test2"
:useless-key1 ""
:useless-map {}
:subservices {:dynamic-name1 {:important-key ""
:useless-key2 ""
:dynamic-name2 {:important-key ""
:useless-key2 ""}}}}
Actual data is a lot more complex than that. But the structure is the same.
I would like to cherry pick the important keys from the data using meander, in the example given it would just drop the useless keys and retain other things. Am I going the wrong way for trying to figure out a meander query that I can use that returns everything with a single match that I wouldn't have to merge the results of meander outside of it?
The real use-case would take similar data to the above one, but create several new keys to the root based on the dynamic-name1 and 2. But one step at a time. Am I going wrong with Meander here?Not solving your exact case here. But hopefully something useful in this post. https://jimmyhmiller.github.io/meander-practical If you are wanting one result m/rewrite is probably best to focus on. On mobile so sadly can’t write an example.
Thank you for the examples there, I wasn't able to get the system quite where I wanted it to be yet but I am getting close with rewrite. It's slow going and needs more input adjustment. This might take me a hot minute to learn. Currently the challenge holding me back is the questions: how to iterate over a map of objects indexed by name with rewrites. Or how to manipulate rewrite's [{:important-key ?key} ...]
syntax to return a value indexed map instead of a vector.
Definately bit more than my skills could handle when I decided to try meander. I'll get back to you if I figure out a way of doing the above or make a workaround.
Edit: My current out is a vector of subservices without key indexes. This isn't enough because I need to merge values from another datasource into the subservices by their name but it's closer.
Cracked it, here is the final result that allows me to work with the data in a way I wanted to.:
(meander/rewrite
(mu/decode "application/json" (slurp "test/app/fixtures/simple.json"))
{:payload {:name ?name
:composite ?composite
:type ?type
:datasources [{:name (meander/and !name !index) :replicator {:version !version}} ...]}}
{(meander/keyword ?name) {:name ?name
:composite ?composite
:type ?type
:datasources {& ([(meander/keyword !index) {:name !name :replicator {:version !version}}] ...)}}})
With an input of payload object with a datasources being a vector it spits out a name indexed map of the sub services. It's not the ideal solution since the input needs to be a map with a vector instead of a map with a submap. But at this point I'll take my victory and call it for this round. I can make it work. The solution to my problems is in how the datasources lines are being manipulated and rewritten.