This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-21
Channels
- # announcements (1)
- # bangalore-clj (1)
- # beginners (5)
- # calva (20)
- # cider (5)
- # clj-kondo (6)
- # clojure-czech (1)
- # clojure-dev (22)
- # clojure-hk (5)
- # clojure-norway (9)
- # clojure-switzerland (1)
- # clojure-uk (22)
- # clojurescript (7)
- # code-reviews (26)
- # cursive (1)
- # data-science (1)
- # datomic (1)
- # emacs (1)
- # fulcro (24)
- # off-topic (43)
- # om (1)
- # pathom (5)
- # pedestal (1)
- # re-frame (9)
- # reagent (1)
- # shadow-cljs (1)
- # spacemacs (7)
- # sql (4)
- # xtdb (8)
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! 😄
I took a look at the code and it seems that you could get better performances using transducers.
I don't think that would make a significant difference? There's only 2 levels of lazy sequence.
It might be a great chance for me to learn about transducers. I'll give it a try. Thanks @U8MJBRSR5 , @U09LZR36F
@U7PQH43PS I recommend you this blog post serie on transducers: https://vincent.404.taipei/clojure/build-your-own-transducer-part1/
@U09LZR36F transducers remove all the cost of the laziness and also remove intermediate buffering as well. For a library, it is often desirable.
Appreciate! I came across your blog post just a while ago. Now is a good time to practice it 🙂
I submitted this issue https://github.com/dawran6/emoji/issues/6
Feel free to ask in #code-reviews if you have any question on transducers, remember to tag me.
Absolutely!
or tag me in the issue if needed (@green-coder)
(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 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.
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?
[trip]
(and (not (some #(nil? (get-in trip %))
[[:id]
[:tenantId]
[:device :id]
[:tripData :startLocation]
[:tripData :endLocation]
[:tripData :segments]]))
(not (#{"BAD" "UNUSABLE"} (:accuracy trip)))))
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 😅
I took a look at the code and it seems that you could get better performances using transducers.