some

some <iterable> <block>

Test whether a predicate holds for at least one element of an iterable.

Arguments

Returns

A booltrue as soon as the predicate yields true for some element, and false if it never does. An empty iterable yields false.

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 [some [creatures $self] { <c> [ismob $c] }]
  do "say There is a mobile in the room."
}

The predicate [ismob $c] runs over the creatures in the owner's room until one is a mobile. The require guard lets the handler proceed when at least one is. In the debug world this evaluates to true.

after command (say) {
  do "say any empty? [some [list] { <x> [isnull $x] }]"
}

The list is empty, so [some ...] is false and the mob says "any empty? false."

See also