News for hackers. Stuff that matters.
Re:The Comprehensive Guide to Elixir's List Comprehension (2... by mhanberg on Wednesday June 28, 2023 @06:02PM (#36513251)
I generally default to a comprehension unless it becomes illegible.

Disclaimer: I am the author of the article and am in the pocket of Big Comprehension

Re:The Comprehensive Guide to Elixir's List Comprehension (2... by freedomben on Wednesday June 28, 2023 @07:20PM (#36514067)
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.

Re:The Comprehensive Guide to Elixir's List Comprehension (2... by square_usual on Wednesday June 28, 2023 @08:37PM (#36514808)
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!
Re:The Comprehensive Guide to Elixir's List Comprehension (2... by bluesnowmonkey on Thursday June 29, 2023 @11:01AM (#36521328)
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.
Re:The Comprehensive Guide to Elixir's List Comprehension (2... by nickpeterson on Wednesday June 28, 2023 @07:28PM (#36514162)
I generally just use for loops but I’m in the pocket of Big Ignorance.
Re:The Comprehensive Guide to Elixir's List Comprehension (2... by PKop on Wednesday June 28, 2023 @11:31PM (#36515993)
Elixir doesn't have for loops
Re:The Comprehensive Guide to Elixir's List Comprehension (2... by arrowsmith on Thursday June 29, 2023 @03:02AM (#36517308)

    for x <- 1..10 do
      IO.puts x
    end
Isn't that a for loop?
Re:The Comprehensive Guide to Elixir's List Comprehension (2... by Munksgaard on Thursday June 29, 2023 @06:42AM (#36518717)
In Elixir that is a called a comprehension, just like the blog post is discussing.
Re:The Comprehensive Guide to Elixir's List Comprehension (2... by PKop on Thursday June 29, 2023 @09:52AM (#36520393)
Similar, but different in subtle ways when you get beyond the toy example posted here...particularly that it's always iterating a collection, vs being able to just arbitrarily loop based on arbitrary conditions..where you'd be able to easily break out of it, modify a mutable collection within it etc

https://dev.to/brewinstallbuzzwords/does-elixir-have-for-loo... "Does Elixir have for loops?"

https://elixirforum.com/t/changing-variables-in-a-loop/43526 "Changing variables in a loop"

https://stackoverflow.com/questions/56196664/better-way-writ...

https://stackoverflow.com/questions/48178773/adding-items-to...