From 76132271ac3357da0b75d159ea29fcc74e27781d Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 24 Feb 2017 16:32:55 -0600 Subject: [PATCH] Fix file that was accidentally emptied, #37 --- elixir/dynamically-generating-atoms.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/elixir/dynamically-generating-atoms.md b/elixir/dynamically-generating-atoms.md index e69de29..3c26cdf 100644 --- a/elixir/dynamically-generating-atoms.md +++ b/elixir/dynamically-generating-atoms.md @@ -0,0 +1,15 @@ +# Dynamically Generating Atoms + +> Atoms are constants where their name is their own value. + +The use of atoms like `:ok` and `:error` show up all over the place in +Elixir. These are atoms that tend to be statically defined. Atoms can also +be dynamically defined using string interpolation. + +For example, I can generate a handful of atoms by mapping over a range of +integers. + +```elixir +> Enum.map(1..5, &(:"some_atom_#{&1}")) +[:some_atom_1, :some_atom_2, :some_atom_3, :some_atom_4, :some_atom_5] +```