collections.scm 586 B

12345678910111213141516
  1. (define-module (utils collections))
  2. (define-public make-reducer
  3. (lambda (col-next-unvisited col-rest-unvisited col-exhausted?)
  4. "Return a procedure, which goes through the collection. Currently this
  5. implementation has some assumptions, which are rather biased towards linked list
  6. like data structures."
  7. (lambda (col reduction-proc init)
  8. (let loop ([acc init] [remaining col])
  9. (cond
  10. [(col-exhausted? remaining) acc]
  11. [else
  12. (loop (reduction-proc acc (col-next-unvisited remaining))
  13. (col-rest-unvisited remaining))])))))