This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-29
Channels
- # announcements (35)
- # aws (40)
- # babashka (10)
- # beginners (119)
- # calva (25)
- # cider (13)
- # clj-kondo (15)
- # cljsrn (23)
- # clojure (205)
- # clojure-dev (3)
- # clojure-europe (15)
- # clojure-germany (3)
- # clojure-italy (3)
- # clojure-nl (2)
- # clojure-uk (58)
- # clojurescript (193)
- # community-development (2)
- # conjure (147)
- # core-async (49)
- # crux (8)
- # cursive (47)
- # datomic (21)
- # duct (1)
- # fulcro (19)
- # graalvm (3)
- # graphql (1)
- # helix (3)
- # hoplon (11)
- # jackdaw (1)
- # joker (1)
- # juxt (5)
- # kaocha (1)
- # keechma (3)
- # lambdaisland (6)
- # local-first-clojure (27)
- # malli (5)
- # off-topic (41)
- # rdf (27)
- # re-frame (7)
- # reagent (15)
- # reitit (5)
- # rum (11)
- # shadow-cljs (157)
- # spacemacs (18)
- # sql (4)
I'm having a bit of an hard time trying to massage some data into another structure, can anyone help? I'm open to using clojure or specter or whatever to get the job done π Here's the original structure...
{"Foobar Motor Group" [{:poi_name "Foobar Motor Group",
:poi_type "GARAGE",
:trip_location #object[org.postgresql.util.PGobject
"0xbda6575"
"44A40"],
:trip_timestamp #inst "2020-02-03T10:41:50"}
{:poi_name "Foobar Motor Group",
:poi_type "GARAGE",
:trip_location #object[org.postgresql.util.PGobject
"0x258b4c14"
"44A40"],
:trip_timestamp #inst "2020-02-03T10:08:19"}
{:poi_name "Foobar Motor Group",
:poi_type "GARAGE",
:trip_location #object[org.postgresql.util.PGobject
"0xed60b3b"
"44A40"],
:trip_timestamp #inst "2020-02-03T09:40:19"}]}
{"Foobar Motor Group" [{:poi_name "Foobar Motor Group",
:poi_type "GARAGE",
:trips [{:trip_location #object......,
:trip_timestamp #inst......}
{:trip_location #object......,
:trip_timestamp #inst......}]}]}
in this example, all the things in the vector are garages, right? if they're unique, any reason why it isn't a hash rather than a vec?
It's just an example, there are multitude of other types in the result set returned
So then u want to merge together all the maps with the same name type and then add in the trips basically in a vec?
yes, in effect deduping the poi's into one and then adding the trips associated with the poi into a vec
β’ transform to flattten data structure β’ group-by β’ transform group-by output to what you want
I did (group-by :poi_name results)
where results is similar to the example I gave at the start π
so then you have a simple (medley/map-vals
transform to do to get thing in the shape thatt you want
nah its just a
(mapv #(select-keys % [:trip_location :trip_timestamp) ...)
innittProbably well enough, and hopefully more experienced enough to say "that could be rewritten better!" π
I think that snippet looks okay, I'd just format it so it's easier to visually parse and maybe rename a couple of the fns to be really explicit, but then my fn names are usually on the long side
Cabin fever is definitely starting to get the better of me. I started a blog... https://blog.nerdwick.net/
That's a really nice looking site! I did the same thing (https://eamonnsullivan.co.uk/), out of pure boredom. Mine looks like something out of the early noughts...
Thanks! Yours looks great - nice and clean, and with far more content than mine! Early days though... Subscribed!