supernova: fixes for boost-1.49 and gcc-4.7
[supercollider.git] / Help / Collections / Collection.html
blob4e5fe7b0b81ae52c3db7c0a950235091824ced69
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: 12.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: 14.0px Helvetica; min-height: 17.0px}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
14 p.p5 {margin: 0.0px 0.0px 0.0px 57.0px; font: 12.0px Helvetica}
15 p.p6 {margin: 0.0px 0.0px 0.0px 57.0px; font: 14.0px Helvetica; min-height: 17.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 57.0px; font: 9.0px Monaco}
17 p.p8 {margin: 0.0px 0.0px 0.0px 57.0px; font: 9.0px Monaco; color: #bf0000}
18 p.p9 {margin: 0.0px 0.0px 0.0px 57.0px; font: 9.0px Monaco; min-height: 12.0px}
19 p.p10 {margin: 0.0px 0.0px 0.0px 57.0px; font: 12.0px Helvetica; min-height: 14.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 57.0px; font: 9.0px Monaco; color: #2c7014}
22 p.p13 {margin: 0.0px 0.0px 0.0px 57.0px; font: 9.0px Monaco; color: #ad140d}
23 p.p14 {margin: 0.0px 0.0px 0.0px 57.0px; font: 9.0px Monaco; color: #000000}
24 p.p15 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
25 p.p16 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica}
26 p.p17 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica; min-height: 16.0px}
27 p.p18 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
28 span.s1 {font: 18.0px Helvetica}
29 span.s2 {color: #0021e7}
30 span.s3 {color: #001bb9}
31 span.s4 {color: #000000}
32 span.s5 {color: #0000bf}
33 span.s6 {color: #2c7014}
34 span.s7 {color: #007300}
35 span.s8 {color: #0000ff}
36 span.s9 {color: #ad140d}
37 span.Apple-tab-span {white-space:pre}
38 </style>
39 </head>
40 <body>
41 <p class="p1"><span class="s1"><b>Collection<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>group of objects</b></p>
42 <p class="p2"><br></p>
43 <p class="p1"><b>Inherits from: </b><a href="../Core/Object.html"><span class="s2"><b>Object</b></span></a></p>
44 <p class="p2"><br></p>
45 <p class="p1">Collections are groups of objects. See the <a href="Collections.html"><span class="s3">Collections</span></a> overview for a complete listing of all subclasses.</p>
46 <p class="p2"><br></p>
47 <p class="p1">Collection is an abstract class. You do not create direct instances of Collection.<span class="Apple-converted-space"> </span></p>
48 <p class="p1">There are many types of Collections including <a href="List.html"><span class="s3">List</span></a>, <a href="Array.html"><span class="s3">Array</span></a>, <a href="Dictionary.html"><span class="s3">Dictionary</span></a>, <a href="Bag.html"><span class="s3">Bag</span></a>, <a href="Set.html"><span class="s3">Set</span></a>, <a href="SortedList.html"><span class="s3">SortedList</span></a>, etc.<span class="Apple-converted-space"> </span></p>
49 <p class="p3"><br></p>
50 <p class="p4"><b>Class Methods:</b></p>
51 <p class="p3"><br></p>
52 <p class="p1"><b>*newFrom(collection)</b></p>
53 <p class="p5">Creates a new Collection from another collection. This supports the interface for the mathod "as"</p>
54 <p class="p6"><br></p>
55 <p class="p7"><span class="s3">Array</span>.newFrom(<span class="s3">Set</span>[4, 2, 1]);</p>
56 <p class="p7"><span class="s3">Set</span>.newFrom(<span class="s3">Array</span>[4, 2, 1]);</p>
57 <p class="p8"><span class="s4">[1, 2, 3, 4, 3, 2].as(</span><span class="s5">Set</span><span class="s4">); </span>// as(someClass) calls someClass.newFrom(this)</p>
58 <p class="p9"><br></p>
59 <p class="p3"><br></p>
60 <p class="p1"><b>*with(collection)</b></p>
61 <p class="p5">Creates a new Collection from the args.</p>
62 <p class="p6"><br></p>
63 <p class="p7"><span class="s3">Array</span>.with(4, 2, 1);</p>
64 <p class="p3"><br></p>
65 <p class="p1"><b>*fill(size, function)</b></p>
66 <p class="p5">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.</p>
67 <p class="p6"><br></p>
68 <p class="p7"><span class="s3">Array</span>.fill(4, { <span class="s3">arg</span> i; i * 2 });</p>
69 <p class="p3"><br></p>
70 <p class="p3"><br></p>
71 <p class="p4"><b>Accessing:</b></p>
72 <p class="p3"><br></p>
73 <p class="p1"><b>size</b></p>
74 <p class="p5">Answers the number of objects contained in the Collection.</p>
75 <p class="p10"><br></p>
76 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].size;</p>
77 <p class="p2"><br></p>
78 <p class="p1"><b>isEmpty</b></p>
79 <p class="p5">Answer whether the receiver contains no objects.</p>
80 <p class="p10"><br></p>
81 <p class="p7"><span class="s3">List</span>[].isEmpty;</p>
82 <p class="p11"><br></p>
83 <p class="p2"><br></p>
84 <p class="p4"><b>Adding and Removing:</b></p>
85 <p class="p2"><br></p>
86 <p class="p1"><b>add(anObject)</b></p>
87 <p class="p5">Add anObject to the receiver.</p>
88 <p class="p10"><br></p>
89 <p class="p7"><span class="s3">List</span>[1, 2].add(3);</p>
90 <p class="p2"><br></p>
91 <p class="p1"><b>addAll(aCollection)</b></p>
92 <p class="p5">Add all items in aCollection to the receiver.</p>
93 <p class="p10"><br></p>
94 <p class="p7"><span class="s3">List</span>[1, 2].addAll(<span class="s3">List</span>[3, 4]);</p>
95 <p class="p2"><br></p>
96 <p class="p1"><b>remove(anObject)</b></p>
97 <p class="p5">Remove anObject from the receiver. Answers the removed object.</p>
98 <p class="p10"><br></p>
99 <p class="p7">(</p>
100 <p class="p7"><span class="s3">var</span> a;</p>
101 <p class="p7">a = <span class="s3">List</span>[1, 2, 3, 4];</p>
102 <p class="p7">a.remove(3);</p>
103 <p class="p7">a;</p>
104 <p class="p7">)</p>
105 <p class="p2"><br></p>
106 <p class="p1"><b>removeAll(aCollection)</b></p>
107 <p class="p5">Remove all items in aCollection from the receiver.</p>
108 <p class="p10"><br></p>
109 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].removeAll(<span class="s3">List</span>[2, 3]);</p>
110 <p class="p10"><br></p>
111 <p class="p5">Note that multiple items in the receiver will not necessarily be removed:</p>
112 <p class="p10"><br></p>
113 <p class="p12"><span class="s4">~closet = [</span>\hat<span class="s4">, </span>\hat<span class="s4">, </span>\hat<span class="s4">, </span>\coat<span class="s4">, </span>\coat<span class="s4">, </span>\shoe<span class="s4">, </span>\shoe<span class="s4">];</span></p>
114 <p class="p13"><span class="s4">~closet.removeAll([</span><span class="s6">\hat</span><span class="s4">, </span><span class="s6">\coat</span><span class="s4">, </span><span class="s6">\shoe</span><span class="s4">, </span><span class="s6">\shoe</span><span class="s4">]); </span>// Doesn't empty the closet, just removes what we wanted to</p>
115 <p class="p10"><br></p>
116 <p class="p5">See removeEvery (below) for a related method that removes <i>all</i> occurrences.</p>
117 <p class="p2"><br></p>
118 <p class="p1"><b>removeEvery(aCollection)</b></p>
119 <p class="p5">Remove <b><i>all occurrences</i></b> of the items in aCollection from the receiver.</p>
120 <p class="p10"><br></p>
121 <p class="p7"><span class="s3">List</span>[1, 2, 3, 2, 3, 2, 3, 4].removeEvery(<span class="s3">List</span>[2, 3]);</p>
122 <p class="p2"><br></p>
123 <p class="p1"><b>removeAllSuchThat(function)</b></p>
124 <p class="p5">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.</p>
125 <p class="p10"><br></p>
126 <p class="p7">(</p>
127 <p class="p7"><span class="s3">var</span> a;</p>
128 <p class="p7">a = <span class="s3">List</span>[1, 2, 3, 4];</p>
129 <p class="p7">a.removeAllSuchThat({ <span class="s3">arg</span> item, i; item &lt; 3 });</p>
130 <p class="p7">a;</p>
131 <p class="p7">)</p>
132 <p class="p1"><b>putEach(keys, values)</b></p>
133 <p class="p5">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>
134 <p class="p10"><br></p>
135 <p class="p7">y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];</p>
136 <p class="p7">y.putEach([4, 7], [<span class="s6">\smelly</span>, <span class="s6">\head</span>])</p>
137 <p class="p7">y.putEach([2, 3, 5, 6], <span class="s6">\wotsits</span>);</p>
138 <p class="p2"><br></p>
139 <p class="p1"><b>atAll(keys)</b></p>
140 <p class="p5">return a collection of all the items for the keys.</p>
141 <p class="p10"><br></p>
142 <p class="p14">y = [<span class="s7">\a</span>, <span class="s7">\b</span>, <span class="s7">\c</span>];</p>
143 <p class="p7">y.atAll([0, 2])</p>
144 <p class="p2"><br></p>
145 <p class="p2"><br></p>
146 <p class="p4"><b>Testing:</b></p>
147 <p class="p2"><br></p>
148 <p class="p1"><b>includes(anObject)</b></p>
149 <p class="p5">Answer whether anObject is contained in the receiver.</p>
150 <p class="p10"><br></p>
151 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].includes(3);</p>
152 <p class="p2"><br></p>
153 <p class="p1"><b>includesAny(aCollection)</b></p>
154 <p class="p5">Answer whether any item in aCollection is contained in the receiver.</p>
155 <p class="p10"><br></p>
156 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].includesAny(<span class="s3">List</span>[4, 5]);</p>
157 <p class="p2"><br></p>
158 <p class="p1"><b>includesAll(aCollection)</b></p>
159 <p class="p5">Answer whether all items in aCollection are contained in the receiver.</p>
160 <p class="p10"><br></p>
161 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].includesAll(<span class="s3">List</span>[4, 5]);</p>
162 <p class="p2"><br></p>
163 <p class="p1"><b>matchItem(item)<span class="Apple-converted-space"> </span></b></p>
164 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>returns true if <b>this</b> inclueds the item.</p>
165 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>See also: <a href="../interfaces/matchItem.html"><span class="s8">matchItem</span></a></p>
166 <p class="p2"><br></p>
167 <p class="p2"><br></p>
168 <p class="p4"><b>Iteration:</b></p>
169 <p class="p2"><br></p>
170 <p class="p1"><b>do(function)</b></p>
171 <p class="p5">Evaluates function for each item in the collection. The function is passed two arguments, the item and an integer index.</p>
172 <p class="p10"><br></p>
173 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].do({ <span class="s3">arg</span> item, i; item.postln });</p>
174 <p class="p2"><br></p>
175 <p class="p1"><b>collect(function)</b></p>
176 <p class="p5">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.</p>
177 <p class="p10"><br></p>
178 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].collect({ <span class="s3">arg</span> item, i; item + 10 });</p>
179 <p class="p10"><br></p>
180 <p class="p5">If you want to control what type of collection is returned, use <b>collectAs(function, class)</b>.</p>
181 <p class="p2"><br></p>
182 <p class="p1"><b>select(function)</b></p>
183 <p class="p5">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.</p>
184 <p class="p10"><br></p>
185 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].select({ <span class="s3">arg</span> item, i; item.even });</p>
186 <p class="p10"><br></p>
187 <p class="p5">If you want to control what type of collection is returned, use <b>selectAs(function, class)</b>.</p>
188 <p class="p2"><br></p>
189 <p class="p1"><b>reject(function)</b></p>
190 <p class="p5">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.</p>
191 <p class="p10"><br></p>
192 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].reject({ <span class="s3">arg</span> item, i; item.even });</p>
193 <p class="p10"><br></p>
194 <p class="p5">If you want to control what type of collection is returned, use <b>rejectAs(function, class)</b>.</p>
195 <p class="p2"><br></p>
196 <p class="p1"><b>detect(function)</b></p>
197 <p class="p5">Answer the first item in the receiver for which function answers true.</p>
198 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
199 <p class="p10"><br></p>
200 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].detect({ <span class="s3">arg</span> item, i; item.even });</p>
201 <p class="p10"><br></p>
202 <p class="p1"><b>detectIndex(function)</b></p>
203 <p class="p5">Similar to detect but returns the index instead of the item itself.</p>
204 <p class="p10"><br></p>
205 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].detectIndex({ <span class="s3">arg</span> item, i; item.even });</p>
206 <p class="p2"><br></p>
207 <p class="p1"><b>inject(initialValue, function)</b></p>
208 <p class="p5">In functional programming, the operation known as a fold.</p>
209 <p class="p5">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. The function takes two arguments and returns the new value. The accumulated value is initialzed to initialValue.</p>
210 <p class="p10"><br></p>
211 <p class="p7">[1,2,3,4,5].inject(0, <span class="s3">_</span>+<span class="s3">_</span>); <span class="s9">// 15</span></p>
212 <p class="p9"><br></p>
213 <p class="p7">[1,2,3,4,5].inject(1, <span class="s3">_</span>*<span class="s3">_</span>); <span class="s9">// 120</span></p>
214 <p class="p9"><br></p>
215 <p class="p13">// same as .collect(_.squared)</p>
216 <p class="p7">[1,2,3,4,5].inject([], {<span class="s3">|a,b|</span> a ++ b.squared }); <span class="s9">// [ 1, 4, 9, 16, 25 ]</span></p>
217 <p class="p7">[1,2,3,4,5].inject([], {<span class="s3">|a,b|</span> [b] ++ a ++ [b]}); <span class="s9">// [ 5, 4, 3, 2, 1, 1, 2, 3, 4, 5 ]</span></p>
218 <p class="p7">[1,2,3,4,5].inject([], {<span class="s3">|a,b|</span> a ++ b ++ a});</p>
219 <p class="p7">[1,2,3,4,5].inject([], {<span class="s3">|a,b|</span> a ++ a ++ b});</p>
220 <p class="p15"><br></p>
221 <p class="p2"><br></p>
222 <p class="p1"><b>any(function)</b></p>
223 <p class="p5">Answer whether function answers true for any item in the receiver.</p>
224 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
225 <p class="p10"><br></p>
226 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].any({ <span class="s3">arg</span> item, i; item.even });</p>
227 <p class="p2"><br></p>
228 <p class="p1"><b>every(function)</b></p>
229 <p class="p5">Answer whether function answers true for every item in the receiver.</p>
230 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
231 <p class="p10"><br></p>
232 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].every({ <span class="s3">arg</span> item, i; item.even });</p>
233 <p class="p2"><br></p>
234 <p class="p1"><b>count(function)</b></p>
235 <p class="p5">Answer the number of items for which function answers true.</p>
236 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
237 <p class="p10"><br></p>
238 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].count({ <span class="s3">arg</span> item, i; item.even });</p>
239 <p class="p2"><br></p>
240 <p class="p1"><b>occurrencesOf(anObject)</b></p>
241 <p class="p5">Answer the number of items in the receiver which are equal to anObject.</p>
242 <p class="p10"><br></p>
243 <p class="p7"><span class="s3">List</span>[1, 2, 3, 3, 4, 3, 4, 3].occurrencesOf(3);</p>
244 <p class="p2"><br></p>
245 <p class="p1"><b>sum(function)</b></p>
246 <p class="p5">Answer the sum of the results of function evaluated for each item in the receiver.</p>
247 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
248 <p class="p10"><br></p>
249 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].sum;</p>
250 <p class="p9"><br></p>
251 <p class="p7">(0..8).sum { <span class="s3">|i|</span> 1 / (2 ** i) };</p>
252 <p class="p2"><br></p>
253 <p class="p1"><b>maxItem(function)</b></p>
254 <p class="p5">Answer the maximum of the results of function evaluated for each item in the receiver.</p>
255 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
256 <p class="p5">If function is nil, then answer the maximum of all items in the receiver.</p>
257 <p class="p10"><br></p>
258 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].maxItem({ <span class="s3">arg</span> item, i; item + 10 });</p>
259 <p class="p2"><br></p>
260 <p class="p1"><b>minItem(function)</b></p>
261 <p class="p5">Answer the minimum of the results of function evaluated for each item in the receiver.</p>
262 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
263 <p class="p5">If function is nil, then answer the minimum of all items in the receiver.</p>
264 <p class="p10"><br></p>
265 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].minItem({ <span class="s3">arg</span> item, i; item + 10 });</p>
266 <p class="p2"><br></p>
267 <p class="p1"><b>maxIndex(function)</b></p>
268 <p class="p5">Answer the index of the maximum of the results of function evaluated for each item in the receiver.</p>
269 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
270 <p class="p5">If function is nil, then answer the maximum of all items in the receiver.</p>
271 <p class="p10"><br></p>
272 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].maxIndex({ <span class="s3">arg</span> item, i; item + 10 });</p>
273 <p class="p7">[3.2, 12.2, 13, 0.4].maxIndex</p>
274 <p class="p2"><br></p>
275 <p class="p1"><b>minIndex(function)</b></p>
276 <p class="p5">Answer the index of the minimum of the results of function evaluated for each item in the receiver.</p>
277 <p class="p5">The function is passed two arguments, the item and an integer index.</p>
278 <p class="p5">If function is nil, then answer the minimum of all items in the receiver.</p>
279 <p class="p10"><br></p>
280 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].minIndex({ <span class="s3">arg</span> item, i; item + 10 });</p>
281 <p class="p7"><span class="s3">List</span>[3.2, 12.2, 13, 0.4].minIndex</p>
282 <p class="p2"><br></p>
283 <p class="p2"><br></p>
284 <p class="p2"><br></p>
285 <p class="p1"><b>iter</b></p>
286 <p class="p5">returns a <a href="../Core/Kernel/Routine.html"><span class="s3">Routine</span></a> that returns the elements one by one.</p>
287 <p class="p10"><br></p>
288 <p class="p7">r = <span class="s3">Set</span>[10, 2, -3, -4].iter;</p>
289 <p class="p7">r.next;</p>
290 <p class="p7">r.next;</p>
291 <p class="p7">r.next;</p>
292 <p class="p7">r.next; <span class="s9">// nil.</span></p>
293 <p class="p15"><br></p>
294 <p class="p3"><br></p>
295 <p class="p3"><br></p>
296 <p class="p4"><b>Conversion:</b></p>
297 <p class="p2"><br></p>
298 <p class="p1"><b>asBag</b></p>
299 <p class="p5">Answer a Bag to which all items in the receiver have been added.</p>
300 <p class="p10"><br></p>
301 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].asBag;</p>
302 <p class="p2"><br></p>
303 <p class="p1"><b>asList</b></p>
304 <p class="p5">Answer a List to which all items in the receiver have been added.</p>
305 <p class="p10"><br></p>
306 <p class="p7"><span class="s3">Set</span>[1, 2, 3, 4].asList;</p>
307 <p class="p2"><br></p>
308 <p class="p1"><b>asSet</b></p>
309 <p class="p5">Answer a Set to which all items in the receiver have been added.</p>
310 <p class="p10"><br></p>
311 <p class="p7"><span class="s3">List</span>[1, 2, 3, 4].asSet;</p>
312 <p class="p2"><br></p>
313 <p class="p1"><b>asSortedList</b></p>
314 <p class="p5">Answer a SortedList to which all items in the receiver have been added.</p>
315 <p class="p10"><br></p>
316 <p class="p7"><span class="s3">List</span>[2, 1, 4, 3].asSortedList;</p>
317 <p class="p2"><br></p>
318 <p class="p2"><br></p>
319 <p class="p1"><b>powerset</b></p>
320 <p class="p5">Returns all possible combinations of the collection's elements.</p>
321 <p class="p9"><br></p>
322 <p class="p7"><span class="s3">Set</span>[1, 2, 3].powerset;</p>
323 <p class="p9"><br></p>
324 <p class="p13">// generate the von neumann ordinals. (warning: only count to four at maximum!)</p>
325 <p class="p7">a = <span class="s3">Set</span>[];</p>
326 <p class="p7">a = a.powerset;</p>
327 <p class="p7">a = a.powerset;</p>
328 <p class="p7">a = a.powerset;</p>
329 <p class="p9"><br></p>
330 <p class="p13"><span class="s4">u = { </span><span class="s3">|set|</span><span class="s4"> set.unify }; </span>// union (count down)</p>
331 <p class="p7">n = { <span class="s3">|set|</span> set.powerset }; <span class="s9">// powerset (count up)</span></p>
332 <p class="p13"><span class="s4">a = </span><span class="s3">Set</span><span class="s4">[]; </span>// empty set (zero)</p>
333 <p class="p7">n.(n.(a)); <span class="s9">// two</span></p>
334 <p class="p7">u.(n.(n.(a))) == n.(a); <span class="s9">// two - one == one</span></p>
335 <p class="p7">u.(u.(n.(n.(a)))) == u.(n.(a)); <span class="s9">// two - two == one - one<span class="Apple-converted-space"> </span></span></p>
336 <p class="p2"><br></p>
337 <p class="p1"><b>flopDict(unbubble)</b></p>
338 <p class="p5">Takes a collection of dictionaries and returns a single dictionary with arrays of all dictionaries' elements.</p>
339 <p class="p5">If unbubble is true (default), and if one element is singular, the array is replaced by this element.</p>
340 <p class="p9"><br></p>
341 <p class="p7">[(degree: 7, x: 4), (degree: 8, x: 5), (degree: -2, dur: 2.5)].flopDict;</p>
342 <p class="p7">[(degree: 7, x: 4), (degree: 8, x: 5), (degree: -2, dur: 2.5)].flopDict(<span class="s3">false</span>);</p>
343 <p class="p2"><br></p>
344 <p class="p2"><br></p>
345 <p class="p1"><b>histo(steps, min, max)</b></p>
346 <p class="p5">Returns a histogram of the collection by counting the number of values that fall into each slot of <b>size (default: 100)</b> subdivisions between <b>min</b> and <b>max</b>. 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.</p>
347 <p class="p9"><br></p>
348 <p class="p7">{ 1.0.linrand }.dup(10000).histo(1000).plot;</p>
349 <p class="p7">{ 8.rand }.dup(10000).histo(8).plot(discrete: <span class="s3">true</span>);</p>
350 <p class="p2"><br></p>
351 <p class="p2"><br></p>
352 <p class="p2"><br></p>
353 <p class="p1"><b>printOn(stream)</b></p>
354 <p class="p5">Print a representation of the collection to a stream.</p>
355 <p class="p2"><br></p>
356 <p class="p1"><b>storeOn(stream)</b></p>
357 <p class="p5">Write a compileable representation of the collection to a stream.</p>
358 <p class="p2"><br></p>
359 <p class="p1"><b>printItemsOn(stream)</b></p>
360 <p class="p5">Print a comma separated compileable representation of the items in the collection to a stream.</p>
361 <p class="p2"><br></p>
362 <p class="p1"><b>storeItemsOn(stream)</b></p>
363 <p class="p5">Write a comma separated compileable representation of the items in the collection to a stream.</p>
364 <p class="p2"><br></p>
365 <p class="p2"><br></p>
366 <p class="p2"><br></p>
367 <p class="p2"><br></p>
368 <p class="p2"><br></p>
369 <p class="p16"><b>Set specific operations:</b></p>
370 <p class="p17"><br></p>
371 <p class="p2"><br></p>
372 <p class="p1"><b>sect(that)</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>return the set theoretical intersection of <b>this</b> and <b>that</b></p>
373 <p class="p15"><br></p>
374 <p class="p18">a = [1, 2, 3]; b = [2, 3, 4, 5];</p>
375 <p class="p18">sect(a, b);</p>
376 <p class="p2"><br></p>
377 <p class="p1"><b>union(that)</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>return the set theoretical union of <b>this</b> and <b>that</b></p>
378 <p class="p15"><br></p>
379 <p class="p18">a = [1, 2, 3]; b = [2, 3, 4, 5];</p>
380 <p class="p18">union(a, b);</p>
381 <p class="p2"><br></p>
382 <p class="p1"><b>difference(that)<span class="Apple-tab-span"> </span></b><span class="Apple-tab-span"> </span>return the set of all items which are elements of <b>this</b>, but not of <b>that</b></p>
383 <p class="p15"><br></p>
384 <p class="p18">a = [1, 2, 3]; b = [2, 3, 4, 5];</p>
385 <p class="p18">difference(a, b);</p>
386 <p class="p2"><br></p>
387 <p class="p1"><b>symmetricDifference(that)</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>return the set of all items which are not elements of both<span class="Apple-converted-space">  </span><b>this</b> and <b>that</b></p>
388 <p class="p1"><b>this -- that</b></p>
389 <p class="p15"><br></p>
390 <p class="p18">a = [1, 2, 3]; b = [2, 3, 4, 5];</p>
391 <p class="p18">symmetricDifference(a, b);</p>
392 <p class="p2"><br></p>
393 <p class="p1"><b>isSubsetOf(that)</b><span class="Apple-tab-span"> </span>returns true if all elements of <b>this</b> are also elements of <b>that</b><span class="Apple-converted-space"> </span></p>
394 <p class="p2"><br></p>
395 <p class="p18">a = <span class="s3">Set</span>[1, 2, 3, 4];</p>
396 <p class="p18"><span class="s3">Set</span>[1, 2].isSubsetOf(a); <span class="s9">// true</span></p>
397 <p class="p18"><span class="s3">Set</span>[1, 5].isSubsetOf(a); <span class="s9">// false</span></p>
398 <p class="p2"><br></p>
399 <p class="p2"><br></p>
400 </body>
401 </html>