On Dec 4, 11:07=A0am, Yukihiro Matsumoto <m... / ruby-lang.org> wrote:
> Hi,
>
> In message "Re: Enumerable#select used to return actual values"
> =A0 =A0 on Fri, 5 Dec 2008 00:47:45 +0900, Trans <transf... / gmail.com> wr=
ites:
>
> |> (1..10).collect{ |a| a * a if a > 5 }.compact
> |>
> |> The only time this doesn't work is when you want to preserve nils in
> |> your original array.
> |
> |And that's exactly what I suggested for #compact, to take a block but
> |faster b/c it's one pass.
>
> I don't deny the existence of use case of such method (although I
> cannot think of any realistic one right now), but its name should not
> be #compact, since it does far more than compacting the receiver.

Why do you say? Is not "compact conditionally on result of block" a
good meaning?

The implementation I have also allows an optional argument to define
what is to be subjected to compacting.

  [1,2,3].compact(1)  #=3D> [2,3]

Which is similar to #delete, except not in place. Though, using #=3D=3D=3D
instead of #=3D=3D could be a very useful differentiation.

  [1,2,3,:x,:y,:z].compact(Symbol) #=3D> [1,2,3]

Yet, what method is currently non-in-place #delete?

T.