supernova: c++11 compile fixes
[supercollider.git] / Help / Collections / ArrayedCollection.html
blobac80718bdfa3e9bac75dfbbdc56e00ba6d4f977d
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.43">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0021e7}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
15 p.p6 {margin: 0.0px 0.0px 0.0px 42.0px; font: 12.0px Helvetica}
16 p.p7 {margin: 0.0px 0.0px 0.0px 42.0px; font: 12.0px Helvetica; min-height: 14.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 42.0px; font: 9.0px Monaco}
18 p.p9 {margin: 0.0px 0.0px 0.0px 42.0px; font: 12.0px Monaco; min-height: 16.0px}
19 p.p10 {margin: 0.0px 0.0px 0.0px 42.0px; font: 9.0px Monaco; min-height: 12.0px}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px}
21 p.p12 {margin: 0.0px 0.0px 0.0px 42.0px; font: 9.0px Monaco; color: #ad140d}
22 p.p13 {margin: 0.0px 0.0px 0.0px 42.0px; font: 9.0px Monaco; color: #2c7014}
23 p.p14 {margin: 0.0px 0.0px 0.0px 42.0px; font: 9.0px Monaco; color: #606060}
24 span.s1 {color: #000000}
25 span.s2 {color: #001bb9}
26 span.s3 {color: #2c7014}
27 span.s4 {color: #ad140d}
28 span.s5 {color: #606060}
29 span.s6 {text-decoration: underline}
30 span.Apple-tab-span {white-space:pre}
31 </style>
32 </head>
33 <body>
34 <p class="p1"><b>ArrayedCollection</b></p>
35 <p class="p2"><br></p>
36 <p class="p3"><span class="s1"><b>Inherits from: </b><a href="../Core/Object.html"><b>Object</b></a><b> : </b><a href="Collection.html"><b>Collection</b></a></span><span class="s2"><b> :</b></span><span class="s1"><b> </b><a href="SequenceableCollection.html"><b>SequenceableCollection</b></a></span></p>
37 <p class="p2"><br></p>
38 <p class="p4">ArrayedCollection is an abstract class, a subclass of SequenceableCollections whose elements are held in a vector of slots. Instances of ArrayedCollection have a fixed maximum size beyond which they may not grow.</p>
39 <p class="p2"><br></p>
40 <p class="p4">Its principal subclasses are <a href="Array.html"><span class="s2">Array</span></a> (for holding objects), and <a href="RawArray.html"><span class="s2">RawArray</span></a>, from which <a href="Int8Array.html"><span class="s2">Int8Array</span></a>, <a href="FloatArray.html"><span class="s2">FloatArray</span></a>, <a href="Signal.html"><span class="s2">Signal</span></a> etc. inherit.</p>
41 <p class="p2"><br></p>
42 <p class="p2"><br></p>
43 <p class="p5"><b><i>Class Methods</i></b></p>
44 <p class="p2"><br></p>
45 <p class="p4"><b>*with(... args)</b></p>
46 <p class="p6">Create a new ArrayedCollection whose slots are filled with the given arguments.</p>
47 <p class="p7"><br></p>
48 <p class="p8"><span class="s2">Array</span>.with(7, <span class="s3">'eight'</span>,<span class="Apple-converted-space">  </span>9).postln;</p>
49 <p class="p7"><br></p>
50 <p class="p4"><b>*series(size, start, step)</b></p>
51 <p class="p6">Fill an ArrayedCollection with an arithmetic series.</p>
52 <p class="p7"><br></p>
53 <p class="p8"><span class="s2">Array</span>.series(5, 10, 2).postln;</p>
54 <p class="p7"><br></p>
55 <p class="p4"><b>*geom(size, start, grow)</b></p>
56 <p class="p6">Fill an ArrayedCollection with a geometric series.</p>
57 <p class="p7"><br></p>
58 <p class="p8"><span class="s2">Array</span>.geom(5, 1, 3).postln;</p>
59 <p class="p9"><br></p>
60 <p class="p4"><b>*iota(...sizes)</b></p>
61 <p class="p6">Fills an ArrayedCollection with a counter. See <a href="../Language/J_concepts_in_SC.html"><span class="s2">J_concepts_in_SC</span></a> for more examples.</p>
62 <p class="p7"><br></p>
63 <p class="p8"><span class="s2">Array</span>.iota(2, 3);</p>
64 <p class="p8"><span class="s2">Array</span>.iota(2, 3, 4);</p>
65 <p class="p9"><br></p>
66 <p class="p4"><b>*fill2D(rows, cols, function)</b></p>
67 <p class="p6">Creates a 2 dimensional ArrayedCollection 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 <a href="../Language/J_concepts_in_SC.html"><span class="s2">J_concepts_in_SC</span></a></p>
68 <p class="p7"><br></p>
69 <p class="p8"><span class="s2">Array</span>.fill2D(2, 4, 0);</p>
70 <p class="p8"><span class="s2">Array</span>.fill2D(3, 4, { <span class="s2">arg</span> r, c; r*c+c; });</p>
71 <p class="p9"><br></p>
72 <p class="p4"><b>*fill3D(planes, rows, cols, function)</b></p>
73 <p class="p6">Creates a 3 dimensional ArrayedCollection 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 <a href="../Language/J_concepts_in_SC.html"><span class="s2">J_concepts_in_SC</span></a></p>
74 <p class="p7"><br></p>
75 <p class="p8"><span class="s2">Array</span>.fill3D(2, 3, 4, { <span class="s2">arg</span> p, r, c; p; });</p>
76 <p class="p10"><br></p>
77 <p class="p4"><b>*fillND(dimensions, function)</b></p>
78 <p class="p6">Creates a N dimensional ArrayedCollection where N is the size of the array <b>dimensions</b>. The items are determined by evaluation of the supplied function. The function is passed N number of indexes as arguments.</p>
79 <p class="p10"><br></p>
80 <p class="p8"><span class="s2">Array</span>.fillND([4, 4], { <span class="s2">arg</span> a, b; a+b; });<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">//2d</span></p>
81 <p class="p8"><span class="s2">Array</span>.fillND([4, 4, 4], { <span class="s2">arg</span> a, b, c; a+b*c; });<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">//3d</span></p>
82 <p class="p8"><span class="s2">Array</span>.fillND([1, 2, 3, 4], { <span class="s2">arg</span> a, b, c, d; b+d; });<span class="Apple-tab-span"> </span><span class="s4">//4d</span></p>
83 <p class="p2"><br></p>
84 <p class="p2"><br></p>
85 <p class="p5"><b><i>Instance Methods</i></b></p>
86 <p class="p11"><br></p>
87 <p class="p4"><b>size</b></p>
88 <p class="p6">Return the number of elements the ArrayedCollection.</p>
89 <p class="p7"><br></p>
90 <p class="p4"><b>maxSize</b></p>
91 <p class="p6">Return the maximum number of elements the ArrayedCollection can hold. For example, <a href="Array.html"><span class="s2">Array</span></a>s may initialise themselves with a larger capacity than the number of elements added.</p>
92 <p class="p7"><br></p>
93 <p class="p8">[4, 5, 6].maxSize; <span class="s4">// gosh</span></p>
94 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
95 <p class="p4"><b>at(index)</b></p>
96 <p class="p6">Return the <b>item</b> at <b>index</b>.</p>
97 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
98 <p class="p4"><b>clipAt(index)</b></p>
99 <p class="p6">Same as <b>at</b>, but values for <b>index</b> greater than the size of the ArrayedCollection will be clipped to the last index.</p>
100 <p class="p7"><br></p>
101 <p class="p8">y = [ 1, 2, 3 ];</p>
102 <p class="p8">y.clipAt(13).postln;</p>
103 <p class="p7"><span class="Apple-converted-space"> </span></p>
104 <p class="p4"><b>wrapAt(index)</b></p>
105 <p class="p6">Same as <b>at</b>, but values for <b>index</b> greater than the size of the ArrayedCollection will be wrapped around to 0.</p>
106 <p class="p7"><br></p>
107 <p class="p8">y = [ 1, 2, 3 ];</p>
108 <p class="p12"><span class="s1">y.wrapAt(3).postln; </span>// this returns the value at index 0</p>
109 <p class="p12"><span class="s1">y.wrapAt(4).postln; </span>// this returns the value at index 1</p>
110 <p class="p7"><br></p>
111 <p class="p4"><b>foldAt(index)</b></p>
112 <p class="p6">Same as <b>at</b>, but values for <b>index</b> greater than the size of the ArrayedCollection will be folded back.</p>
113 <p class="p7"><br></p>
114 <p class="p8">y = [ 1, 2, 3 ];</p>
115 <p class="p12"><span class="s1">y.foldAt(3).postln; </span>// this returns the value at index 1</p>
116 <p class="p12"><span class="s1">y.foldAt(4).postln; </span>// this returns the value at index 0</p>
117 <p class="p12"><span class="s1">y.foldAt(5).postln; </span>// this returns the value at index 1</p>
118 <p class="p7"><br></p>
119 <p class="p4"><b>plot</b></p>
120 <p class="p6">Plot data in a GUI window. See <a href="../GUI/GUI-Tools/plot.html"><span class="s2">plot</span></a> for more details.</p>
121 <p class="p7"><br></p>
122 <p class="p4"><b>swap(i, j)</b></p>
123 <p class="p6">Swap the values at indices i and j.</p>
124 <p class="p7"><br></p>
125 <p class="p8">[ 1, 2, 3 ].swap(0, 2).postln;</p>
126 <p class="p7"><br></p>
127 <p class="p4"><b>put(index, item)</b></p>
128 <p class="p6">Put <b>item</b> at <b>index</b>, replacing what is there.</p>
129 <p class="p7"><br></p>
130 <p class="p4"><b>clipPut(index, item)</b></p>
131 <p class="p6">Same as <b>put</b>, but values for <b>index</b> greater than the size of the ArrayedCollection will be clipped to the last index.</p>
132 <p class="p7"><span class="Apple-converted-space"> </span></p>
133 <p class="p4"><b>wrapPut(index, item)</b></p>
134 <p class="p6">Same as <b>put</b>, but values for <b>index</b> greater than the size of the ArrayedCollection will be wrapped around to 0.</p>
135 <p class="p7"><br></p>
136 <p class="p4"><b>foldPut(index)</b></p>
137 <p class="p6">Same as <b>put</b>, but values for <b>index</b> greater than the size of the ArrayedCollection will be folded back.</p>
138 <p class="p7"><br></p>
139 <p class="p4"><b>putEach(keys, values)</b></p>
140 <p class="p6">Put the <b>values</b> in the corresponding indices given by <b>keys</b>. If one of the two argument arrays is longer then it will wrap.</p>
141 <p class="p7"><br></p>
142 <p class="p8">y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];</p>
143 <p class="p8">y.putEach([4, 7], [<span class="s3">\smelly</span>, <span class="s3">\head</span>])</p>
144 <p class="p8">y.putEach([2, 3, 5, 6], <span class="s3">\wotsits</span>);</p>
145 <p class="p7"><br></p>
146 <p class="p4"><b>indexOf(item)</b></p>
147 <p class="p6">Return the first index containing an item which matches <b>item</b>.</p>
148 <p class="p7"><br></p>
149 <p class="p13"><span class="s1">y = [ </span>\the<span class="s1">, </span>\symbol<span class="s1">, </span>\collection<span class="s1">, </span>\contains<span class="s1">, </span>\my<span class="s1">, </span>\symbol<span class="s1"> ];<span class="Apple-converted-space"> </span></span></p>
150 <p class="p8">y.indexOf(<span class="s3">\symbol</span>);<span class="Apple-converted-space"> </span></p>
151 <p class="p7"><br></p>
152 <p class="p4"><b>includes(item)</b></p>
153 <p class="p6">Return a boolean indicating whether the collection contains anything matching <b>item</b>.</p>
154 <p class="p7"><br></p>
155 <p class="p13"><span class="s1">y = [ </span>\the<span class="s1">, </span>\symbol<span class="s1">, </span>\collection<span class="s1">, </span>\contains<span class="s1">, </span>\my<span class="s1">, </span>\symbol<span class="s1"> ];<span class="Apple-converted-space"> </span></span></p>
156 <p class="p8">y.includes(<span class="s3">\symbol</span>);<span class="Apple-converted-space"> </span></p>
157 <p class="p8">y.includes(<span class="s3">\solipsism</span>);<span class="Apple-converted-space"> </span></p>
158 <p class="p7"><br></p>
159 <p class="p4"><b>indexOfGreaterThan(item)</b></p>
160 <p class="p6">Return the first index containing an item which is greater than <b>item</b>.</p>
161 <p class="p7"><br></p>
162 <p class="p8">y = <span class="s2">List</span>[ 10, 5, 77, 55, 12, 123];<span class="Apple-converted-space"> </span></p>
163 <p class="p8">y.indexOfGreaterThan(70);<span class="Apple-converted-space"> </span></p>
164 <p class="p7"><br></p>
165 <p class="p4"><b>removeAt(index)</b></p>
166 <p class="p6">Remove and return the element at <b>index</b>, shrinking the size of the ArrayedCollection.</p>
167 <p class="p7"><br></p>
168 <p class="p8">y = [ 1, 2, 3 ];<span class="Apple-converted-space"> </span></p>
169 <p class="p8">y.removeAt(1);<span class="Apple-converted-space"> </span></p>
170 <p class="p8">y.postln;</p>
171 <p class="p7"><br></p>
172 <p class="p4"><b>takeAt(index)</b></p>
173 <p class="p6">Similar to <b>removeAt</b>, but does not maintain the order of the items following the one that was removed. Instead, the last item is placed into the position of the removed item and the array's size decreases by one.</p>
174 <p class="p9"><br></p>
175 <p class="p8">y = [ 1, 2, 3, 4, 5 ];<span class="Apple-converted-space"> </span></p>
176 <p class="p8">y.takeAt(1);<span class="Apple-converted-space"> </span></p>
177 <p class="p8">y.postln;</p>
178 <p class="p9"><br></p>
179 <p class="p4"><b>takeThese(function)</b></p>
180 <p class="p6">Removes all items in the receiver for which the <b>function</b> answers true. The function is passed two arguments, the item and an integer index. Note that order is not preserved. See <b>takeAt</b>.</p>
181 <p class="p9"><br></p>
182 <p class="p8">y = [ 1, 2, 3, 4 ];</p>
183 <p class="p8">y.takeThese({ <span class="s2">arg</span> item, index; item.odd; });<span class="Apple-tab-span"> </span><span class="s4">//remove odd items</span></p>
184 <p class="p8">y.postln;</p>
185 <p class="p9"><br></p>
186 <p class="p4"><b>add(item)</b></p>
187 <p class="p6">Adds an item to an ArrayedCollection if there is space. If there is not any space left in the object then this method returns a new ArrayedCollection. For this reason, you should always assign the result of add to a variable - never depend on add changing the receiver.</p>
188 <p class="p7"><br></p>
189 <p class="p8">(</p>
190 <p class="p12">// z and y are the same object</p>
191 <p class="p8"><span class="s2">var</span> y, z;</p>
192 <p class="p8">z = [1, 2, 3];</p>
193 <p class="p8">y = z.add(4);</p>
194 <p class="p8">z.postln;</p>
195 <p class="p8">y.postln;</p>
196 <p class="p8">)</p>
197 <p class="p9"><br></p>
198 <p class="p8">(</p>
199 <p class="p12">// in this case a new object is returned</p>
200 <p class="p8"><span class="s2">var</span> y, z;</p>
201 <p class="p8">z = [1, 2, 3, 4];</p>
202 <p class="p8">y = z.add(5);</p>
203 <p class="p8">z.postln;</p>
204 <p class="p8">y.postln;</p>
205 <p class="p8">)</p>
206 <p class="p9"><br></p>
207 <p class="p4"><b>addAll(aCollection)</b></p>
208 <p class="p6">Adds all the elements of aCollection to the contents of the receiver, possibly returning a new collection.</p>
209 <p class="p7"><br></p>
210 <p class="p8">(</p>
211 <p class="p12">// in this case a new object is returned</p>
212 <p class="p8"><span class="s2">var</span> y, z;</p>
213 <p class="p8">z = [1, 2, 3, 4];</p>
214 <p class="p8">y = z.addAll([7, 8, 9]);</p>
215 <p class="p8">z.postln;</p>
216 <p class="p8">y.postln;</p>
217 <p class="p8">)</p>
218 <p class="p7"><br></p>
219 <p class="p4"><b>extend(size, item)</b></p>
220 <p class="p6">Extends the receiver to match <b>size</b> by adding a number of <b>item</b>s. If <b>size</b> is less than receiver size then truncate.</p>
221 <p class="p7"><br></p>
222 <p class="p8">(</p>
223 <p class="p8"><span class="s2">var</span> y, z;</p>
224 <p class="p8">z = [1, 2, 3, 4];</p>
225 <p class="p12"><span class="s1">y = z.extend(10, 9);<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>//fill up with 9 until the size equals 10</p>
226 <p class="p8">z.postln;</p>
227 <p class="p8">y.postln;</p>
228 <p class="p8">)</p>
229 <p class="p7"><br></p>
230 <p class="p4"><b>fill(value)</b></p>
231 <p class="p6">Inserts the item into the contents of the receiver, possibly returning a new collection. Note the difference between this and Collection's *fill.</p>
232 <p class="p7"><br></p>
233 <p class="p8">(</p>
234 <p class="p8"><span class="s2">var</span> z;</p>
235 <p class="p8">z = <span class="s2">List</span>[1, 2, 3, 4];</p>
236 <p class="p8">z.fill(4).postln;</p>
237 <p class="p8">z.fill([1,2,3,4]).postln;</p>
238 <p class="p8">)</p>
239 <p class="p7"><br></p>
240 <p class="p4"><b>insert(index, item)</b></p>
241 <p class="p6">Inserts the item into the contents of the receiver, possibly returning a new collection.</p>
242 <p class="p7"><br></p>
243 <p class="p8">(</p>
244 <p class="p12">// in this case a new object is returned</p>
245 <p class="p8"><span class="s2">var</span> y, z;</p>
246 <p class="p8">z = [1, 2, 3, 4];</p>
247 <p class="p8">y = z.insert(1, 999);</p>
248 <p class="p8">z.postln;</p>
249 <p class="p8">y.postln;</p>
250 <p class="p8">)</p>
251 <p class="p9"><br></p>
252 <p class="p4"><b>addFirst(item)</b></p>
253 <p class="p6">Inserts the item before the contents of the receiver, possibly returning a new collection.</p>
254 <p class="p7"><br></p>
255 <p class="p8">(</p>
256 <p class="p12">// in this case a new object is returned</p>
257 <p class="p8"><span class="s2">var</span> y, z;</p>
258 <p class="p8">z = [1, 2, 3, 4];</p>
259 <p class="p8">y = z.addFirst(999);</p>
260 <p class="p8">z.postln;</p>
261 <p class="p8">y.postln;</p>
262 <p class="p8">)</p>
263 <p class="p9"><br></p>
264 <p class="p4"><b>pop</b></p>
265 <p class="p6">Remove and return the last element of the ArrayedCollection.</p>
266 <p class="p7"><br></p>
267 <p class="p8">(</p>
268 <p class="p8"><span class="s2">var</span> z;</p>
269 <p class="p8">z = [1, 2, 3, 4];</p>
270 <p class="p8">z.pop.postln;</p>
271 <p class="p8">z.postln;</p>
272 <p class="p8">)</p>
273 <p class="p7"><br></p>
274 <p class="p4"><b>grow(sizeIncrease)</b></p>
275 <p class="p6">Increase the size of the ArrayedCollection by <b>sizeIncrease </b>number of slots,<span class="Apple-converted-space">  </span>possibly returning a new collection.</p>
276 <p class="p7"><br></p>
277 <p class="p4"><b>growClear(sizeIncrease)</b></p>
278 <p class="p6">Increase the size of the ArrayedCollection by <b>sizeIncrease </b>number of slots,<span class="Apple-converted-space">  </span>returning a new collection with <a href="../Core/Nil.html"><span class="s2">nil</span></a>s in the added slots.</p>
279 <p class="p7"><br></p>
280 <p class="p12">// Compare:</p>
281 <p class="p8">[4,5,6].grow(5)</p>
282 <p class="p8">[4,5,6].growClear(5)</p>
283 <p class="p7"><br></p>
284 <p class="p4"><b>copyRange(start, end)</b></p>
285 <p class="p6">Return a new ArrayedCollection which is a copy of the indexed slots of the receiver from <b>start</b> to <b>end</b>.</p>
286 <p class="p6">x.copyRange(a, b) can also be written as <b>x[a..b]</b></p>
287 <p class="p9"><br></p>
288 <p class="p8">(</p>
289 <p class="p8"><span class="s2">var</span> y, z;</p>
290 <p class="p8">z = [1, 2, 3, 4, 5];</p>
291 <p class="p8">y = z.copyRange(1,3);</p>
292 <p class="p8">z.postln;</p>
293 <p class="p8">y.postln;</p>
294 <p class="p8">)</p>
295 <p class="p10"><br></p>
296 <p class="p4"><b>copySeries(first, second, last)</b></p>
297 <p class="p6">Return a new ArrayedCollection consisting of the values starting at <b>first</b>, then every step of the distance between <b>first</b> and <b>second</b>, up until <b>last</b>.</p>
298 <p class="p6">x.copySeries(a, b, c) can also be written as <b>x[a, b..c]</b></p>
299 <p class="p9"><br></p>
300 <p class="p8">(</p>
301 <p class="p8"><span class="s2">var</span> y, z;</p>
302 <p class="p8">z = [1, 2, 3, 4, 5, 6];</p>
303 <p class="p8">y = z.copySeries(0, 2, 5);</p>
304 <p class="p8">y.postln;</p>
305 <p class="p8">)</p>
306 <p class="p10"><br></p>
307 <p class="p4"><b>seriesFill(start, step)</b></p>
308 <p class="p6">Fill the receiver with an arithmetic progression. The first element will be <b>start</b>, the second <b>start + step</b>, the third <b>start + step + step</b> ...</p>
309 <p class="p9"><br></p>
310 <p class="p8">(</p>
311 <p class="p8"><span class="s2">var</span> y;</p>
312 <p class="p8">y = <span class="s2">Array</span>.newClear(15);</p>
313 <p class="p8">y.seriesFill(5, 3);</p>
314 <p class="p8">y.postln;</p>
315 <p class="p8">)</p>
316 <p class="p9"><br></p>
317 <p class="p4"><b>putSeries(first, second, last, value)</b></p>
318 <p class="p6">Put <b>value</b> at every index starting at <b>first</b>, then every step of the distance between <b>first</b> and <b>second</b>, up until <b>last</b>.</p>
319 <p class="p6">x.putSeries(a, b, c, val) can also be written as <b>x[a, b..c] = val</b></p>
320 <p class="p9"><br></p>
321 <p class="p8">(</p>
322 <p class="p8"><span class="s2">var</span> y, z;</p>
323 <p class="p8">z = [1, 2, 3, 4, 5, 6];</p>
324 <p class="p8">y = z.putSeries(0, 2, 5, <span class="s5">"foo"</span>);</p>
325 <p class="p8">y.postln;</p>
326 <p class="p8">)</p>
327 <p class="p9"><br></p>
328 <p class="p4"><b>++ aCollection</b></p>
329 <p class="p6">Concatenate the contents of the two collections into a new ArrayedCollection.</p>
330 <p class="p7"><br></p>
331 <p class="p8">(</p>
332 <p class="p8"><span class="s2">var</span> y, z;</p>
333 <p class="p8">z = [1, 2, 3, 4];</p>
334 <p class="p8">y = z ++ [7, 8, 9];</p>
335 <p class="p8">z.postln;</p>
336 <p class="p8">y.postln;</p>
337 <p class="p8">)</p>
338 <p class="p9"><br></p>
339 <p class="p4"><b>reverse</b></p>
340 <p class="p6">Return a new ArrayedCollection whose elements are reversed.</p>
341 <p class="p7"><br></p>
342 <p class="p8">(</p>
343 <p class="p8"><span class="s2">var</span> y, z;</p>
344 <p class="p8">z = [1, 2, 3, 4];</p>
345 <p class="p8">y = z.reverse;</p>
346 <p class="p8">z.postln;</p>
347 <p class="p8">y.postln;</p>
348 <p class="p8">)</p>
349 <p class="p9"><br></p>
350 <p class="p4"><b>do(function)</b></p>
351 <p class="p6">Iterate over the elements in order, calling the function for each element. The function is passed two arguments, the element and an index.</p>
352 <p class="p7"><br></p>
353 <p class="p8">[<span class="s3">'a'</span>, <span class="s3">'b'</span>, <span class="s3">'c'</span>].do({ <span class="s2">arg</span> item, i; [i, item].postln; });</p>
354 <p class="p9"><br></p>
355 <p class="p4"><b>reverseDo(function)</b></p>
356 <p class="p6">Iterate over the elements in reverse order, calling the function for each element. The function is passed two arguments, the element and an index.</p>
357 <p class="p7"><br></p>
358 <p class="p8">[<span class="s3">'a'</span>, <span class="s3">'b'</span>, <span class="s3">'c'</span>].reverseDo({ <span class="s2">arg</span> item, i; [i, item].postln; });</p>
359 <p class="p9"><br></p>
360 <p class="p4"><b>collect(function)</b></p>
361 <p class="p6">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. See <a href="Collection.html"><span class="s2">Collection</span></a> helpfile for examples.</p>
362 <p class="p7"><br></p>
363 <p class="p4"><b>deepCollect(depth, function)</b></p>
364 <p class="p6">The same as <b>collect</b>, but can look inside sub-arrays up to the specified <b>depth</b>.</p>
365 <p class="p7"><br></p>
366 <p class="p8">a = [99, [4,6,5], [[32]]];</p>
367 <p class="p8">a.deepCollect(1, {<span class="s2">|item|</span> item.isArray}).postln;</p>
368 <p class="p8">a.deepCollect(2, {<span class="s2">|item|</span> item.isArray}).postln;</p>
369 <p class="p8">a.deepCollect(3, {<span class="s2">|item|</span> item.isArray}).postln;</p>
370 <p class="p7"><br></p>
371 <p class="p4"><b>windex</b></p>
372 <p class="p6">Interprets the array as a list of probabilities which should sum to 1.0 and returns a random index value based on those probabilities.</p>
373 <p class="p9"><br></p>
374 <p class="p8">(</p>
375 <p class="p8"><span class="s2">Array</span>.fill(10, {</p>
376 <p class="p8"><span class="Apple-tab-span"> </span>[0.1, 0.6, 0.3].windex;</p>
377 <p class="p8">}).postln;</p>
378 <p class="p8">)</p>
379 <p class="p9"><br></p>
380 <p class="p4"><b>normalizeSum</b></p>
381 <p class="p6">Returns the Array resulting from :<span class="Apple-converted-space"> </span></p>
382 <p class="p7"><br></p>
383 <p class="p8">(<span class="s2">this</span> / <span class="s2">this</span>.sum)</p>
384 <p class="p9"><br></p>
385 <p class="p6">so that the array will sum to 1.0.</p>
386 <p class="p7"><br></p>
387 <p class="p6">This is useful for using with windex or wchoose.</p>
388 <p class="p9"><br></p>
389 <p class="p8">[1, 2, 3].normalizeSum.postln;</p>
390 <p class="p9"><br></p>
391 <p class="p4"><b>normalize(min, max)</b></p>
392 <p class="p6">Returns a new Array with the receiver items normalized between <b>min</b> and <b>max</b>.</p>
393 <p class="p9"><br></p>
394 <p class="p8">[1, 2, 3].normalize;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">//default min=0, max= 1</span></p>
395 <p class="p8">[1, 2, 3].normalize(-20, 10);</p>
396 <p class="p9"><br></p>
397 <p class="p4"><b>perfectShuffle</b></p>
398 <p class="p6">Returns a copy of the receiver with its items split into two equal halves, then reconstructed by interleaving the two halves. Note: use an even number of item pairs in order to not loose any items in the shuffle.</p>
399 <p class="p9"><br></p>
400 <p class="p8">(</p>
401 <p class="p8"><span class="s2">var</span> y, z;</p>
402 <p class="p8">z = [ 1, 2, 3, 4, 5, 6 ];</p>
403 <p class="p8">y = z.perfectShuffle;</p>
404 <p class="p8">z.postln;</p>
405 <p class="p8">y.postln;</p>
406 <p class="p8">)</p>
407 <p class="p9"><br></p>
408 <p class="p4"><b>performInPlace(selector, from, to, argList)</b></p>
409 <p class="p6">performs a method in place, within a certain region [from..to], returning the same array.</p>
410 <p class="p7"><br></p>
411 <p class="p8">a = (0..10);</p>
412 <p class="p8">a.performInPlace(<span class="s3">\normalizeSum</span>, 3, 6);<span class="Apple-converted-space"> </span></p>
413 <p class="p7"><br></p>
414 <p class="p4"><b>rank</b></p>
415 <p class="p6">Rank is the number of dimensions in a multidimensional array.</p>
416 <p class="p7"><br></p>
417 <p class="p8">a = [4,7,6,8];</p>
418 <p class="p8">a.rank;</p>
419 <p class="p8">a = [[4,7],[6,8]];</p>
420 <p class="p8">a.rank;</p>
421 <p class="p10"><br></p>
422 <p class="p4"><b>shape</b></p>
423 <p class="p6">For a multidimensional array, returns the number of elements along each dimension.</p>
424 <p class="p7"><br></p>
425 <p class="p8">a = [4,7,6,8];</p>
426 <p class="p8">a.shape;</p>
427 <p class="p8">a = [[4,7],[6,8]];</p>
428 <p class="p8">a.shape;</p>
429 <p class="p10"><br></p>
430 <p class="p4"><b>reshape( ... shape)</b></p>
431 <p class="p6">For a multidimensional array, rearranges the data using the desired number of elements along each dimension. The data may be extended using wrapExtend if needed.</p>
432 <p class="p7"><br></p>
433 <p class="p8">a = [4,7,6,8];</p>
434 <p class="p8">a.reshape(2,2);</p>
435 <p class="p8">a.reshape(2,3);</p>
436 <p class="p10"><br></p>
437 <p class="p4"><b>find(anotherArray)</b></p>
438 <p class="p6">finds the starting index of a number of elements contained in the array.</p>
439 <p class="p7"><br></p>
440 <p class="p8">a = (0..10);</p>
441 <p class="p8">a.find([4, 5, 6]);<span class="Apple-converted-space"> </span></p>
442 <p class="p10"><br></p>
443 <p class="p4"><b>replace(anotherArray)</b></p>
444 <p class="p6">return a new array in which a number of elements have been replaced by another<span class="Apple-converted-space"> </span></p>
445 <p class="p7"><br></p>
446 <p class="p8">a = (0..10) ++ (0..10);</p>
447 <p class="p8">a.replace([4, 5, 6], 100);<span class="Apple-converted-space"> </span></p>
448 <p class="p8">a.replace([4, 5, 6], [1734, 1985, 1860]);</p>
449 <p class="p10"><br></p>
450 <p class="p6">this method is inherited by <a href="String.html"><span class="s2">String</span></a>:</p>
451 <p class="p10"><br></p>
452 <p class="p14"><span class="s1">a = </span>"hello world"<span class="s1">;</span></p>
453 <p class="p8">a.replace(<span class="s5">"world"</span>, <span class="s5">"word"</span>);</p>
454 <p class="p10"><br></p>
455 <p class="p4"><b>asRandomTable</b></p>
456 <p class="p6">return an integral table that can be used to generate random numbers with a specified distribution.</p>
457 <p class="p6">(see<span class="s6"> [Randomness] </span>helpfile for a more detailed example)</p>
458 <p class="p7"><br></p>
459 <p class="p8">(</p>
460 <p class="p8">a = (0..100) ++ (100..50) / 100; <span class="s4">// distribution</span></p>
461 <p class="p8">a = a.asRandomTable;</p>
462 <p class="p8">)</p>
463 <p class="p10"><br></p>
464 <p class="p4"><b>tableRand</b></p>
465 <p class="p6">returns a new random number from a random table.</p>
466 <p class="p7"><br></p>
467 <p class="p8">(</p>
468 <p class="p8">a = (0..100) ++ (100..50) / 100; <span class="s4">// distribution</span></p>
469 <p class="p8">a = a.asRandomTable;</p>
470 <p class="p8">20.do { a.tableRand.postln };</p>
471 <p class="p8">)</p>
472 <p class="p10"><br></p>
473 <p class="p4"><b>msgSize</b></p>
474 <p class="p6">return the size of an osc message in bytes</p>
475 <p class="p7"><br></p>
476 <p class="p14"><span class="s1">a = [</span>"/s_new"<span class="s1">, </span>"default"<span class="s1">, -1, </span>"freq"<span class="s1">, 440];</span></p>
477 <p class="p8">a.msgSize;</p>
478 <p class="p7"><br></p>
479 <p class="p4"><b>bundleSize</b></p>
480 <p class="p6">return the size of an osc bundle in bytes</p>
481 <p class="p7"><br></p>
482 <p class="p14"><span class="s1">a = [[</span>"/s_new"<span class="s1">, </span>"default"<span class="s1">, -1, </span>"freq"<span class="s1">, 440], [</span>"/s_new"<span class="s1">, </span>"default"<span class="s1">, -1, </span>"freq"<span class="s1">, 220]];</span></p>
483 <p class="p8">a.bundleSize;</p>
484 <p class="p7"><br></p>
485 <p class="p4"><b>asciiPlot</b></p>
486 <p class="p6">For an ArrayedCollection containing numbers (e.g. audio data) this renders a plot in the post window using asterisks and spaces (works best if you use a monospace font in your post window).</p>
487 <p class="p7"><br></p>
488 <p class="p8">a = (0, pi/10 .. 5pi).collect{|val| val.sin}</p>
489 <p class="p8">a.asciiPlot;</p>
490 <p class="p7"><br></p>
491 </body>
492 </html>