Category: Collections-Sequenceable
Superclass: Collection
My instances represent collections of objects that are ordered. I provide some access and manipulation methods.

Method category index

instance creation (class)
basic (instance)
comparing (instance)
concatenating (instance)
copying SequenceableCollections (instance)
enumerating (instance)
manipulation (instance)
replacing items (instance)
sorting (instance)
still unclassified (instance)
testing (instance)
testing collections (instance)

instance creation (class)

join: aCollection separatedBy: sepCollection
Where aCollection is a collection of SequenceableCollections, answer a new instance with all the elements therein, in order, each separated by an occurrence of sepCollection.

top


basic (instance)

after: oldObject
Return the element after oldObject. Error if oldObject not found or if no following object is available

allButFirst

Answer a copy of the receiver without the first object.

allButFirst: n

Answer a copy of the receiver without the first n objects.

allButLast

Answer a copy of the receiver without the last object.

allButLast: n

Answer a copy of the receiver without the last n objects.

at: anIndex ifAbsent: aBlock

Answer the anIndex-th item of the collection, or evaluate aBlock and answer the result if the index is out of range

atAll: keyCollection

Answer a collection of the same kind returned by #collect:, that only includes the values at the given indices. Fail if any of the values in keyCollection is out of bounds for the receiver.

atAll: aCollection put: anObject

Put anObject at every index contained in aCollection

atAllPut: anObject

Put anObject at every index in the receiver

atRandom

Return a random item of the receiver.

before: oldObject

Return the element before oldObject. Error if oldObject not found or if no preceding object is available

first

Answer the first item in the receiver

first: n

Answer the first n items in the receiver

fourth

Answer the fourth item in the receiver

identityIncludes: anObject

Answer whether we include the anObject object

identityIndexOf: anElement

Answer the index of the first occurrence of an object identical to anElement in the receiver. Answer 0 if no item is found

identityIndexOf: anElement ifAbsent: exceptionBlock

Answer the index of the first occurrence of an object identical to anElement in the receiver. Invoke exceptionBlock and answer its result if no item is found

identityIndexOf: anElement startingAt: anIndex

Answer the first index > anIndex which contains an object identical to anElement. Answer 0 if no item is found

identityIndexOf: anObject startingAt: anIndex ifAbsent: exceptionBlock

Answer the first index > anIndex which contains an object exactly identical to anObject. Invoke exceptionBlock and answer its result if no item is found

identityIndexOfLast: anElement ifAbsent: exceptionBlock

Answer the last index which contains an object identical to anElement. Invoke exceptionBlock and answer its result if no item is found

includes: anObject

Answer whether we include anObject

indexOf: anElement

Answer the index of the first occurrence of anElement in the receiver. Answer 0 if no item is found

indexOf: anElement ifAbsent: exceptionBlock

Answer the index of the first occurrence of anElement in the receiver. Invoke exceptionBlock and answer its result if no item is found

indexOf: anElement startingAt: anIndex

Answer the first index > anIndex which contains anElement. Answer 0 if no item is found

indexOf: anElement startingAt: anIndex ifAbsent: exceptionBlock

Answer the first index > anIndex which contains anElement. Invoke exceptionBlock and answer its result if no item is found

indexOfLast: anElement ifAbsent: exceptionBlock

Answer the last index which contains anElement. Invoke exceptionBlock and answer its result if no item is found

indexOfSubCollection: aSubCollection

Answer the first index > anIndex at which starts a sequence of items matching aSubCollection. Answer 0 if no such sequence is found.

indexOfSubCollection: aSubCollection ifAbsent: exceptionBlock

Answer the first index > anIndex at which starts a sequence of items matching aSubCollection. Answer 0 if no such sequence is found.

indexOfSubCollection: aSubCollection startingAt: anIndex

Answer the first index > anIndex at which starts a sequence of items matching aSubCollection. Answer 0 if no such sequence is found.

indexOfSubCollection: aSubCollection startingAt: anIndex ifAbsent: exceptionBlock

Answer the first index > anIndex at which starts a sequence of items matching aSubCollection. Invoke exceptionBlock and answer its result if no such sequence is found

last

Answer the last item in the receiver

last: n

Answer the last n items in the receiver

second

Answer the second item in the receiver

third

Answer the third item in the receiver

top


comparing (instance)

endsWith: aSequenceableCollection
Returns true if the receiver ends with the same characters as aSequenceableCollection.

startsWith: aSequenceableCollection

Returns true if the receiver starts with the same characters as aSequenceableCollection.

top


concatenating (instance)

join: sepCollection
Answer a new collection like my first element, with all the elements (in order) of all my elements (which should be collections) separated by sepCollection. I use my first element instead of myself as a prototype because my elements are more likely to share the desired properties than I am, such as in: #('hello,' 'world') join: ' ' => 'hello, world'

with: aSequenceableCollection

Return an Array with the same size as the receiver and aSequenceableCollection, each element of which is a 2-element Arrays including one element from the receiver and one from aSequenceableCollection.

with: seqColl1 with: seqColl2

Return an Array with the same size as the receiver and the arguments, each element of which is a 3-element Arrays including one element from the receiver and one from each argument.

with: seqColl1 with: seqColl2 with: seqColl3

Return an Array with the same size as the receiver and the arguments, each element of which is a 4-element Arrays including one element from the receiver and one from each argument.

top


copying SequenceableCollections (instance)

copyAfter: anObject
Answer a new collection holding all the elements of the receiver after the first occurrence of anObject, up to the last.

copyAfterLast: anObject

Answer a new collection holding all the elements of the receiver after the last occurrence of anObject, up to the last.

copyFrom: start

Answer a new collection containing all the items in the receiver from the start-th.

copyFrom: start to: stop

Answer a new collection containing all the items in the receiver from the start-th and to the stop-th

copyReplaceAll: oldSubCollection with: newSubCollection

Answer a new collection in which all the sequences matching oldSubCollection are replaced with newSubCollection

copyReplaceFrom: start to: stop with: replacementCollection

Answer a new collection of the same class as the receiver that contains the same elements as the receiver, in the same order, except for elements from index `start' to index `stop'. If start < stop, these are replaced by the contents of the replacementCollection. Instead, If start = (stop + 1), like in `copyReplaceFrom: 4 to: 3 with: anArray', then every element of the receiver will be present in the answered copy; the operation will be an append if stop is equal to the size of the receiver or, if it is not, an insert before index `start'.

copyReplaceFrom: start to: stop withObject: anObject

Answer a new collection of the same class as the receiver that contains the same elements as the receiver, in the same order, except for elements from index `start' to index `stop'. If start < stop, these are replaced by stop-start+1 copies of anObject. Instead, If start = (stop + 1), then every element of the receiver will be present in the answered copy; the operation will be an append if stop is equal to the size of the receiver or, if it is not, an insert before index `start'.

copyUpTo: anObject

Answer a new collection holding all the elements of the receiver from the first up to the first occurrence of anObject, excluded.

copyUpToLast: anObject

Answer a new collection holding all the elements of the receiver from the first up to the last occurrence of anObject, excluded.

copyWithFirst: anObject

Answer a new collection holding all the elements of the receiver after the first occurrence of anObject, up to the last.

top


enumerating (instance)

anyOne
Answer an unspecified element of the collection.

do: aBlock

Evaluate aBlock for all the elements in the sequenceable collection

do: aBlock separatedBy: sepBlock

Evaluate aBlock for all the elements in the sequenceable collection. Between each element, evaluate sepBlock without parameters.

doWithIndex: aBlock

Evaluate aBlock for all the elements in the sequenceable collection, passing the index of each element as the second parameter. This method is mantained for backwards compatibility and is not mandated by the ANSI standard; use #keysAndValuesDo:

findFirst: aBlock

Returns the index of the first element of the sequenceable collection for which aBlock returns true, or 0 if none

findLast: aBlock

Returns the index of the last element of the sequenceable collection for which aBlock returns true, or 0 if none does

fold: binaryBlock

First, pass to binaryBlock the first and second elements of the receiver; for each subsequent element, pass the result of the previous evaluation and an element. Answer the result of the last invocation, or the first element if the collection has size 1. Fail if the collection is empty.

from: startIndex to: stopIndex do: aBlock

Evaluate aBlock for all the elements in the sequenceable collection whose indices are in the range index to stopIndex

from: startIndex to: stopIndex doWithIndex: aBlock

Evaluate aBlock for all the elements in the sequenceable collection whose indices are in the range index to stopIndex, passing the index of each element as the second parameter. This method is mantained for backwards compatibility and is not mandated by the ANSI standard; use #from:to:keysAndValuesDo:

from: startIndex to: stopIndex keysAndValuesDo: aBlock

Evaluate aBlock for all the elements in the sequenceable collection whose indices are in the range index to stopIndex, passing the index of each element as the first parameter and the element as the second.

keys

Return an Interval corresponding to the valid indices in the receiver.

keysAndValuesDo: aBlock

Evaluate aBlock for all the elements in the sequenceable collection, passing the index of each element as the first parameter and the element as the second.

readStream

Answer a ReadStream streaming on the receiver

readWriteStream

Answer a ReadWriteStream which streams on the receiver

reverse

Answer the receivers' contents in reverse order

reverseDo: aBlock

Evaluate aBlock for all elements in the sequenceable collection, from the last to the first.

with: aSequenceableCollection collect: aBlock

Evaluate aBlock for each pair of elements took respectively from the receiver and from aSequenceableCollection; answer a collection of the same kind of the receiver, made with the block's return values. Fail if the receiver has not the same size as aSequenceableCollection.

with: aSequenceableCollection do: aBlock

Evaluate aBlock for each pair of elements took respectively from the receiver and from aSequenceableCollection. Fail if the receiver has not the same size as aSequenceableCollection.

top


manipulation (instance)

swap: anIndex with: anotherIndex
Swap the item at index anIndex with the item at index another index

top


replacing items (instance)

replaceAll: anObject with: anotherObject
In the receiver, replace every occurrence of anObject with anotherObject.

replaceFrom: start to: stop with: replacementCollection

Replace the items from start to stop with replacementCollection's items from 1 to stop-start+1 (in unexpected order if the collection is not sequenceable).

replaceFrom: start to: stop with: replacementCollection startingAt: repStart

Replace the items from start to stop with replacementCollection's items from repStart to repStart+stop-start

replaceFrom: anIndex to: stopIndex withObject: replacementObject

Replace every item from start to stop with replacementObject.

top


sorting (instance)

sort
Sort the contents of the receiver according to the default sort block, which uses #<= to compare items.

sort: sortBlock

Sort the contents of the receiver according to the given sort block, which accepts pair of items and returns true if the first item is less than the second one.

sorted

Return a copy of the receiver sorted according to the default sort block, which uses #<= to compare items.

sorted: sortBlock

Return a copy of the receiver sorted according to the given sort block, which accepts pair of items and returns true if the first item is less than the second one.

top


still unclassified (instance)

nextPutAllOn: aStream
Write all the objects in the receiver to aStream

top


testing (instance)

= aCollection
Answer whether the receiver's items match those in aCollection

examineOn: aStream

Print all the instance variables and context of the receiver on aStream

hash

Answer an hash value for the receiver

isSequenceable

Answer whether the receiver can be accessed by a numeric index with #at:/#at:put:.

top


testing collections (instance)

size
Answer a dummy size of 0, so that SequenceableCollection>>#do: works.

top