Saku Ytti
4/11/2008 4:47:00 PM
On (2008-04-12 01:32 +0900), David A. Black wrote:
Thanks everyone for fast reply.
>> I first looked at delete_if, then noticed that it actually mutates original
>> array and returns mutated array. I wonder would it make sense for delete_if
>> not to mutate and return new array and delete_if! to mutate and return deleted
>> elements?
>
> You should use #reject, which is non-destructive.
I guess I wasn't being clear, indeed reject removes the need for
non-mutating delete_if, which would make them equal. However, we're still
without method that does select, but mutates the returned elements out from
the original array.
If we'd have it, I guess select! would be bit odd name for it? And if it would
be delete_if! then mutating delete_if would be even more surprising?
Also, I may be biased with my own problem thinking that select that removes
elements from array is typical need. Just feels so at the moment.
--
++ytti