code-reviews

2019-09-21T00:54:11.005700Z

Hi folks, I created the library: https://github.com/dawran6/emoji. Currently the emoji.core ns is about 100 loc. Feel free to drop your comments here or on the Github issues. Thank you! 😄

dominicm 2019-09-23T05:49:58.017700Z

I don't think that would make a significant difference? There's only 2 levels of lazy sequence.

2019-09-23T14:25:01.017900Z

It might be a great chance for me to learn about transducers. I'll give it a try. Thanks @vincent.cantin , @dominicm

2019-09-26T15:18:33.022200Z

@dawran6 I recommend you this blog post serie on transducers: https://vincent.404.taipei/clojure/build-your-own-transducer-part1/

2019-09-26T15:21:14.022500Z

@dominicm transducers remove all the cost of the laziness and also remove intermediate buffering as well. For a library, it is often desirable.

2019-09-26T15:29:27.022800Z

Appreciate! I came across your blog post just a while ago. Now is a good time to practice it 🙂

😄 1
2019-09-26T15:29:35.023Z

I submitted this issue https://github.com/dawran6/emoji/issues/6

2019-09-26T15:30:36.023400Z

Feel free to ask in #code-reviews if you have any question on transducers, remember to tag me.

🦜 1
2019-09-26T15:32:07.023800Z

Absolutely!

2019-09-26T15:32:32.024Z

or tag me in the issue if needed (@green-coder)

dharrigan 2019-09-21T11:41:28.007700Z

What would be a better way of doing this?

dharrigan 2019-09-21T11:41:43.008Z

(defn filter-trip
  [trip]
  (cond
   (= nil (:id trip)) false
   (= nil (:tripData trip)) false
   (= nil (:tenantId trip)) false
   (= nil (-> trip :tripData :startLocation)) false
   (= nil (-> trip :tripData :endLocation)) false
   (= nil (-> trip :tripData :segments)) false
   (= nil (:device trip)) false
   (= nil (-> trip :device :id)) false
   ((contains? #{"BAD" "UNUSABLE"} (:accuracy trip))) false
   :else trip))

dharrigan 2019-09-21T11:42:26.008300Z

I feel it's a bit clunky

jaihindhreddy 2019-09-21T15:09:18.008700Z

@dharrigan Maybe this?

(defn legit-trip?
  [{{:keys [startLocation endLocation segments]} :tripData
    {:keys [id]} :device
    :as trip}]
  (and startLocation endLocation segments id
       (every? trip [:tenantId :id])
       (not (#{"BAD" "UNUSABLE"} (:accuracy trip)))))

jaihindhreddy 2019-09-21T15:09:37.009100Z

Your fn seems to be a predicate

jaihindhreddy 2019-09-21T15:10:13.009900Z

But if you want the trip to be returned in the truthy case (for use with keep maybe), then you can wrap the and expr in an if and return it.

dharrigan 2019-09-21T15:10:30.010200Z

nice, thank you - definitely looks sweeter 🙂

jaihindhreddy 2019-09-21T15:12:34.011100Z

Both these versions return truthy even if :accuracy isn't present in trip. Is that intentional?

jaihindhreddy 2019-09-21T15:20:51.012700Z

@dharrigan An alternative version, if the prev. one has too much destructuring for your taste 😄

(defn legit-trip?
  [trip]
  (and (not (some #(nil? (get-in trip %))
               [[:id]
                [:tenantId]
                [:device :id]
                [:tripData :startLocation]
                [:tripData :endLocation]
                [:tripData :segments]]))
       (not (#{"BAD" "UNUSABLE"} (:accuracy trip)))))

dharrigan 2019-09-21T15:24:43.013200Z

ah, that was an oversight, if accuracy is not present, it should be false

dharrigan 2019-09-21T15:25:22.013900Z

I always um and ah about destructuring in function arguments - sometimes I like, sometimes...not so sure 🙂

jaihindhreddy 2019-09-21T15:50:06.015900Z

@dharrigan A little destructuring is probably best. Here's one with "a little" destructuring

(defn legit-trip?
  [{:keys [tripData device] :as trip}]
  (not (or (some #(nil? (% trip)) [:id :accuracy :tenantId])
           (some #(nil? (% tripData)) [:startLocation :endLocation :segments])
           (nil? (:id device))
           (#{"BAD" "UNUSABLE"} (:accuracy trip)))))

jaihindhreddy 2019-09-21T15:50:25.016300Z

I'll stop tagging you now. Sorry if noise 😅

dharrigan 2019-09-21T15:58:58.016700Z

It's okay - really appreciate helpful feedback, I like to learn 🙂

💯 1
dharrigan 2019-09-21T15:59:02.016900Z

Thanks and have a nice day!

👍 2