Skip to content

Instantly share code, notes, and snippets.

@mudssrali
Created September 19, 2022 04:30
Show Gist options
  • Save mudssrali/a1446a47f52bbc9e05a88aa070e3b93a to your computer and use it in GitHub Desktop.
Save mudssrali/a1446a47f52bbc9e05a88aa070e3b93a to your computer and use it in GitHub Desktop.
Snippets for list generation in Elixir
# 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