×
The Ruby and Rails community linklog
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
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