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


22.3 Maping 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-map acceptor fun iter0 iter
Function: $iteration-thunk-map acceptor fun iter0 iter

Apply fun to the items from the iteration thunks iter. When multiple iteration thunks are given: the iteration stops when one of the thunks returns the sentinel. The function acceptor is applied to the the results of the applications. The return value of the mapping form is the return value of the last application of acceptor; if the iteration thunk is empty: the return value is the sentinel.

(let ((ell '()))
  (iteration-thunk-map (lambda (rv)
                         (set-cons! ell rv)
                         ell)
    -
    (make-list-iteration-thunk '(0 1 2 3 4))))
⇒ (-4 -3 -2 -1 0)

(let ((ell '()))
  (iteration-thunk-map (lambda (rv)
                         (set-cons! ell rv)
                         ell)
    +
    (make-list-iteration-thunk '(0  1  2  3  4))
    (make-list-iteration-thunk '(0 10 20 30 40))))
⇒ (44 33 22 11 0)
Function: iteration-thunk-for-each fun iter0 iter
Function: $iteration-thunk-for-each fun iter0 iter

Apply fun to the items from the iteration thunks iter and discard the return values. When multiple iteration thunks are given: the iteration stops when one of the thunks returns the sentinel.

(receive-and-return (ell)
    '()
  (iteration-thunk-for-each
      (lambda (item)
        (set-cons! ell (- item)))
    (make-list-iteration-thunk '(0 1 2 3 4))))
⇒ (-4 -3 -2 -1 0)

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

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