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:
parent
438ff66eed
commit
50f0bd3dad
1 changed files with 14 additions and 0 deletions
|
@ -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'."
|
"Return t if X is in XS using `equal'."
|
||||||
(-contains? xs x))
|
(-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
|
;; Tests
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
Loading…
Reference in a new issue