Hacker News new | ask | show | jobs
by knrz 2374 days ago
In JavaScript, Elixir, and Ruby I use flatMap for this purpose. You can return an empty array on the block to “skip” over the element.
1 comments

2.7 introduces `Enumerable#filter_map` for that. Example from the NEWS file:

[1, 2, 3].filter_map {|x| x.odd? ? x.to_s : nil } #=> ["1", "3"]