I have already done many of the Project Euler questions in other languages before, but whenever learning a new language, I like to do the problems again in that language.
Here is my elixir version of
Find the sum of all Fibonacci numbers below 4,000,000.
stream = Stream.unfold({0,1}, fn {a, b} -> {a, {b, a + b}} end)
Enum.reduce_while(stream, 0, &(
cond do
&1 < 4000000 and rem(&1, 2) == 0 ->
{:cont, &2 + &1}
&1 < 4000000 ->
{:cont, &2}
true ->
{:halt, &2}
end
))
Can anyone spot a way to make my code fit the elixir paradigm more? Are there things I could improve?