Next: , Previous: , Up: deques   [Index]


38.4 Folding over deques

The following syntactic bindings are exported by the library (vicare containers deques). The syntactic bindings whose name is prefixed with $ are unsafe operations: they do not validate their arguments before accessing them.

Function: deque-fold-left kons knil deque
Function: $deque-fold-left kons knil deque

Analogous to fold-left for lists. Fold the procedure kons over the objects from deque, starting from the front.

(define D
  (deque 0 1 2 3 4 5))

(deque-fold-left (lambda (knil obj)
                   (cons obj knil))
  '() D)
⇒ (5 4 3 2 1 0)
Function: deque-fold-right kons knil deque
Function: $deque-fold-right kons knil deque

Analogous to fold-right for lists. Fold the procedure kons over the objects from deque, starting from the rear.

(define D
  (deque 0 1 2 3 4 5))

(deque-fold-right (lambda (obj knil)
                    (cons obj knil))
  '() D)
⇒ (0 1 2 3 4 5)