This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-28
Channels
- # announcements (1)
- # babashka (9)
- # beginners (82)
- # calva (6)
- # cider (3)
- # clj-kondo (69)
- # cljdoc (4)
- # cljs-dev (10)
- # cljsrn (2)
- # clojure (74)
- # clojure-europe (11)
- # clojure-italy (9)
- # clojure-nl (15)
- # clojure-spec (18)
- # clojure-uk (89)
- # code-reviews (8)
- # core-async (42)
- # cursive (22)
- # datomic (26)
- # fulcro (13)
- # graalvm (33)
- # graphql (1)
- # leiningen (20)
- # malli (19)
- # music (1)
- # off-topic (4)
- # pathom (56)
- # re-frame (3)
- # reitit (26)
- # shadow-cljs (40)
- # spacemacs (5)
- # tools-deps (25)
(defn boring-location [a b]
(< (haversine a b) 5))
(defn dedupe-if
([f]
(fn [xf]
(let [prev (volatile! ::none)]
(fn
([] (xf))
([result] (xf result))
([result input]
(let [prior @prev]
(if (and (not= ::none prior) (f prior input))
result
(do
(vreset! prev input)
(xf result input)))))))))
([f coll] (sequence (dedupe-if f) coll)))
(defn remove-boring-locations [locations]
(dedupe-if boring-location locations))
How do I write this better? locations
is a set of GPS coordinates. The intent is to dedupe
when an adjacent GPS coordinate is less than 5km’s away.Looks just fine to me. But dunno why dedupe-if
is being called with two args at the bottom there.
(def r (range 1 10))
(->> r (partition 2 2)
(mapcat (fn [[a b]] ;;apply haversine here
(if ( < a 5) [a b] [b]))))
I would name f
something more meaningful.
Except this, the function looks right.
I would also rename xf
to rf