Skip to content
Better HN
Top
Best
Ask
Show
New
Jobs
Search
⌘K
0 points
knrz
6y ago
0 comments
Save
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.
0 comments
1 comments · 1 top-level
top
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