every

every <iterable> <block>

Test whether a predicate holds for every element of an iterable.

Arguments

Returns

A booltrue 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