List:
Filter:
Classes | Collections > Ordered

List : SequenceableCollection : Collection : Object

list of items of variable size
Source: List.sc

Description

List is a subclass of SequenceableCollection with unlimited growth in size. Although not a subclass of Array or its superclass ArrayedCollection it uses an Array in its implementation and is in many cases interchangeable with one. (List implements many of the same methods as Array.)

Arrays have a fixed maximum size. If you add beyond that size a new Array is created and returned, but you must use an assignment statement or the new array will be lost. (See the Array helpfile.) List has no size limitation and is thus more flexible, but has slightly more overhead.

Many of List's methods are inherited from SequenceableCollection or Collection and are documented in those helpfiles.

Class Methods

List.new(size: 8)

Creates a List with the initial capacity given by size.

List.newClear(size: 0)

Creates a List with the initial capacity given by size and slots filled with nil.

List.copyInstance(aList)

Creates a List by copying aList's array variable.

List.newUsing(anArray)

Creates a List using anArray.

Inherited class methods

Instance Methods

.asArray

Returns a new Array based upon this List.

.array

.array = value

Returns the List's Array, allowing it to be manipulated directly. This should only be necessary for exotic manipulations not implemented in List or its superclasses.

.array

.array = value

Sets the List's Array.

.at(i)

Return the item at index.

.clipAt(i)

Same as -at, but values for index greater than the size of the List will be clipped to the last index.

.wrapAt(i)

Same as -at, but values for index greater than the size of the List will be wrapped around to 0.

.foldAt(i)

Same as -at, but values for index greater than the size of the List will be folded back.

.put(i, item)

Put item at index, replacing what is there.

.clipPut(i, item)

Same as -put, but values for index greater than the size of the List will be clipped to the last index.

.wrapPut(i, item)

Same as -put, but values for index greater than the size of the List will be wrapped around to 0.

.foldPut(i, item)

Same as -put, but values for index greater than the size of the List will be folded back.

.add(item)

Adds an item to the end of the List.

.addFirst(item)

Inserts the item at the beginning of the List.

.insert(index, item)

Inserts the item into the contents of the List at the indicated index.

.pop

Remove and return the last element of the List.

.grow(sizeIncrease)

Increase the size of the List by sizeIncrease number of slots.

.removeAt(index)

Remove and return the element at index, shrinking the size of the List.

.fill(item)

Inserts the item into the contents of the receiver, possibly returning a new collection.

NOTE: the difference between this and Collection's *fill.

.do(function)

Iterate over the elements in order, calling the function for each element. The function is passed two arguments, the element and an index.

.reverseDo(function)

Iterate over the elements in reverse order, calling the function for each element. The function is passed two arguments, the element and an index.

.pairsDo(function)

Calls function for each subsequent pair of elements in the List. The function is passed the two elements and an index.

.copyRange(start, end)

Return a new List which is a copy of the indexed slots of the receiver from start to end.

.copySeries(first, second, last)

Return a new List consisting of the values starting at first, then every step of the distance between first and second, up until last.

.putSeries(first, second, last, value)

Put value at every index starting at first, then every step of the distance between first and second, up until last.

.reverse

Return a new List whose elements are reversed.

.scramble

Returns a new List whose elements have been scrambled. The receiver is unchanged.

.mirror

Return a new List which is the receiver made into a palindrome. The receiver is unchanged.

.mirror1

Return a new List which is the receiver made into a palindrome with the last element removed. This is useful if the list will be repeated cyclically, the first element will not get played twice. The receiver is unchanged.

.mirror2

Return a new List which is the receiver concatenated with a reversal of itself. The center element is duplicated. The receiver is unchanged.

.stutter(n: 2)

Return a new List whose elements are repeated n times. The receiver is unchanged.

NOTE: It is recommended to use dupEach instead. This method is retained for backwards compatibility.

.dupEach(n: 2)

Return a new List whose elements are repeated n times. The receiver is unchanged.

.rotate(n: 1)

Return a new List whose elements are in rotated order. Negative n values rotate left, positive n values rotate right. The receiver is unchanged.

.pyramid(patternType: 1)

Return a new List whose elements have been reordered via one of 10 "counting" algorithms. The algorithms are numbered 1 through 10. Run the examples to see the algorithms.

.lace(length)

Returns a new List whose elements are interlaced sequences of the elements of the receiver's subcollections, up to size length. The receiver is unchanged.

.permute(nthPermutation)

Returns a new List whose elements are the nthPermutation of the elements of the receiver. The receiver is unchanged.

.wrapExtend(length)

Returns a new List whose elements are repeated sequences of the receiver, up to size length. The receiver is unchanged.

.foldExtend(length)

Same as -wrapExtend but the sequences fold back on the list elements.

.slide(windowLength: 3, stepSize: 1)

Return a new List whose elements are repeated subsequences from the receiver. Easier to demonstrate than explain.

.dump

Dump the List's Array.

.clear

Replace the List's Array with a new empty one.

Inherited instance methods

Undocumented instance methods

.asList

.copy

.doAdjacentPairs(function)

.first

.last

.setCollection(aColl)

.size

.swap(i, j)