← Back to all TILs

Create A List Of Atoms

elixir Written May 22, 2017

The ~w sigil makes it easy to create a word list -- a list of strings -- where each word is separated by a space.

> ~w(bulbasaur charmander squirtle)
["bulbasaur", "charmander", "squirtle"]

By appending an a onto that sigil construct, you are instructing Elixir that you would instead like a list of atoms.

> ~w(bulbasaur charmander squirtle)a
[:bulbasaur, :charmander, :squirtle]

source

Other posts like this