chickadee » srfi-197 » chain-and

(chain-and <initial-value> [<placeholder>] <step> ...)procedure

A variant of chain that short-circuits and returns #f if any step returns #f. chain-and is to chain as SRFI 2 and-let* is to let*.

<initial-value> is an expression. <placeholder> is a literal symbol; this is the placeholder symbol. If <placeholder> is not present, the placeholder symbol is _.

The syntax of <step> is (<datum> ... [<_> <datum> ...]), where <_> is the placeholder symbol.

Each <step> is evaluated as an application. If the step evaluates to #f, the remaining steps are not evaluated, and chain-and returns #f. Otherwise, the return value of the step is passed to the next step as its pipeline value. <initial-value> is the pipeline value of the first step. If no step evaluates to #f, the return value of chain-and is the return value of the last step.

The <_> placeholder in each <step> is replaced with that step's pipeline value. If a <step> does not contain <_>, it will ignore its pipeline value, but chain-and will still check whether that pipeline value is #f.

Because chain-and checks the return value of each step, it does not support steps with multiple return values. It is an error if a step returns more than one value.