about summary refs log tree commit diff
path: root/configs
diff options
context:
space:
mode:
Diffstat (limited to 'configs')
-rw-r--r--configs/shared/.emacs.d/wpc/list.el14
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
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;