Imagine that you need to select some values, and for each of them you should evaluate the block. On the other hand, if there is no value that satisfies the condition, it is necessary to evaluate another block.
Example:
Consider the following method signature:
forPositivesOf: aCollection do: aBlock otherwise: defaultBlock
This method should evaluate the block aBlock
with each positive element aCollection
, but if there are no such elements, evaluate defaultBlock
. Note that in fact, a method can calculate something more complicated than just positive numbers, and instead of aCollection, there can be a very complex object.
source
share