Fork me on GitHub
Daw-Ran Liou00:09:11

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

Vincent Cantin05:09:48

I took a look at the code and it seems that you could get better performances using transducers.

👍 4

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

Daw-Ran Liou14:09:01

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

Vincent Cantin15:09:14

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

Daw-Ran Liou15:09:27

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

😄 4
Vincent Cantin15:09:36

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

parrot 4
Vincent Cantin15:09:32

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


What would be a better way of doing this?


(defn filter-trip
   (= 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))


I feel it's a bit clunky


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


Your fn seems to be a predicate


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.


nice, thank you - definitely looks sweeter 🙂


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


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

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


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


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


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


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


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

💯 4

Thanks and have a nice day!

👍 8