about summary refs log tree commit diff
path: root/emacs/.emacs.d
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-02-08T15·53+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-02-08T15·55+0000
commit3f54dd8601ca7b484a42a8d2b1ee867201bcfccb (patch)
tree97d2bb88bce30373b25267424bf99f69c9ff4334 /emacs/.emacs.d
parent5ade510598e0104a103f0b8fe9ed84ad3c4b13dc (diff)
Support cycle/empty?
Add predicate for determining if a cycle contains items.

Updated cycle/{new,from-list} to support setting current-index to nil when a
consumer calls it with an empty list.
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r--emacs/.emacs.d/wpc/cycle.el28
1 files changed, 19 insertions, 9 deletions
diff --git a/emacs/.emacs.d/wpc/cycle.el b/emacs/.emacs.d/wpc/cycle.el
index 9475ddd99659..592de10e0de7 100644
--- a/emacs/.emacs.d/wpc/cycle.el
+++ b/emacs/.emacs.d/wpc/cycle.el
@@ -34,17 +34,19 @@
 (defconst cycle/enable-tests? t
   "When t, run the tests defined herein.")
 
-(defun cycle/new (&rest xs)
-  "Create an empty cycle."
-  (make-cycle :current-index 0
-              :previous-index nil
-              :xs xs))
-
 (defun cycle/from-list (xs)
   "Create a cycle from a list of `XS'."
-  (make-cycle :current-index 0
-              :previous-index nil
-              :xs xs))
+  (if (= 0 (length xs))
+      (make-cycle :current-index nil
+                  :previous-index nil
+                  :xs xs)
+    (make-cycle :current-index 0
+                :previous-index nil
+                :xs xs)))
+
+(defun cycle/new (&rest xs)
+  "Create a cycle with XS as the values."
+  (cycle/from-list xs))
 
 (defun cycle/to-list (xs)
   "Return the list representation of a cycle, XS."
@@ -135,6 +137,14 @@ underlying struct."
        cycle-xs
        (list/contains? x)))
 
+(defun cycle/empty? (xs)
+  "Return t if cycle XS has no elements."
+  (= 0 (length (cycle-xs xs))))
+
+(defun cycle/focused? (xs)
+  "Return t if cycle XS has a non-nil value for current-index."
+  (maybe/some? (cycle-current-index xs)))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Tests
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;