Skip to content
Better HN
Top
New
Best
Ask
Show
Jobs
Search
⌘K
0 points
knrz
6y ago
0 comments
Share
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.
undefined | Better HN
0 comments
default
newest
oldest
Rafert
6y ago
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"]
j
/
k
navigate · click thread line to collapse