code-reviews

dharrigan 2019-09-10T12:53:50.037500Z

Is there a way to do this better?...

dharrigan 2019-09-10T12:56:38.037700Z

(def xform
  (comp
   (map #(let [{:keys [id location geohash frequency]} %]
           {:id id :location (m/pgobject-location->latlng location) :geohash geohash :frequency frequency}))))

dharrigan 2019-09-10T12:56:52.038100Z

given that I need to convert the location into a different format

2019-09-10T13:02:49.039400Z

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]))))

πŸ‘ 1
dominicm 2019-09-10T13:03:05.039800Z

You want the update function, no?

dharrigan 2019-09-10T13:08:14.041100Z

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...

dharrigan 2019-09-10T13:08:33.041400Z

@delaguardo works great

dominicm 2019-09-10T13:10:48.042400Z

We were discussing this yesterday in JUXT

dominicm 2019-09-10T13:11:12.043100Z

I think Tim Baldridge's video on this is good

2019-09-10T13:11:24.043300Z

not in the scope of transducers https://clojure.org/reference/transducers#_defining_transformations_with_transducers

dharrigan 2019-09-10T13:11:30.043600Z

link me! πŸ™‚

dharrigan 2019-09-10T13:12:09.043700Z

Thank you! (and for the rewrite!) πŸ™‚ It's good to learn! πŸ™‚

2019-09-10T13:12:45.043900Z

you are welcome)

2019-09-10T13:16:10.044100Z

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

dharrigan 2019-09-10T13:18:05.044300Z

thank you

jaihindhreddy 2019-09-10T22:25:39.044700Z

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