Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Regarding find_all_with_index, you can do:

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


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




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: