Skip to content

Instantly share code, notes, and snippets.

@MrAlexLau
Last active December 18, 2017 17:02
Show Gist options
  • Save MrAlexLau/e13858cba7ccb8e316acdfdee5f8ca62 to your computer and use it in GitHub Desktop.
Save MrAlexLau/e13858cba7ccb8e316acdfdee5f8ca62 to your computer and use it in GitHub Desktop.
adding to elixir lists
# See https://hexdocs.pm/elixir/List.html for reference
iex> list = [1, 2, 3]
iex> [list | 4] # fast, but probably not what you want
[[1, 2, 3] | 4]
iex> [0 | list] # fast
[0, 1, 2, 3]
iex> list ++ [4] # slow
[1, 2, 3, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment