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 of the steps subdivisions (default: 100) between min and max. If not provided, min and max default to the smallest and largest value in the collection, respectively. If there are any values outside this range, it posts a note.

See also: Collection: -plotHisto.

.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

.asPenFunction

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SVGFile/extVarious-SVGFile.sc

.asPerformDict( ... methods)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Extensions/Collection/extCollection-asPerformDict.sc

.asSMPTE(fps)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SMPTE/extVarious-asSMPTE.sc

.asSVGPath

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SVGFile/extVarious-SVGFile.sc

.asSVGPathSegment

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SVGFile/extVarious-SVGFile.sc

.asSVGTransform

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SVGFile/extVarious-SVGFile.sc

.atPercent(index: 0.5, interpol: true)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.case(default)

.clipPath

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SVGFile/extVarious-SVGFile.sc

.clumpSubsequent(delta: 1)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Extensions/Collection/extCollection-histDo.sc

.collectAs(function, class)

.collectMsg(selector ... args)

.debug(caller)

From extension in /SuperCollider/Contents/Resources/SCClassLibrary/Common/Core/debug.sc

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

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

.detectAll(function)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Extensions/Collection/extCollection-detectAll.sc

.detectIndexMsg(selector ... args)

.detectMsg(selector ... args)

.doMsg(selector ... args)

.downSize(n: 1)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Extensions/Collection/extCollection-firstIfSizeIsOne.sc

.dumpAll

.fillPath

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SVGFile/extVarious-SVGFile.sc

.firstIfSizeIsOne

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Extensions/Collection/extCollection-firstIfSizeIsOne.sc

.flatSize

.geoMean

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.harmMean

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.hash

.histDo(function)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Extensions/Collection/extCollection-histDo.sc

.histoBands(steps, min, max, center: 0.5)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extHisto.sc

.isAssociationArray

.isCollection

.kurtosis(mean)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.lastForWhich(function)

.lastIndexForWhich(function)

.makeEnvirValPairs

.mapToCantor

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/various/isCantorNumber.sc

.maxValue(function)

.mean(function)

.meanF(function)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.median2

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.minValue(function)

.notEmpty

.percentile(percent: [ 0.25, 0.5, 0.75 ], interpol: true)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.plotHisto(steps: 100, min, max)

From extension in /SuperCollider/Contents/Resources/SCClassLibrary/Common/GUI/PlusGUI/Math/PlotView.sc

.printAll(before, after)

.printcsAll

.product(function)

.rejectAs(function, class)

.rejectMsg(selector ... args)

.repeatLast(n: 1)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Extensions/Collection/extCollection-firstIfSizeIsOne.sc

.selectAs(function, class)

.selectMsg(selector ... args)

.skew(mean)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.skewPop(mean)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.species

.stdDev(mean)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.stdDevPop(mean)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.strokePath

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SVGFile/extVarious-SVGFile.sc

.sumF(function)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.sumabs

.transformFromRect(rect, fromRect, keepRatio: false, ratio: 1, move: 0.5)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-transformToRect.sc

.transformToRect(rect, fromRect, keepRatio: false, ratio: 1, move: 0.5)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-transformToRect.sc

.trimedian(interpol: true)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.variance(mean)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.variancePop(mean)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc

.writeDef(file)

.writeDefOld(file)

From extension in /SuperCollider/Contents/Resources/SCClassLibrary/Common/Audio/SynthDefOld.sc

.writeInputSpec(file, synthDef)

.writeInputSpecOld(file, synthDef)

From extension in /SuperCollider/Contents/Resources/SCClassLibrary/Common/Audio/SynthDefOld.sc

.zTable(mean, stdDev)

From extension in /Library/Application Support/SuperCollider/downloaded-quarks/MathLib/classes/statistics/extStatistics.sc