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


35.8 Searching in chains

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

Function: chain-for-all-forwards fun chain0 chain
Function: $chain-for-all-forwards fun chain0 chain

Apply the procedure fun over the chain arguments; stop at the first application returning #f and return #f. If the iteration reaches the end of one argument: the last procedure application is performed in tail position, so its return value is the return value of the iteration; if one of the arguments is null: the return value is #t. The iteration starts from the link given as argument, then it proceeds in the forwards direction; the iteration stops when reaching the end of one of the chain arguments.

Function: chain-exists-forwards fun chain0 chain
Function: $chain-exists-forwards fun chain0 chain

Apply the procedure fun over the chain arguments; stop at the first application returning true and return the returned value. If the iteration reaches the end of one argument: the last procedure application is performed in tail position, so its return value is the return value of the iteration; if one of the arguments is null: the return value is #f. The iteration starts from the link given as argument, then it proceeds in the forwards direction; the iteration stops when reaching the end of one of the chain arguments.

Function: chain-find-forwards fun chain
Function: chain-find-forwards fun chain not-found-rv
Function: $chain-find-forwards fun chain not-found-rv

Apply the procedure fun to the objects in chain: stop at the first true value and return the object from chain that generated it.

When not-found-rv is not used: if all the applications return #f, the return value is #f.

When not-found-rv is used: if all the applications return #f, the return value is not-found-rv.

The iteration starts from the link given as argument, then it proceeds in the forwards direction; the iteration stops when reaching the end of one of the chain arguments.

(chain-find-forwards
    even?
  (chain 1 3 5 7)
  'not-found)
⇒ not-found

(chain-find-forwards
    even?
  (chain 1 3 5 7))
⇒ #f

(chain-find-forwards
    even?
  (chain 1 3 5 6 7)
  'not-found)
⇒ 6

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