code-reviews

danieroux 2019-11-28T18:57:37.037200Z

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

2019-12-02T14:04:35.038300Z

do you want to recursively dedupe or just one pass?

2019-12-02T14:07:13.038500Z

you can use partitionand mapcat

2019-12-02T14:07:36.038700Z

(def r (range 1 10))
(->> r (partition 2 2) 
       (mapcat (fn [[a b]] ;;apply haversine here
                  (if ( < a 5) [a b] [b]))))

2019-12-02T14:08:49.039Z

but if [a b c d] are all close , this will generate [a c] or similar, not [a]

2019-12-03T14:37:52.039200Z

I would name f something more meaningful. Except this, the function looks right.

2019-12-03T15:33:24.039500Z

I would also rename xf to rf