Next: , Previous: , Up: iteration thunks   [Index]


22.2 Folding over iterators

The following syntactic bindings are exported by the library (vicare containers iteration-thunks). The syntactic bindings whose name is prefixed with ‘$’ are unsafe: they do not validate their arguments.

Function: iteration-thunk-fold kons knil iter0 iter
Function: $iteration-thunk-fold kons knil iter0 iter

Fold operation over the objects from the iteration thunks iter. When multiple iteration thunks are given: the iteration stops when one of the thunks returns the sentinel.

(define (xcons a b)
  (cons b a))

(iteration-thunk-fold xcons
  '()
  (make-list-iteration-thunk '(0 1 2 3 4)))
⇒ (4 3 2 1 0)

(receive-and-return (ell)
    '()
  (iteration-thunk-fold (lambda (knil item1 item2)
                          (set-cons! ell (+ knil item1 item2))
                          knil)
    0
    (make-list-iteration-thunk '(0  1  2  3  4))
    (make-list-iteration-thunk '(0 10 20 30 40))))
⇒ (44 33 22 11 0)