copy distinct-by to graph-parser

pull/7779/head
rcmerci 2022-12-20 15:00:12 +08:00
parent db7975d09f
commit 1790223ed6
2 changed files with 14 additions and 5 deletions

View File

@ -8,8 +8,7 @@
;; stubbed in nbb
com.lambdaisland/glogi {:mvn/version "1.1.144"}
;; built in to nbb
cljs-bean/cljs-bean {:mvn/version "1.5.0"}
medley/medley {:mvn/version "1.4.0"}}
cljs-bean/cljs-bean {:mvn/version "1.5.0"}}
:aliases
;; This runs tests with nodejs. Would be nice to run this with in a browser env

View File

@ -5,7 +5,6 @@
[clojure.edn :as edn]
[clojure.string :as string]
[clojure.walk :as walk]
[medley.core :as medley]
[logseq.graph-parser.log :as log]))
(defn safe-decode-uri-component
@ -158,9 +157,20 @@
(map string/capitalize)
(string/join " ")))
(defn distinct-by
[f col]
(medley/distinct-by f (seq col)))
"Copy from medley"
[f coll]
(let [step (fn step [xs seen]
(lazy-seq
((fn [[x :as xs] seen]
(when-let [s (seq xs)]
(let [fx (f x)]
(if (contains? seen fx)
(recur (rest s) seen)
(cons x (step (rest s) (conj seen fx)))))))
xs seen)))]
(step (seq coll) #{})))
(defn normalize-format
[format]