aboutsummaryrefslogtreecommitdiff
path: root/pypi/utils.scm
blob: 88ec879caa7e4f0990e8afc0771e4fb0c55b28a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(define-module (pypi utils)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-69)
  #:use-module (guix packages)
  #:export (all-combinations))

; Combinatorics

(define (combinations lst len)
  (cond ((= len 0)
          '(()))
        ((null? lst)
          '())
        (else (append (map (lambda (rest) (cons (car lst) rest))
                           (combinations (cdr lst) (- len 1)))
                      (combinations (cdr lst) len)))))

(define (all-combinations lst)
  (apply
    append
    (map
      (lambda (len)
        (combinations lst len))
      (cdr (iota (+ 1 (length lst)))))))