374 #(1 2 3 4 5) copy removeAll |
374 #(1 2 3 4 5) copy removeAll |
375 #(1 2 3 4 5) removeAll |
375 #(1 2 3 4 5) removeAll |
376 " |
376 " |
377 |
377 |
378 "Modified: 10.1.1997 / 15:14:55 / cg" |
378 "Modified: 10.1.1997 / 15:14:55 / cg" |
|
379 ! |
|
380 |
|
381 removeAllSuchThat:aBlock |
|
382 "remove all elements that meet a test criteria as specified in aBlock. |
|
383 The argument, aBlock is evaluated for successive elements and all those, |
|
384 for which it returns true, are removed. |
|
385 Return a collection containing the removed elements. |
|
386 Redefined to do a single become operation." |
|
387 |
|
388 |keptElements removedElements element sz "{ Class:SmallInteger }"| |
|
389 |
|
390 sz := self size. |
|
391 keptElements := self speciesForAdding new:sz. |
|
392 |
|
393 1 to:sz do:[:index | |
|
394 element := self at:index. |
|
395 (aBlock value:element) ifTrue:[ |
|
396 removedElements isNil ifTrue:[ |
|
397 removedElements := self speciesForAdding new. |
|
398 ]. |
|
399 removedElements add:element. |
|
400 ] ifFalse:[ |
|
401 keptElements add:element. |
|
402 ]. |
|
403 ]. |
|
404 |
|
405 removedElements isNil ifTrue:[ |
|
406 ^ #(). |
|
407 ]. |
|
408 |
|
409 'ArrayedCollection [info]: slow removeAllSuchThat operation (' infoPrint. |
|
410 self class name infoPrint. ')' infoPrintCR. |
|
411 |
|
412 keptElements := (self species withAll:keptElements) postCopyFrom:self. |
|
413 self become:keptElements. |
|
414 ^ removedElements |
|
415 |
|
416 " |
|
417 |coll| |
|
418 |
|
419 coll := Array withAll:(1 to:10). |
|
420 Transcript showCR:(coll removeAllSuchThat:[:el | el even]). |
|
421 Transcript showCR:coll |
|
422 " |
|
423 |
|
424 "Created: / 13-04-2018 / 14:02:24 / stefan" |
379 ! ! |
425 ! ! |
380 |
426 |
381 !ArrayedCollection methodsFor:'copying'! |
427 !ArrayedCollection methodsFor:'copying'! |
382 |
428 |
383 copyEmptyAndGrow:size |
429 copyEmptyAndGrow:size |