RubyFlow The Ruby and Rails community linklog

New in ruby-2.7.0 filter_map

Comments

items.each_with_object([]) { |item, obj| obj << item.name if item.foo? }

This allows nils and falses.

I don’t like this filter_map thing as-is.

Couldn’t something like this be made to work:

items.filter_map do |item| next if item.foo? item.name end

With plain map next will give you a nil, but maybe it could be handled differently inside filter_map.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in