2312 #(1 2 3 4) detect:[:n | n odd] ifNone:['sorry'] |
2312 #(1 2 3 4) detect:[:n | n odd] ifNone:['sorry'] |
2313 #(2 4 6 8) detect:[:n | n odd] ifNone:['sorry'] |
2313 #(2 4 6 8) detect:[:n | n odd] ifNone:['sorry'] |
2314 " |
2314 " |
2315 |
2315 |
2316 "Modified: / 13-09-2006 / 11:17:42 / cg" |
2316 "Modified: / 13-09-2006 / 11:17:42 / cg" |
|
2317 ! |
|
2318 |
|
2319 detect:checkBlock thenCompute:evalBlock |
|
2320 "evaluate the argument, aBlock for each element in the receiver until |
|
2321 chloeckBck returns true; in this case return the value from evalBlock |
|
2322 applied to the element which caused the true evaluation. |
|
2323 If none of the evaluations returns true, report an error" |
|
2324 |
|
2325 ^ self detect:checkBlock thenCompute:evalBlock ifNone:[self errorNotFound] |
|
2326 |
|
2327 " |
|
2328 #((1 'one') (2 'two') (3 'three') (4 'four')) |
|
2329 detect:[:pair | pair first odd] thenCompute:[:pair | pair second] |
|
2330 " |
|
2331 ! |
|
2332 |
|
2333 detect:checkBlock thenCompute:evalBlock ifNone:exceptionValue |
|
2334 "evaluate the argument, aBlock for each element in the receiver until |
|
2335 chloeckBck returns true; in this case return the value from evalBlock |
|
2336 applied to the element which caused the true evaluation. |
|
2337 If none of the evaluations returns true, return the value from exceptionValue." |
|
2338 |
|
2339 ^ evalBlock value:(self detect:checkBlock ifNone:[^ exceptionValue value]). |
|
2340 |
|
2341 " |
|
2342 #((1 'one') (2 'two') (3 'three') (4 'four')) |
|
2343 detect:[:pair | pair first odd] thenCompute:[:pair | pair second] |
|
2344 ifNone:[ nil ]. |
|
2345 " |
|
2346 " |
|
2347 #( (2 'two') (4 'four')) |
|
2348 detect:[:pair | pair first odd] thenCompute:[:pair | pair second] |
|
2349 ifNone:[ nil ]. |
|
2350 " |
2317 ! |
2351 ! |
2318 |
2352 |
2319 detectLast:aBlock |
2353 detectLast:aBlock |
2320 "evaluate the argument, aBlock for each element in the receiver until |
2354 "evaluate the argument, aBlock for each element in the receiver until |
2321 the block returns true; in this case return the element which caused |
2355 the block returns true; in this case return the element which caused |
4767 ! ! |
4801 ! ! |
4768 |
4802 |
4769 !Collection class methodsFor:'documentation'! |
4803 !Collection class methodsFor:'documentation'! |
4770 |
4804 |
4771 version |
4805 version |
4772 ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.304 2013-06-09 13:03:50 cg Exp $' |
4806 ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.305 2013-06-20 10:20:15 cg Exp $' |
4773 ! |
4807 ! |
4774 |
4808 |
4775 version_CVS |
4809 version_CVS |
4776 ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.304 2013-06-09 13:03:50 cg Exp $' |
4810 ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.305 2013-06-20 10:20:15 cg Exp $' |
4777 ! ! |
4811 ! ! |
4778 |
4812 |
4779 |
4813 |
4780 Collection initialize! |
4814 Collection initialize! |