about summary refs log tree commit diff
path: root/configs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-23T14·51+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-23T14·51+0000
commit190d5e4406cafd9a6f832c294adc9bba9bd0f861 (patch)
treeac72c835bbc2cccb0192dcb71921eba343c8356c /configs
parentd7c52e4e64f38d5635b5974a0deed6ee7c91c3b2 (diff)
Support set/{super,sub}set
Define predicates for testing whether two sets are supersets or subsets.
Diffstat (limited to 'configs')
-rw-r--r--configs/shared/.emacs.d/wpc/set.el28
1 files changed, 28 insertions, 0 deletions
diff --git a/configs/shared/.emacs.d/wpc/set.el b/configs/shared/.emacs.d/wpc/set.el
index c77e2d0cd5f5..ff2db75d94ab 100644
--- a/configs/shared/.emacs.d/wpc/set.el
+++ b/configs/shared/.emacs.d/wpc/set.el
@@ -97,6 +97,16 @@
   "Return t if sets A and B have no shared members."
   (set/empty? (set/intersection a b)))
 
+(defun set/superset? (a b)
+  "Return t if set A contains all of the members of set B."
+  (->> b
+       set/to-list
+       (list/all? (lambda (x) (set/contains? x a)))))
+
+(defun set/subset? (a b)
+  "Return t if each member of set A is present in set B."
+  (set/superset? b a))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Tests
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -132,6 +142,24 @@
                          (->> '(1 1 2 2 3 3)
                               set/from-list
                               set/to-list)))
+  (let ((primary-colors (set/new "red" "green" "blue")))
+    ;; set/subset?
+    (prelude/refute
+     (set/subset? (set/new "black" "grey")
+                  primary-colors))
+    (prelude/assert
+     (set/subset? (set/new "red")
+                  primary-colors))
+    ;; set/superset?
+    (prelude/refute
+     (set/superset? primary-colors
+                    (set/new "black" "grey")))
+    (prelude/assert
+     (set/superset? primary-colors
+                    (set/new "red" "green" "blue")))
+    (prelude/assert
+     (set/superset? primary-colors
+                    (set/new "red" "blue"))))
   ;; set/empty?
   (prelude/assert (set/empty? (set/new)))
   (prelude/refute (set/empty? (set/new 1 2 3)))