<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<font face="Georgia">One thing to note is that the collection is
messed up while in the midst of removal:<br>
<br>
a _ #(1 2 3 4 5) asOrderedCollection.<br>
a removeAllSuchThat: [ :each |<br>
Transcript show: a asString; cr.<br>
each odd<br>
].<br>
Transcript show: a asString; cr.<br>
<br>
so, if your #doSomething were to examine the collection, it might
get the wrong impression.<br>
<br>
<br>
<br>
</font>
<div class="moz-cite-prefix">On 7/4/13 11:30 AM, Chris Muller wrote:<br>
</div>
<blockquote
cite="mid:CADTxDUiaCnVszvGdRaq=LY8npA=VwOvvTtbvaTdGxujF-ybVjA@mail.gmail.com"
type="cite">
<pre wrap="">Hm, I did not know about removeAllSuchThat:, but in looking at it, I
find two things "wrong" with it. 1) the superclass implementation in
Collection makes a copy of the collection, which is the basis of my
reason to use reverseDo: instead of enumerating a copy myself.
But I'm using an OC and OC overrides it without making the copy.
That's good, but I also need to know which elements were removed. I
ended up doing it like:
myCollection removeAllSuchThat: [ : each | each meetsMyCondition
and: [ each doSomething. true ] ]
I think it would be nice if removeAllSuchThat: could be similar to
remove: in this respect, but at least, unlike Java, Smalltalk lets me
put any "doSomething" expression in the block as long as it finally
evaluates to a boolean.
Thanks.
On Wed, Jul 3, 2013 at 4:19 PM, Bert Freudenberg <a class="moz-txt-link-rfc2396E" href="mailto:bert@freudenbergs.de"><bert@freudenbergs.de></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">
On 03.07.2013, at 11:27, Chris Muller <a class="moz-txt-link-rfc2396E" href="mailto:asqueaker@gmail.com"><asqueaker@gmail.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I have a case where I need to remove certain entries from an
OrderedCollection that will be called very frequently. I therefore
want to avoid copying the collection (to safely remove while
enumerating) but it seems #reverseDo: can do what I want.
myCollection reverseDo: [ : each | each meetsSomeCriteria ifTrue: [
myCollection remove: each ] ]
Does anyone see any problem with doing this?
</pre>
</blockquote>
<pre wrap="">
What's wrong with removeAllSuchThat:?
- Bert -
</pre>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
<br>
</body>
</html>