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


37.4 Folding over queues

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

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

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

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

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

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

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

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