diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index 4e4841d55c..45b7fe3c78 100644 --- a/src/main/frontend/util.cljc +++ b/src/main/frontend/util.cljc @@ -27,7 +27,8 @@ [promesa.core :as p] [rum.core :as rum] [clojure.core.async :as async] - [cljs.core.async.impl.channels :refer [ManyToManyChannel]])) + [cljs.core.async.impl.channels :refer [ManyToManyChannel]] + [medley.core :as medley])) (:require [clojure.pprint] [clojure.string :as string] @@ -471,30 +472,16 @@ [s substr] (string/starts-with? s substr)) -(defn distinct-by - [f col] - (reduce - (fn [acc x] - (if (some #(= (f x) (f %)) acc) - acc - (vec (conj acc x)))) - [] - col)) -(defn distinct-by-last-wins - [f col] - (reduce - (fn [acc x] - (if (some #(= (f x) (f %)) acc) - (mapv - (fn [v] - (if (= (f x) (f v)) - x - v)) - acc) - (vec (conj acc x)))) - [] - col)) +#?(:cljs + (def distinct-by medley/distinct-by)) + +#?(:cljs + (defn distinct-by-last-wins + [f col] + (if (sequential? col) + (reverse (distinct-by f (reverse col))) + (distinct-by f col)))) (defn get-git-owner-and-repo [repo-url] @@ -1040,7 +1027,7 @@ #?(:clj (defmacro with-time - "Evaluates expr and prints the time it took. + "Evaluates expr and prints the time it took. Returns the value of expr and the spent time of float number in msecs." [expr] `(let [start# (cljs.core/system-time)