-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Dynamically Generating Atoms as an elixir til
- Loading branch information
1 parent
ae12914
commit ebd901f
Showing
2 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
``` |