|
Iterators, filters, mappers, convertorsThere are many operations common to all collections. Perhaps the most important are those that can apply a block to each element of a collection. The basic iterator is do:. It takes a block (or anything that responds to value:With:) as argument, and sends it value:With: with each element and key of the collection. (For unordered collections, the key has little meaning. Note that blocks in Self can take fewer arguments that supplied, so the key can be ignored.) Browse traits collection and traits indexable for the complete set of iterators.The elements of a collection can be mapped using a block as the mapping function, with the messages mapBy:, copyMappedBy: and mapBy:Into:. Collections can have elements filtered from them using a block as a predicate; the messages are filterBy:, copyFilteredBy: and filterBy:Into:. Searching iterators are provided too, such as findFirst:IfPresent:IfAbsent:. New collections can be created from the elements of an existing collections using asDictionary, asList, asSequence, asSet, etc. Two collections can be concatenated to form a new collection using the comma message (,).
|