On Dec 31, 2010, at 02:12 , Michel Demazure wrote:

> I often have to write something like
> 
> some_enumerator.collect ... # or collect.with_index ...
> ....
> next if ...
> ...
> end.reject(&:nil?)
> 
> Is there a better way to do a "collect_unless_nil", avoiding the double
> processing ?

compact:

result = collection.map { |x|
  next if x.hinkey?
}.compact

that will be a LOT faster than your second pass with reject/nil?.