Collectors

  • All descendants of defaultBehavior respond to &, making a new collector list with the arg.

  • Collectors respond to & by appending the arg to the list

  • Collectors can be turned into collections using asSet, asList, asVector, etc.
     (1 & false & nil & İfooİ) asVector 

Collectors

A useful kind of object when building a collection is a collector. A collector is a node in a linked list of collectors.

All objects that inherit from defaultBehavior respond to the binary message & by making a new collector list containing the receiver and argument. Collectors respond to & by appending the argument to the list. Collector lists can be converted to the other kinds of collections using asList, asSequence, asSet, etc.

Hence, a convenient way to make a collection from literal objects is using collectors:

	
	(1 & false & nil & 'foo') asVector 
Because the & operation is fast, a collector is also a useful way of accumulating all the elements of a collection before actually constructing the collection.

[ Previous ] [ Index ] [ Next ]