Created
September 19, 2022 04:30
-
-
Save mudssrali/a1446a47f52bbc9e05a88aa070e3b93a to your computer and use it in GitHub Desktop.
Snippets for list generation in Elixir
This file contains hidden or 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
# Using for construct | |
# [0, 0, 0] | |
for _x <- 0..2, do: 0 | |
# [0, 2, 4, 6, 8] | |
for x <- 0..4, do: x * 2 | |
# List of 5 random numbers | |
for _x <- 0..4, do: System.unique_integer([:positive]) | |
# Using Enum.map | |
# [0, 0, 0] | |
Enum.map(0..2, fn _x -> 0 end) | |
# [0, 2, 4, 6, 8] | |
Enum.map(0..4, fn x -> x * 2 end) | |
# List of 5 random numbers | |
Enum.map(0..4, fn _x -> System.unique_integer([:positive]) end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment