Hacker News new | ask | show | jobs
by Widdershin 4255 days ago
Regarding find_all_with_index, you can do:

    .find_all.with_index { |item, index| ... }
1 comments

except .find_all.with_index passes the index to the predicate block, but still only returns a view of the matching elements from the list.

What I think is being sought is more like:

  module Enumerable
    def find_indices
      each.with_index
          .find_all {|x,_| yield x}
          .map {|_,y| y}
    end
  end