every
every <iterable> <block>
Test whether a predicate holds for every element of an iterable.
Arguments
<iterable>— a list or any iterable. A bare string is not iterable; convert it first withwords.<block>— a block taking one parameter, declared inside the braces right after{, and bound to the current element on each pass. The block is the predicate; it must yield a bool.
Returns
A bool — true if the predicate yields true for every element, and
false as soon as it yields false for one. An empty iterable is
vacuously true.
Control flow
Inside the block, continue skips to the next element,
break stops the iteration early, and
return returns from the enclosing handler or def.
If the predicate yields anything other than a bool, the script stops with a run-time error.
Examples
after command (say) {
require [every [creatures $self] { <c> [ismob $c] }]
do "say Every creature here is a mobile."
}
The predicate [ismob $c] runs for each creature in the owner's room. The
require guard lets the handler proceed only when it
is true for all of them. In the debug world (only mobs in room 1) this
evaluates to true.
after command (say) {
do "say all empty? [every [list] { <x> [isnull $x] }]"
}
The list is empty, so [every ...] is vacuously true and the
mob says "all empty? true."
See also
some— true if the predicate holds for any element.select— keep the elements for which the predicate holds.each— run a block for its side effects across elements.- Blocks · Iterables and iterables · Control flow