Is there any reason there's no select!
(and I am familiar with compact! but still...)
C:\>ruby -e 'puts [].methods.grep /reject/'
reject
reject!
C:\>ruby -e 'puts [].methods.grep /select/'
select
···
--
Posted via http://www.ruby-forum.com/.
Is there any reason there's no select!
(and I am familiar with compact! but still...)
C:\>ruby -e 'puts [].methods.grep /reject/'
reject
reject!
C:\>ruby -e 'puts [].methods.grep /select/'
select
--
Posted via http://www.ruby-forum.com/.
Perhaps because `select! x` is as simple as `reject! not x`?
On Dec 15, 2009, at 10:35 , Roger Pack wrote:
Is there any reason there's no select!
Maybe Matz felt that using "select" to actually _delete_ from an Array
would be considered weird. And indeed, we have #delete, #delete_at
and #delete_if:
irb(main):001:0> Array.instance_methods.grep /delete/
=> [:delete, :delete_at, :delete_if]
irb(main):002:0>
![]()
Kind regards
robert
2009/12/15 Roger Pack <rogerpack2005@gmail.com>:
Is there any reason there's no select!
(and I am familiar with compact! but still...)C:\>ruby -e 'puts .methods.grep /reject/'
reject
reject!C:\>ruby -e 'puts .methods.grep /select/'
select
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
For consistency's sake, I'd still suggest the standard library should provide
something like:
module Enumerable
def select!
reject! {|*args| ! yield(*args) }
end
def reject!
select! {|*args| ! yield(*args) }
end
end
Not exactly that, though -- the obvious problem is that if neither select! no
reject! is overridden, you'd want a NoMethodError instead of a stack overflow.
On Tuesday 15 December 2009 02:51:56 pm Ryan Davis wrote:
On Dec 15, 2009, at 10:35 , Roger Pack wrote:
> Is there any reason there's no select!Perhaps because `select! x` is as simple as `reject! not x`?
Enumerable does not have a reject! since not all Enumerables are
mutable either in general or during enumeration
Yeah this is a feature request only for Array#select!
[Enumerable doesn't have a reject! nor should it have a select!]
Maybe Matz felt that using "select" to actually _delete_ from an Array
would be considered weird. And indeed, we have #delete, #delete_at
and #delete_if:
His words:
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.
So yes but hopefully I can change his mind ![]()
-r
--
Posted via http://www.ruby-forum.com/\.
For consistency's sake, I'd still suggest the standard library should
provide
something like:module Enumerable
def select!
reject! {|*args| ! yield(*args) }
end
def reject!
select! {|*args| ! yield(*args) }
end
end
Anybody in favor of select!
Could comment on
http://redmine.ruby-lang.org/issues/show/2515
-r
--
Posted via http://www.ruby-forum.com/\.
The second "SELECT * FROM TABLE" deletes the records I want to retrieve from a DBMS, I agree with you. ![]()
On 22.12.2009 17:29, Roger Pack wrote:
His words:
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.So yes but hopefully I can change his mind
--
Phillip Gawlowski
-1
Enumerable does not have a reject! since not all Enumerables are
mutable either in general or during enumeration.
Also the given suggestion would lead to infinite loops, unless reject!
or select! was overridden in the including class.
On Tue, Dec 22, 2009 at 9:54 AM, Roger Pack <rogerpack2005@gmail.com> wrote:
For consistency's sake, I'd still suggest the standard library should
provide
something like:module Enumerable
def select!
reject! {|*args| ! yield(*args) }
end
def reject!
select! {|*args| ! yield(*args) }
end
end
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale