Skip to content

Instantly share code, notes, and snippets.

@iyahoo
Last active August 20, 2018 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iyahoo/164406dbb730f935b8677cf3420dfe2f to your computer and use it in GitHub Desktop.
Save iyahoo/164406dbb730f935b8677cf3420dfe2f to your computer and use it in GitHub Desktop.
(defn remove-duplicate-with-test [test coll]
(loop [new-coll [] src coll]
(if-let [first-element (first src)]
(recur (conj new-coll first-element)
(remove #(test first-element %) src))
new-coll)))
;; (remove-duplicate-with-test = [1 2 3 4 3 2 1])
;; ;=> [1 2 3 4]
;; (remove-duplicate-with-test #(= (:hoge %1) (:hoge %2))
;; [{:hoge 1 :fuga 2} {:hoge 1 :fuga 3} {:hoge 2 :fuga 1} {:hoge 2 :fuga 4}])
;; ;=> [{:hoge 1, :fuga 2} {:hoge 2, :fuga 1}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment