Package: Collections and Sequenceable
Class: Array
Introduction
Environment: container
Array is a fixed-sized collection of elements accessed by integer indices.
It has the following common used methods:
size
return the size of the array.at:put:
set the element at the given index.at:
get the element at the given index.do:
iterate over the elements of the array.
Class Method
Category: instance creation
new
- answer a new empty array.new:
- answer a new array with specified size.
Instance Method
Category: accessing
add:
- Add an element to the end of the array.For example:
at:
- answer the element at the given index.The index is zero based.
at:put:
- Set the element at the given index.The index is zero based.
first
- answer the first element of the receiver.size
- answer the number of elements in the receiver.For example:
Category: combining
,
- Concatenate two arrays.For example:
Category: comparing
=
- answer whether the receiver sorts equally.
Category: converting
asList
- answer a list containing the elements of the receiver.asString
- Convert an array into a string by join them with ',' by default
Category: enumerating
allSatisfy:
- Evaluate aBlock with the elements of the receiver. If aBlock returns false for any element return false. Otherwise return true.For example:
collect:
- Evaluate the given block for each element of the receiver and return a new array with the results.For example:
count:
- Evaluate aBlock with each of the receiver's elements as the argument. Answer the number of elements that answered true.For example:
detect:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. Answer the first element for which aBlock evaluates to true.For example:
detect:ifFound:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. If some element evaluates aBlock to true, then cull this element into foundBlock and answer the result of this evaluation.For example:
detect:ifFound:ifNone:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. If some element evaluates aBlock to true, then cull this element into foundBlock and answer the result of this evaluation. If none evaluate to true, then evaluate exceptionBlockFor example:
detect:ifNone:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. Answer the first element for which aBlock evaluates to true, or answer the value in none block.For example:
do:
- Evaluate the given block for each element of the receiver.
Category: instance creation
new
- Create a new array object by copy current array.
Category: removing
remove:
- Removed the given element in the array and return the removed element.For example:
Only first matched element will be removed, please use
removeAll:
if you want to remove all matched elements.removeAll:
- Removed the given element in the array for all occurrences.For example:
Only first matched element will be removed, please use
removeAll:
if you want to remove all matched elements.removeAt:
- Remove the item at the specified position and return the removed item's value.The index is zero based.
For example:
removeDuplicates
- Answer a modified copy of sequence from which any element that matches another element occurring in sequence has been removed.For example:
Class: LinkedList
Introduction
Environment: container
I am a sequential collection where adjecent objects are linked. I can store any kind of objects that I will wrap into a Link.
It has the following common used methods:
size
return the size of the list.first
return the first element of the list.rest
return the rest of the list.at:
get the element at the given index.do:
iterate over the elements of the list.
For example:
Instance Method
Category: accessing
at:
- answer the element at the given index.at:put:
- Set the element at the given index.first
- answer the first element of the receiver.rest
- answer the rest of the receiver.size
- answer the number of elements in the receiver.
Category: converting
asString
- Convert a list into a string by join them with ',' by default
Category: enumerating
collect:
- Evaluate the given block for each element of the receiver and return a new list with the results.For example:
detect:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. Answer the first element for which aBlock evaluates to true.For example:
detect:ifFound:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. If some element evaluates aBlock to true, then cull this element into foundBlock and answer the result of this evaluation.For example:
detect:ifFound:ifNone:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. If some element evaluates aBlock to true, then cull this element into foundBlock and answer the result of this evaluation. If none evaluate to true, then evaluate exceptionBlockFor example:
detect:ifNone:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. Answer the first element for which aBlock evaluates to true, or answer the value in none block.For example:
do:
- Evaluate the given block for each element of the receiver.
Category: removing
removeDuplicates
- Answer a modified copy of sequence from which any element that matches another element occurring in sequence has been removed.For example:
Last updated