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


22.4 Searching with 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-for-all fun iter0 iter
Function: $iteration-thunk-for-all 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.

If all the applications of fun return true: the return value is #t. If an application of fun returns #f: the iteration stops immediately and the return value is #f.

(iteration-thunk-for-all
    even?
  (make-list-iteration-thunk '(2 4 5 6 8)))
⇒ #f

(iteration-thunk-for-all
    even?
  (make-list-iteration-thunk '(2 4 6 8)))
⇒ #t

(iteration-thunk-for-all
    =
  (make-list-iteration-thunk '(+1 +2 +3 +4))
  (make-list-iteration-thunk '(+1 +2 +3 +4))
  (make-list-iteration-thunk '(+1 +2 +3 +4)))
⇒ #t
Function: iteration-thunk-exists fun iter0 iter
Function: $iteration-thunk-exists 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.

If all the applications of fun return #f: the return value is #f. If an application of fun returns a non–#f value: the iteration stops immediately and the returned value is returned.

(iteration-thunk-exists
    even?
  (make-list-iteration-thunk '(1 3 5 7)))
⇒ #f

(iteration-thunk-exists
    even?
  (make-list-iteration-thunk '(1 3 4 5 7)))
⇒ #t

(iteration-thunk-exists
    =
  (make-list-iteration-thunk '(+1 +2 +3 +4))
  (make-list-iteration-thunk '(-1 -2 +3 -4))
  (make-list-iteration-thunk '( 0  0 +3  0)))a
⇒ #t
Function: iteration-thunk-find fun iter
Function: iteration-thunk-find fun iter not-found-handler
Function: $iteration-thunk-find fun iter not-found-handler

Apply fun to the items from the iteration thunk iter:

(iteration-thunk-find
    even?
  (make-list-iteration-thunk '(1 3 5 7)))
⇒ #f

(iteration-thunk-find
    even?
  (make-list-iteration-thunk '(1 3 5 7))
  (lambda () 'not-found))
⇒ not-found

(iteration-thunk-find
    even?
  (make-list-iteration-thunk '(1 3 4 5 7)))
⇒ 4

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