Skip to content

Instantly share code, notes, and snippets.

(defun iterator-from-combos (&rest lists)
"Takes a set of lists, and returns an iterator that iterates through every
possible combo of values where each value is from the list passed at its
index."
(if (contains nil lists) ;; If any of the passed lists are nil, no combos can be made.
(lambda () (values nil t)) ;; There are no combos, return an empty iterator.
(labels ;; Otherwise, build the combos iterator.
((shift (lists base) ;; Shifts the set of lists down by one.
;; Returns two values, the new lists, and whether we have hit the end
(if (not lists) ;; If no lists have been passed, we are done shifting.
(defun iterator-from-combos (&rest lists)
"Takes a set of lists, and returns an iterator that iterates through every
possible combo of values where each value is from the list passed at its
index."
; If any of the passed lists are nil, no combos can be made.
(if (contains nil lists)
; There are no combos, return an empty iterator.
(lambda () (values nil t))
; Otherwise, build the combos iterator.
(labels