Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Created January 7, 2017 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonewebdesign/9a21e4724fe2e7042e1543c6bc514c0a to your computer and use it in GitHub Desktop.
Save simonewebdesign/9a21e4724fe2e7042e1543c6bc514c0a to your computer and use it in GitHub Desktop.
Ways of looping through a collection/enumerable in Elixir
iex(6)> for _ <- 1..10 do
...(6)> end
[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
iex(7)> Enum.map(1..10, fn _ -> end)
warning: an expression is always required on the right side of ->. Please provide a value after ->
iex:7
[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
iex(8)> Enum.map(1..10, fn x -> x end)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
iex(9)> for x <- 1..10 do x end
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment