Last active
August 20, 2018 07:31
-
-
Save iyahoo/164406dbb730f935b8677cf3420dfe2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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