Support list/dedupe-adjacent

Support a function to deduplicate adjacent elements in a list.

Also tracks additional work with TODOs.
This commit is contained in:
William Carroll 2020-01-16 01:16:58 +00:00
parent 438ff66eed
commit 50f0bd3dad

View file

@ -177,6 +177,20 @@ Be leery of using this with things like alists. Many data structures in Elisp
"Return t if X is in XS using `equal'."
(-contains? xs x))
;; TODO: Support dedupe.
;; TODO: Should we call this unique? Or distinct?
;; TODO: Add tests.
(defun list/dedupe-adjacent (xs)
"Return XS without adjacent duplicates."
(prelude/assert (not (list/empty? xs)))
(list/reduce (list (list/first xs))
(lambda (x acc)
(if (equal x (list/first acc))
acc
(list/cons x acc)))
xs))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Tests
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;