enhance: replace util/distinct-by

This commit is contained in:
rcmerci
2022-12-19 23:06:23 +08:00
parent d188e28427
commit c4f3e44be1

View File

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