Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

For, Map and Reduce in Elixir

livebook/For_Map_Reduce.livemd

For, Map and Reduce in Elixir

Section

for i <- 1..10 do
  i * 10
end
1..10
|> Enum.map(fn x -> x * 10 end)
1..10
|> Enum.map(fn x -> x * 10 end)
|> Enum.sum()
1..10
|> Enum.reduce(fn x, accum -> x * 10 + accum end)
1..10
|> Enum.reduce(1, fn x, accum -> x * 10 * accum end)
for i <- 1..3, j <- ["Mexico", "Brasil", "United States"] do
  {:number, i, :country, j}
end
require Integer

for i <- 1..3,
    j <- ["Mexico", "Brasil", "United States"],
    Integer.is_even(i),
    String.starts_with?(j, "M") do
  {:number, i, :country, j}
end