ABSOLUTE BEGINNER
Your First anySatisfy: in Squeak
Ask whether at least one item in a list passes a test.
STEP 1
Ask one number
Start with one yes-or-no question: is seven greater than five?
7 > 5
Change 7 to 2 and print false.
STEP 2
Ask about a list
The list tries the rule on its items. Only one item needs to pass.
#(1 7 3) anySatisfy: [:n | n > 5]
Try 6 in place of 7. It still prints true.
STEP 3
Try a list with no match
None of the numbers is greater than five, so the answer is false.
#(1 2 3) anySatisfy: [:n | n > 5]
Change 3 to 8; the answer changes to true.
STEP 4
Try the empty list
No item can pass when the list is empty.
#() anySatisfy: [:n | n > 5]
Add just 9 to the empty list and try again.
STEP 5
Ask about words
The rule can ask about words too. Rabbit has more than four letters, so the result is true.
#('cat' 'rabbit' 'ox') anySatisfy: [:word | word size > 4]
Remove 'rabbit' and print it again.
YOU DID IT
A small step. A real result.
anySatisfy: answers true if at least one item passes your test. Otherwise it answers false.
Optional code download: open it as text and copy one example into Workspace.