This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-15
Channels
- # adventofcode (46)
- # announcements (3)
- # aws (7)
- # babashka (47)
- # beginners (86)
- # calva (40)
- # cider (8)
- # clj-kondo (22)
- # clojure (63)
- # clojure-europe (16)
- # clojure-hungary (3)
- # clojure-nl (1)
- # clojure-norway (46)
- # clojure-sweden (1)
- # clojure-uk (3)
- # clojuredesign-podcast (2)
- # conjure (4)
- # datalevin (1)
- # events (1)
- # fulcro (5)
- # graalvm (4)
- # honeysql (8)
- # hyperfiddle (15)
- # music (1)
- # off-topic (5)
- # pathom (7)
- # pedestal (1)
- # polylith (3)
- # portal (19)
- # quil (1)
- # re-frame (36)
- # releases (1)
- # specter (3)
- # sql (3)
- # timbre (11)
- # tools-deps (4)
- # xtdb (55)
Hi I'm trying to transform the output from instaparse:
[:S
[:game
[:id "1"]
[:draws
[:draw
[:cubes "3" "blue" "4" "red"]
[:cubes "1" "red" "2" "green" "6" "blue"]
[:cubes "2" "green"]]]]]
to something like:
{:id "1",
:draws
[[{:number "3", :color "blue"}
{:number "3", :color "blue"}]
[{:number "1", :color "red"}
{:number "2", :color "green"}
{:number "6", :color "blue"}]
[{:number "2", :color "green"}]]}
so far i was only able to acces the data via index:
(defn get-data [game]
(let [id (s/select-any [(s/nthpath 1 1 1)] game)
games (s/select [s/nthpath 1 2 1] game)]
{:id id :games games}))
i would prefer to have some path like [SELECTOR :id] etc. Could you tell me in which direction i should go there?You might like to look at using transform that will take a function that returns the transformation. in this case the function could take the vector [:cubes "3" "blue" "4" "red"] and transform it into the vector
[{:number "3", :color "blue"}
{:number "4", :color "red"}]
I also wonder if it would help to transform the vectors directory within the :game vector into a map before doing the transformation. That would give you the :id and and :draws keys before trying the transformation.
I will add that I notice loads of these kind of questions and looking at your data the fact that it does not easily transform into an obvious map is difficult.Thanks for your help! I saw now https://clojurians.slack.com/archives/C0FVDQLQ5/p1529932554000085 and understod that this is the simpler solution for me.