New in ruby-2.7.0 filter_map by Tessy Joseph John — 11 June 2019 https://blog.mavenhive.in/ruby-2-7-adds-enumerable-filter-map-d84aad03b6d4 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. Kimmo Lehto — 12 June 2019 Post a comment You can use basic HTML markup (e.g. <a>) or Markdown. Authenticate with GitHub As you are not logged in, you will bedirected via GitHub to signup or sign in
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 insidefilter_map
.Post a comment