Function: set:combinations

set:combinations is a byte-compiled function defined in set.el.

Signature

(set:combinations SET &optional ARITY)

Documentation

Return all possible combinations (subsets) of SET.

This includes the empty set and the SET itself. Assume SET is a valid set. With optional ARITY, return only subsets with ARITY members.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/set.el
(defun set:combinations (set &optional arity)
  "Return all possible combinations (subsets) of SET.
This includes the empty set and the SET itself.  Assume SET is a
valid set.  With optional ARITY, return only subsets with ARITY
members."
  (cond ((null arity)
	 (setq arity 0)
	 (cons nil (apply #'nconc (mapcar (lambda (_elt) (setq arity (1+ arity)) (set:combinations set arity))
					 set))))
	((= arity 1) set)
	((<= arity 0) '(nil))
	(t (let ((rest) (ctr 1))
	     (apply
	      'nconc
	      (mapcar (lambda (first)
			(setq rest (nthcdr ctr set)
			      ctr (1+ ctr))
			(mapcar (lambda (elt)
				  (if (listp elt)
				      (cons first elt)
				    (list first elt)))
				(set:combinations rest (1- arity))))
		      set))))))