diff options
author | William Carroll <wpcarro@gmail.com> | 2020-01-16T01·16+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-01-17T10·56+0000 |
commit | 50f0bd3dadf253edb7a043589263f08b3a3b1f10 (patch) | |
tree | 965e27f8df2fc389720079222f3f1c874cf9ac5c | |
parent | 438ff66eed6e698f206c5b5ac454fbb5eb3440b9 (diff) |
Support list/dedupe-adjacent
Support a function to deduplicate adjacent elements in a list. Also tracks additional work with TODOs.
-rw-r--r-- | configs/shared/.emacs.d/wpc/list.el | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/configs/shared/.emacs.d/wpc/list.el b/configs/shared/.emacs.d/wpc/list.el index bcab3df09cde..1ea5c18a7274 100644 --- a/configs/shared/.emacs.d/wpc/list.el +++ b/configs/shared/.emacs.d/wpc/list.el @@ -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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |