mirror of
https://github.com/logseq/logseq.git
synced 2026-05-25 05:04:24 +00:00
enhance: replace util/distinct-by
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user