equal
deleted
inserted
replaced
257 Kludges around the stupid definition of OrderedCollection>>new:" |
257 Kludges around the stupid definition of OrderedCollection>>new:" |
258 |
258 |
259 ^ self withSize:n |
259 ^ self withSize:n |
260 ! ! |
260 ! ! |
261 |
261 |
262 |
|
263 !Collection class methodsFor:'Signal constants'! |
262 !Collection class methodsFor:'Signal constants'! |
264 |
263 |
265 emptyCollectionSignal |
264 emptyCollectionSignal |
266 "return the signal used to report non-allowed operation on empty collections" |
265 "return the signal used to report non-allowed operation on empty collections" |
267 |
266 |
528 |
527 |
529 ^ self keysAndValuesDo:[:key :index | |
528 ^ self keysAndValuesDo:[:key :index | |
530 aTwoArgBlock value:index value:key |
529 aTwoArgBlock value:index value:key |
531 ]. |
530 ]. |
532 ! ! |
531 ! ! |
533 |
|
534 |
532 |
535 !Collection methodsFor:'accessing'! |
533 !Collection methodsFor:'accessing'! |
536 |
534 |
537 anElement |
535 anElement |
538 "return any element from the collection, |
536 "return any element from the collection, |
2217 " |
2215 " |
2218 #(1 2 3 4 5 6 7) collect:[:i | i * 2] thenSelect:[:i | i < 10] |
2216 #(1 2 3 4 5 6 7) collect:[:i | i * 2] thenSelect:[:i | i < 10] |
2219 " |
2217 " |
2220 ! |
2218 ! |
2221 |
2219 |
|
2220 collect:collectBlock thenSelect:selectBlock as:aCollectionClass |
|
2221 "first apply collectBlock to each element, then pass the result to |
|
2222 selectBlock. |
|
2223 Return a new collection with all elements from the receiver, |
|
2224 for which the selectBlock evaluates to true. |
|
2225 Returns the same as if two separate collect+select messages were sent, |
|
2226 but avoids the creation of intermediate collections, so this is nicer for |
|
2227 big collections." |
|
2228 |
|
2229 |newCollection| |
|
2230 |
|
2231 newCollection := aCollectionClass new. |
|
2232 self do:[:each | |
|
2233 |rslt| |
|
2234 |
|
2235 rslt := collectBlock value:each. |
|
2236 (selectBlock value:rslt) ifTrue:[newCollection add:rslt]. |
|
2237 ]. |
|
2238 ^ newCollection |
|
2239 |
|
2240 " |
|
2241 #(1 2 3 4) select:[:e | e odd] thenCollect:[:e| e*e] as:OrderedCollection |
|
2242 (1 to:10) select:[:e | e even] thenCollect:[:e| e*e] as:IdentitySet |
|
2243 " |
|
2244 |
|
2245 "Created: / 29-08-2013 / 09:56:20 / cg" |
|
2246 ! |
|
2247 |
2222 collectAll:aBlock |
2248 collectAll:aBlock |
2223 "for each element in the receiver, evaluate the argument, aBlock. |
2249 "for each element in the receiver, evaluate the argument, aBlock. |
2224 The block is supposed to return a collection, whose elements are collected. |
2250 The block is supposed to return a collection, whose elements are collected. |
2225 The species of the returned collection is that of the first returned |
2251 The species of the returned collection is that of the first returned |
2226 partial result." |
2252 partial result." |
3046 ! |
3072 ! |
3047 |
3073 |
3048 select:selectBlock thenCollect:collectBlock as:aCollectionClass |
3074 select:selectBlock thenCollect:collectBlock as:aCollectionClass |
3049 "return a new collection with all elements from the receiver, for which |
3075 "return a new collection with all elements from the receiver, for which |
3050 the argument selectBlock evaluates to true. |
3076 the argument selectBlock evaluates to true. |
3051 Process the elements throgh collectBlock before adding." |
3077 Process the elements throgh collectBlock before adding. |
|
3078 Returns the same as if two separate collect+select messages were sent, |
|
3079 but avoids the creation of intermediate collections, so this is nicer for |
|
3080 big collections." |
3052 |
3081 |
3053 |newCollection| |
3082 |newCollection| |
3054 |
3083 |
3055 newCollection := aCollectionClass new. |
3084 newCollection := aCollectionClass new. |
3056 self do:[:each | |
3085 self do:[:each | |
4840 ! ! |
4869 ! ! |
4841 |
4870 |
4842 !Collection class methodsFor:'documentation'! |
4871 !Collection class methodsFor:'documentation'! |
4843 |
4872 |
4844 version |
4873 version |
4845 ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.309 2013-08-10 11:14:45 stefan Exp $' |
4874 ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.310 2013-08-29 09:52:54 cg Exp $' |
4846 ! |
4875 ! |
4847 |
4876 |
4848 version_CVS |
4877 version_CVS |
4849 ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.309 2013-08-10 11:14:45 stefan Exp $' |
4878 ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.310 2013-08-29 09:52:54 cg Exp $' |
4850 ! ! |
4879 ! ! |
4851 |
4880 |
4852 |
4881 |
4853 Collection initialize! |
4882 Collection initialize! |