This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |