Hacker News new | ask | show | jobs
by freedomben 1093 days ago
Interesting, I use `map` all the time and `for` rarely. I'm not necessarily disagreeing with you as I see this as more of a style preference.

The map approach feels a lot more functional to me and is easy to chain. The `for` method feels a bit awkward. But that said I much prefer Ruby to Python. If I had the opposite preference, I'd probably like the `for` in Elixir more.

2 comments

I agree with you: I prefer map and reduce unless I specifically need a comprehension because of multiple input collections. IMO for with many conditions etc. becomes too hard to understand, and you have to keep too many things in mind vs. a filter |> map. Regardless, I don't mind its presence, and it definitely has come in handy at times. Yet another reason to enjoy Elixir's approach to language design!
I also use ‘for’ rarely. It silently ignore list elements that don’t match, whereas ‘map’ or ‘each’ blow up. Generally I prefer things to blow up rather than fail silently.