Created
January 7, 2017 11:54
-
-
Save simonewebdesign/9a21e4724fe2e7042e1543c6bc514c0a to your computer and use it in GitHub Desktop.
Ways of looping through a collection/enumerable in Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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