It is useful for implementing functionality, that is inherited by such classes as:
+ with :(int) nArgs,...Returns a new object with nArgs elements. For example,
creates a collection and adds anObject and otherObject to it. In a similar way, Set or SortCltn instances can be created like this.id aCltn = [OrdCltn with:2,anObject,otherObject];
This (factory) method has the same name as the instance method add: and can be used as follows, in circumstances when the user does not want to allocate a collection unless it is actually used :
Note: If aCltn is the same object as the receiver, a addYourself message is sent to the object.
Note: If aCltn is the same object as the receiver, it empties itself using emptyYourself and returns the receiver.
Evaluates noneBlock if there's no element for which aBlock evaluates to something that is non-nil, and returns the return value of that block. For example,
This message will return a subset of the receiver containing all elements for which testBlock evaluates to nil. For example,
Often, the Block would, as a side-effect, modify a variable, as in:
Typically the Block will modify the variable flag when some condition holds:
with:with:
+ with : firstObject with : nextObject
This method is equivalent to with: 2,firstObject,nextObject.
add:
+ add : firstObject
This method is equivalent to with: 1,firstObject.
This shows that creation of the collection is delayed until it is actually needed. If the collection already exists, objects are simply added, using the instance method add:.
aCltn = [ (aCltn)?aCltn:OrdCltn add:myObject ];
includesAllOf:
- (BOOL) includesAllOf : aCltn
Answer whether all the elements of aCltn are in the receiver, by sending includes: for each individual element.
includesAnyOf:
- (BOOL) includesAnyOf : aCltn
Answer whether any element of aCltn is in the receiver, by sending includes: for each individual element.
addAll:
- addAll : aCltn
Adds each member of aCltn to the receiver. If aCltn is nil, no action is taken. The argument aCltn need not be a collection, so long as it responds to eachElement in the same way as collections do. Returns the receiver.
addContentsOf:
- addContentsOf : aCltn
This method is equivalent to addAll: and is provided for Stepstone ICpak101 compatibility.
addContentsTo:
- addContentsTo : aCltn
This method is equivalent to addAll:, but with argument and receiver interchanged, and is provided for Stepstone ICpak101 compatibility.
removeAll:
- removeAll : aCltn
Removes all of the members of aCltn from the receiver. The argument aCltn need not be a collection, as long as it responds to eachElement as collections do. Returns the receiver.
removeContentsFrom:
- removeContentsFrom : aCltn
This method is equivalent to removeAll:, and is provided for compatibility with Stepstone ICpak101.
removeContentsOf:
- removeContentsOf : aCltn
This method is equivalent to removeAll:, and is provided for compatibility with Stepstone ICpak101.
asSet
- asSet
Creates a Set instance and adds the contents of the object to the set.
asOrdCltn
- asOrdCltn
Creates a OrdCltn instance and adds the contents of the object to the set.
detect:
- detect : aBlock
This message returns the first element in the receiver for which aBlock evaluates to something that is non-nil . For example, the following :
Returns nil if there's no element for which aBlock evaluates to something that non-nil.
[ aCltn detect: { :each | [each isEqual:anObject] } ];
detect:ifNone:
- detect : aBlock ifNone : noneBlock
This message returns the first element in the receiver for which aBlock evaluates to something that is non-nil.
[ aCltn detect: { :e | [e isEqual:anObject]} ifNone: {anObject} ];
select:
- select : testBlock
This message will return a subset of the receiver containing all elements for which testBlock evaluates to an Object that is non-nil. For example,
Returns a new empty instance of the same class as the receiver, if there's no element for which testBlock evaluates to something that is non-nil.
[ aCltn select: { :each | [each isEqual:anObject] } ];
reject:
- reject : testBlock
Complement of select:
Returns a new empty instance of the same class as the receiver, if there's no element for which testBlock evaluates to nil.
[ aCltn reject: { :each | [each isEqual:anObject] } ];
collect:
- collect : transformBlock
This message creates and returns a new collection of the same size and type as the receiver. The elements are the result of performing transformBlock on each element in the receiver (elements for which the Block would return nil are filtered out).
count:
- (unsigned) count : aBlock
Evaluate aBlock with each of the receiver's elements as the argument. Return the number that answered a non-nil value.
elementsPerform:
- elementsPerform :(SEL) aSelector
Send aSelector to all objects in the collection, starting from the object at offset 0. For Stepstone compatibility. Producer uses this.
elementsPerform:with:
- elementsPerform :(SEL) aSelector with : anObject
Send aSelector to all objects in the collection, starting from the object at offset 0. For Stepstone compatibility. Producer uses this.
elementsPerform:with:with:
- elementsPerform :(SEL) aSelector with : anObject with : otherObject
Send aSelector to all objects in the collection, starting from the object at offset 0. For Stepstone compatibility. Producer uses this.
elementsPerform:with:with:with:
- elementsPerform :(SEL) aSelector with : anObject with : otherObject with : thirdObj
Send aSelector to all objects in the collection, starting from the object at offset 0. For Stepstone compatibility. ICpak201 uses this.
do:
- do : aBlock
Evaluates aBlock for each element in the collection and returns self. aBlock must be a block taking one object (element) as argument; the return value of the block is ignored by this method.
int count = 0;
[contents do: { :what | if (what == anObject) count++; }];
do:until:
- do : aBlock until :(BOOL*) flag
Evaluates aBlock for each element in the collection, or until the variable pointed to by flag becomes true, and returns self. aBlock must be a block taking one object (element) as argument; the return value of the block is ignored by this method.
BOOL found = NO;
[contents do:{ :what | if (what == findObject) found=YES;} until:&found];
if (found) { ... }