Is there a way to do this better?...
(def xform
(comp
(map #(let [{:keys [id location geohash frequency]} %]
{:id id :location (m/pgobject-location->latlng location) :geohash geohash :frequency frequency}))))
given that I need to convert the location into a different format
Assuming you will use xform in transducer context so you can chain map
calls
(def xform
(comp
(map #(update % :location m/pgobject-location->latlng))
(map #(select-keys % [:id :location :geohash :frequency]))))
You want the update function, no?
This is what confused me still with transducers, how to read the order, i.e., it looks like in that comp form above, stuff is being applied bottom up....(whereas, the natural way of looking at pipelines is top to bottom)...a bit confusing...
@delaguardo works great
We were discussing this yesterday in JUXT
I think Tim Baldridge's video on this is good
not in the scope of transducers https://clojure.org/reference/transducers#_defining_transformations_with_transducers
link me! π
Thank you! (and for the rewrite!) π It's good to learn! π
you are welcome)
And if you donβt need to have maps with listed keys but only with updated location: (map #(update % :location ....))
will give you a transducer )
You can check on map
βs documentation - look for note about one-arity version of map
thank you
there's actually a subtle difference, the old version always has all four keys in the output with absent values as nil, whereas delaguardo's version omits absent keys, because of select-keys