Closed bdunne closed 4 years ago
:+1: for the idea, but I don't like the name... What are the other methods that do this "dual" thing. Only one I can think of is .flat_map
. Perhaps select_and_collect
or select_and_map
? Otherwise there's .each_with_object
and .each_with_index
, which can be .each.with_object
and .each.with_index
. Perhaps this might be more flexible....select.collect
?
Additionally, if you have a select, you probably want a reject.
Crystal lang uses compact_map
, so I suggest going with that. This also then feels analogous to flat_map
.
Also a few of these rubocops are legit.
Too many times I find myself enumerating over an array wanting some transformed data and no
nil
s. So, I wind up with something like this:Instead, we can have:
This avoids allocating an extra array before the compact