(setq result (cons elt result))))
(nreverse result)))
+(cl-defmethod seq-uniq ((sequence list) &optional testfn)
+ (let ((result nil))
+ (if (not testfn)
+ ;; Fast path.
+ (while sequence
+ (unless (member (car sequence) result)
+ (push (car sequence) result))
+ (pop sequence))
+ ;; Slower path.
+ (while sequence
+ (unless (seq-find (lambda (elem)
+ (funcall testfn elem (car sequence)))
+ result)
+ (push (car sequence) result))
+ (pop sequence)))
+ (nreverse result)))
+
(cl-defgeneric seq-mapcat (function sequence &optional type)
"Concatenate the result of applying FUNCTION to each element of SEQUENCE.
The result is a sequence of type TYPE, or a list if TYPE is nil."
(should (equal (seq-split seq 3)
'("012" "345" "678" "9")))))
+(ert-deftest test-seq-uniq-list ()
+ (let ((list '(1 2 3)))
+ (should (equal (seq-uniq (append list list)) '(1 2 3))))
+ (let ((list '(1 2 3 2 1)))
+ (should (equal (seq-uniq list) '(1 2 3))))
+ (let ((list (list (substring "1")
+ (substring "2")
+ (substring "3")
+ (substring "2")
+ (substring "1"))))
+ (should (equal (seq-uniq list) '("1" "2" "3")))
+ (should (equal (seq-uniq list #'eq) '("1" "2" "3" "2" "1")))))
+
(provide 'seq-tests)
;;; seq-tests.el ends here