about summary refs log tree commit diff
path: root/configs/shared
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-16T01·16+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-17T10·56+0000
commit50f0bd3dadf253edb7a043589263f08b3a3b1f10 (patch)
tree965e27f8df2fc389720079222f3f1c874cf9ac5c /configs/shared
parent438ff66eed6e698f206c5b5ac454fbb5eb3440b9 (diff)
Support list/dedupe-adjacent
Support a function to deduplicate adjacent elements in a list.

Also tracks additional work with TODOs.
Diffstat (limited to 'configs/shared')
-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
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;