--0016364c76298d249a047b8c634b
Content-Type: text/plain; charset=ISO-8859-1

Hi

2009/12/25 David A. Black <dblack / rubypal.com>

> Hi --
>
>
> On Thu, 24 Dec 2009, Gavin Sinclair wrote:
>
>  On Thu, Dec 24, 2009 at 10:19 AM, David A. Black <dblack / rubypal.com>
>> wrote:
>>
>>  |Is there any reason there's no select!
>>>>
>>>> Enumerables cannot have bang method, since they are not always
>>>> mutable.  The reason we don't have Array#select! is that I feel the
>>>> word select means picking up elements, not removing non-selecting
>>>> elements.  But I once felt same way to map! and (English speaking)
>>>> people persuaded me, so same thing could happen on select! as well.
>>>>
>>>
>>> I agree with you. The idea of a destructive select makes no sense to
>>> me. Selecting implies that there's a result set that's separate from
>>> the original collection.
>>>
>>
>> I think it's fine.  It's an aggressive selection, like selecting a
>> sports team from a squad of available players.
>>
>
> But that's the thing; it's the original squad, not the selected team,
> that's analogous to the array.
>
> Say you've got a squad of players, standing in a line:
>
>  SQUAD:  Joe Jim Jill Jack Jason Jeff Joan
>
> You select a bunch of them for a team and ask them to step forward, on
> the understanding that they will no longer be part of the original
> squad/pool of players
>
>  SQUAD:  Joe     Jill Jack       Jeff
>
>  TEAM :      Jim           Jason      Joan
>
> The squad (i.e., the original "object" from which you have made a
> selection) now consists of the people who were *not* selected for the
> team, not those who were.
>
> Aggressiveness isn't relevant. If you say to Jim, Jason, and Joan:
> "You have been *aggressively* selected for the team!", that should
> still mean that they're on the team, not that they're back in the
> original player pool (the array/object), let alone that they are now
> the sole occupants of that original pool.
>
> Select and reject are not symmetrical or opposite operations; they're
> two names for the same process, namely identifying a result set based
> on selection criteria from a collection. However this process happens,
> you end up with the original collection and the result set. The only
> decision to be made is whether or not the members of the result set
> can also be in the original collection.
>
> A destructive reject means: having made this separation of original
> collection and result set, make the separation permanent. A
> destructive select, in the sense that's being suggested here, would
> mean: having made the separation, replace the original collection with
> the result set. That's a completely new twist, and one that isn't
> implied in any way by the original idea of "select".
>
> That's why "keep" makes more sense as a name for "reduce the original
> collection to the matching elements". It's a simple statement of the
> semantics of this particular operation.
>
> (I almost wish reject! were called "discard" or something. I think the
> similarity in sound between reject and select suggests a symmetry that
> really isn't in the semantics.)
>
>
>
> David
>
> --
> David A. Black
> Senior Developer, Cyrus Innovation Inc.
> THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
> January 22-23, Tampa, Florida
> Info and registration at http://www.thecompleatrubyist.com
>

I think also select is just taking a part of something and probably do
something with that part.

For the team (let's say of football), I see it in this way:

Somebody is going to select some people, for example:
people.select { |p| p.strength > 0.8 && p.cooperative? }

So, now you want to add these player to the team. But you'll have too many
players... So you need to reject some :
team.reject { |p| p.bad? }

So:
team.reject! { |p| p.bad? }
team + eople.select { |p| p.strength > 0.8 && p.cooperative? }

About your example of select!:
 result  ollection.map { |x|
   ...
   ...
   ...
 }
 result.select! { |x| ... }

I think not many people use select to change a collection. Well, with this
select, what you'll gonna do is removing(rejecting...) some elements. And
that fact is linked to reject, not to select. Select is, as Matz said
earlier, done for picking up some elements and then do something with them.

But, show us some real use of select!, to see how it looks ;)

Also, I think this kinf of things:
irb(main):001:0> a  1..6).to_a
[1, 2, 3, 4, 5, 6]
irb(main):002:0> a.map! { |n| -n }.reject! { |n| n.even? }
[-1, -3, -5]

Looks really not good and doing this seem more readable:

a  .map { |n| -n }.reject { |n| n.even? }

Anyway, Happy Christmas's day

--0016364c76298d249a047b8c634b
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi<br><br><div class="gmail_quote">2009/12/25 David A. Black <span dir="ltr">&lt;dblack / rubypal.com&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solidgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi --<div class="im"><br>
<br>
On Thu, 24 Dec 2009, Gavin Sinclair wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Thu, Dec 24, 2009 at 10:19 AM, David A. Black &lt;<a href="mailto:dblack / rubypal.com" target="_blank">dblack / rubypal.com</a>&gt; wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

|Is there any reason there&#39;s no select!<br>
<br>
Enumerables cannot have bang method, since they are not always<br>
mutable.         word select means picking up elements, not removing non-selecting<br>
elements.         穼people persuaded me, so same thing could happen on select! as well.<br>
</blockquote>
<br>
I agree with you. The idea of a destructive select makes no sense to<br>
me. Selecting implies that there&#39;s a result set that&#39;s separate from<br>
the original collection.<br>
</blockquote>
<br>
I think it&#39;s fine.      sports team from a squad of available players.<br>
</blockquote>
<br></div>
But that&#39;s the thing; it&#39;s the original squad, not the selected team,<br>
that&#39;s analogous to the array.<br>
<br>
Say you&#39;ve got a squad of players, standing in a line:<br>
<br>
       
<br>
You select a bunch of them for a team and ask them to step forward, on<br>
the understanding that they will no longer be part of the original<br>
squad/pool of players<br>
<br>
      
<br>
     <br>
The squad (i.e., the original &quot;object&quot; from which you have made a<br>
selection) now consists of the people who were *not* selected for the<br>
team, not those who were.<br>
<br>
Aggressiveness isn&#39;t relevant. If you say to Jim, Jason, and Joan:<br>
&quot;You have been *aggressively* selected for the team!&quot;, that should<br>
still mean that they&#39;re on the team, not that they&#39;re back in the<br>
original player pool (the array/object), let alone that they are now<br>
the sole occupants of that original pool.<br>
<br>
Select and reject are not symmetrical or opposite operations; they&#39;re<br>
two names for the same process, namely identifying a result set based<br>
on selection criteria from a collection. However this process happens,<br>
you end up with the original collection and the result set. The only<br>
decision to be made is whether or not the members of the result set<br>
can also be in the original collection.<br>
<br>
A destructive reject means: having made this separation of original<br>
collection and result set, make the separation permanent. A<br>
destructive select, in the sense that&#39;s being suggested here, would<br>
mean: having made the separation, replace the original collection with<br>
the result set. That&#39;s a completely new twist, and one that isn&#39;t<br>
implied in any way by the original idea of &quot;select&quot;.<br>
<br>
That&#39;s why &quot;keep&quot; makes more sense as a name for &quot;reducehe original<br>
collection to the matching elements&quot;. It&#39;s a simple statement of the<br>
semantics of this particular operation.<br>
<br>
(I almost wish reject! were called &quot;discard&quot; or something. I think the<br>
similarity in sound between reject and select suggests a symmetry that<br>
really isn&#39;t in the semantics.)<div><div></div><div class="h5"><br>
<br>
<br>
David<br>
<br>
-- <br>
David A. Black<br>
Senior Developer, Cyrus Innovation Inc.<br>
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!<br>
January 22-23, Tampa, Florida<br>
Info and registration at <a href="http://www.thecompleatrubyist.com" target="_blank">http://www.thecompleatrubyist.com</a></div></div></blockquote></div><br>I think also select is just taking a part of something and probably do something with that part.<br>
<br>For the team (let&#39;s say of football), I see it in this way:<br><br>Somebody is going to select some people, for example:<br>people.select { |p| p.strength &gt; 0.8 &amp;&amp; p.cooperative? }<br><br>So, now you want to add these player to the team. But you&#39;ll have too many players... So you need to reject some :<br>
team.reject { |p| p.bad? }<br><br>So:<br>team.reject! { |p| p.bad? }<br>team += people.select { |p| p.strength &gt; 0.8 &amp;&amp; p.cooperative? }<br><br>About your example of select!:<br>  
 ..<br>
 ..<br>
 ..<br>
  ¼
            箮                    <br>But, show us some real use of select!, to see how it looks ;)<br><br>Also, I think this kinf of things:<br>irb(main):001:0&gt; a = (1..6).to_a<br>=&gt; [1, 2, 3, 4, 5, 6]<br>irb(main):002:0&gt; a.map! { |n| -n }.reject! { |n| n.even? }<br>
=&gt; [-1, -3, -5]<br><br>Looks really not good and doing this seem more readable:<br><br>a = a.map { |n| -n }.reject { |n| n.even? }<br><br>Anyway, Happy Christmas&#39;s day<br><br>

--0016364c76298d249a047b8c634b--