Collection:
Filter:
Classes | Collections

Collection : Object

Abstract superclass of all collections

Description

Collection is an abstract class. You do not create direct instances of Collection. There are many types of Collections including List, Array, Dictionary, Bag, Set, SortedList, etc. See Collections for a complete class tree.

Class Methods

Collection.newFrom(aCollection)

Creates a new Collection from another collection. This supports the interface for the method "as".

Collection.with( ... args)

Creates a new Collection from the args.

Collection.fill(size, function)

Creates a Collection of the given size, the elements of which are determined by evaluation the given function. The function is passed the index as an argument.

Arguments:

size

The size of the collection which is returned. If nil, it returns an empty collection. If an array of sizes is given, the resulting collection has the appropriate dimensions (see: *fillND).

function

The function which is called for each new element - the index is passed in as a first argument. The function be anything that responds to the message "value".

Collection.fill2D(rows, cols, function)

Creates a 2 dimensional Collection of the given sizes. The items are determined by evaluation of the supplied function. The function is passed row and column indexes as arguments. See J concepts in SC

Collection.fill3D(planes, rows, cols, function)

Creates a 3 dimensional Collection of the given sizes. The items are determined by evaluation of the supplied function. The function is passed plane, row and column indexes as arguments. See J concepts in SC

Collection.fillND(dimensions, function, args: [ ])

Creates a N dimensional Collection where N is the size of the array dimensions. The items are determined by evaluation of the supplied function. The function is passed N number of indexes as arguments. See J concepts in SC

Inherited class methods

Instance Methods

Accessing

.size

Answers the number of objects contained in the Collection.

.isEmpty

Answer whether the receiver contains no objects.

Adding and Removing

.add

Add anObject to the receiver.

.addAll(aCollection)

Add all items in aCollection to the receiver.

.remove

Remove anObject from the receiver. Answers the removed object.

.removeAll(list)

Remove all items in aCollection from the receiver.

NOTE: that multiple items in the receiver will not necessarily be removed

See -removeEvery for a related method that removes all occurrences.

.removeEvery(list)

Remove all occurrences of the items in aCollection from the receiver.

.removeAllSuchThat(function)

Remove all items in the receiver for which function answers True. The function is passed two arguments, the item and an integer index. Answers the objects which have been removed.

.putEach(keys, values)

Put the values in the corresponding indices given by keys. If one of the two argument arrays is longer then it will wrap.

.atAll(keys)

Return a collection of all the items for the keys.

Testing

.includes(item1)

Answer whether anObject is contained in the receiver.

.includesEqual(item1)

Answer whether anObject is contained in the receiver. In contrast to -includes this tests for equality - not identity.

.includesAny(aCollection)

Answer whether any item in aCollection is contained in the receiver.

.includesAll(aCollection)

Answer whether all items in aCollection are contained in the receiver.

.matchItem(item)

Returns True if this includes the item.

See also matchItem.

Iteration

.do

Evaluates function for each item in the collection. The function is passed two arguments, the item and an integer index.

.collect(function)

Answer a new collection which consists of the results of function evaluated for each item in the collection. The function is passed two arguments, the item and an integer index.

If you want to control what type of collection is returned, use -collectAs(function, class).

.select(function)

Answer a new collection which consists of all items in the receiver for which function answers True. The function is passed two arguments, the item and an integer index.

If you want to control what type of collection is returned, use -selectAs(function, class).

.reject(function)

Answer a new collection which consists of all items in the receiver for which function answers False. The function is passed two arguments, the item and an integer index.

If you want to control what type of collection is returned, use -rejectAs(function, class).

.detect(function)

Answer the first item in the receiver for which function answers True. The function is passed two arguments, the item and an integer index.

.detectIndex(function)

Similar to -detect but returns the index instead of the item itself.

.inject(thisValue, function)

In functional programming, the operation known as a left fold. inject takes an initial value and a function and combines the elements of the collection by applying the function to the accumulated value and an element from the collection starting from the first element in the collection. The function takes two arguments and returns the new value. The accumulated value is initialized to initialValue.

.injectr(thisValue, function)

In functional programming, the operation known as a right fold. inject takes an initial value and a function and combines the elements of the collection by applying the function to the accumulated value and an element from the collection starting from the last element in the collection. The function takes two arguments and returns the new value. The accumulated value is initialized to initialValue.

.collectInPlace(function)

Iterate over the collection and replace each item with a new one, returned by the function. This can be useful when one wants to aviod creating a new array in memory. In most cases, it is better to use -collect.

.collectCopy(func)

Like -collect, but the collection is copied before iteration. This is recommended wherever the function may change the collection itself.

.any(function)

Answer whether function answers True for any item in the receiver. The function is passed two arguments, the item and an integer index.

.every(function)

Answer whether function answers True for every item in the receiver. The function is passed two arguments, the item and an integer index.

.count(function)

Answer the number of items for which function answers True. The function is passed two arguments, the item and an integer index.

.occurrencesOf(obj)

Answer the number of items in the receiver which are equal to anObject.

.sum(function)

Answer the sum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index.

.maxItem(function)

Answer the maximum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index. If function is nil, then answer the maximum of all items in the receiver.

.minItem(function)

Answer the minimum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index. If function is nil, then answer the minimum of all items in the receiver.

.maxIndex(function)

Answer the index of the maximum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index. If function is nil, then answer the maximum of all items in the receiver.

.minIndex(function)

Answer the index of the minimum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index. If function is nil, then answer the minimum of all items in the receiver.

.maxSizeAtDepth(rank)

Returns the maximum size of all subcollections at a certain depth (dimension)

Arguments:

rank

The depth at which the size of the collection is measured

.maxDepth(max: 1)

Returns the maximum depth of all subcollections.

Arguments:

max

Internally used only.

.iter

Returns a Routine that returns the elements one by one.

Conversion

.asBag

Answer a Bag to which all items in the receiver have been added.

.asList

Answer a List to which all items in the receiver have been added.

.asSet

Answer a Set to which all items in the receiver have been added.

.asSortedList(function)

Answer a SortedList to which all items in the receiver have been added.

.asDict(mergeFunc, class)

Answer a corresponding dictionary. This is part of the Key Value Pairs interface.

Arguments:

mergeFunc

Use this function to decide what to do with duplicate keys.

class

The class of the dictionary to be returned. By default this is an IdentityDictionary.

.asAssociations(class)

Answer an array of Associations. If the first item of the list is already an associiation, return itself. This is part of the Key Value Pairs interface.

Arguments:

class

The class of the collection to be returned. By default this is an Array.

.asPairs(class)

Answer an array with alternating key value pairs, like [\freq, 1848, \amp, 0.2]. This is part of the Key Value Pairs interface.

Arguments:

class

The class of the collection to be returned. By default this is an Array.

.asEvent(mergeFunc)

Answer an Event: with the key value pairs. See Key Value Pairs.

.asDictWith(mergeFunc, class)

used internally by asDict.

.powerset

Returns all possible combinations of the collection's elements.

.flopDict(unbubble: true)

Takes a collection of dictionaries and returns a single dictionary with arrays of all dictionaries' elements. If unbubble is True (default), and if one element is singular, the array is replaced by this element.

.histo(steps: 100, min, max)

Returns a histogram of the collection by counting the number of values that fall into each slot of size (default: 100) subdivisions between min and max. If there are any values outside this range, it posts a note. If min or max is not given, the smallest (or largest value respectively) is used.

.invert(axis)

Subtractively invert a collection about a value (default: sum of minimal and maximum value). It can be used to invert a pitch list about a given axis.

Writing to streams

.printOn(stream)

Print a representation of the collection to a stream.

.storeOn(stream)

Write a compilable representation of the collection to a stream.

.printItemsOn(stream)

Print a comma separated compilable representation of the items in the collection to a stream.

.storeItemsOn(stream)

Write a comma separated compilable representation of the items in the collection to a stream.

Set specific operations

.sect(that)

Return the set theoretical intersection of this and that.

.union(that)

Return the set theoretical union of this and that.

.difference(that)

Return the set of all items which are elements of this, but not of that.

.symmetricDifference(that)

Return the set of all items which are not elements of both this and that. this -- that

.isSubsetOf(that)

Returns True if all elements of this are also elements of that

Inherited instance methods

Undocumented instance methods

++(collection)

==(aCollection)

@(index)

.asArray

.asCollection

.case(default)

.collectAs(function, class)

.collectMsg(selector ... args)

.debug(caller)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Core/debug.sc

.deepCollect(depth: 1, function, index: 0, rank: 0)

.deepDo(depth: 1, function, index: 0, rank: 0)

.detectIndexMsg(selector ... args)

.detectMsg(selector ... args)

.doMsg(selector ... args)

.dumpAll

.flatSize

.hash

.isAssociationArray

.isCollection

.lastForWhich(function)

.lastIndexForWhich(function)

.makeEnvirValPairs

.maxValue(function)

.mean(function)

.minValue(function)

.notEmpty

.plotHisto(steps: 100, min, max)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Math/PlotView.sc

.printAll(before, after)

.printcsAll

.product(function)

.rejectAs(function, class)

.rejectMsg(selector ... args)

.selectAs(function, class)

.selectMsg(selector ... args)

.species

.sumabs

.writeDef(file)

.writeDefOld(file)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Audio/SynthDefOld.sc

.writeInputSpec(file, synthDef)

.writeInputSpecOld(file, synthDef)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Audio/SynthDefOld.sc