![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
You can also send the collect:
message to any instance of a
collection class. The collect:
message answers with a new
collection instance in which the elements are the values produced by the
final statement in the argument block.
The following example illustrates. Each value in the ordered collection is
assigned, successively, to the element
variable. For each
assignment, 1 + element
is evaluated, producing an element of the
ordered collection produced by the collect:
message:
Workspace ((OrderedCollection new addFirst: 570; addFirst: 720; addFirst: 640; addFirst: 720; yourself) collect: [:element | 1 + element]) do: [:element | Transcript show: element printString; space]. Transcript 721 641 721 571