list-helpers.scm 745 B

123456789101112131415161718192021222324252627282930
  1. (library (list-helpers)
  2. (export conditionally-make-alist-of
  3. alist-to-query-params
  4. alist-keys)
  5. (import (rnrs base)
  6. (only (guile)
  7. lambda* λ
  8. string-join)))
  9. (define (conditionally-make-alist-of names vals)
  10. (cond [(null? names) '()]
  11. [(car vals)
  12. (cons (cons (car names) (car vals))
  13. (conditionally-make-alist-of (cdr names) (cdr vals)))]
  14. [else (conditionally-make-alist-of (cdr names) (cdr vals))]))
  15. (define (alist-to-query-params alist)
  16. (string-join (map (lambda (assoc)
  17. (string-append (car assoc) "=" (cdr assoc)))
  18. alist)
  19. "&"))
  20. (define (alist-keys alist)
  21. (map car alist))