1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-05 08:08:02 +00:00

Add Word Lists For Atoms as an elixir til

This commit is contained in:
jbranchaud
2016-06-27 07:44:44 -05:00
parent ace0dacbc4
commit 2070ffa7c5
2 changed files with 36 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
# Word Lists For Atoms
The `~w` sigil works similarly to Ruby's `%w` (word array notation). It
allows you to create a list of words (namely, strings).
```elixir
~w(one two three)
["one", "two", "three"]
```
It sets itself apart though with some modifiers. The default behavior
matches the `s` modifier (for strings).
```elixir
> ~w(one two three)s
["one", "two", "three"]
```
Where it gets more interesting is with the `a` modifier allowing you to
create a list of atoms.
```elixir
> ~w(one two three)a
[:one, :two, :three]
```
Note: there is a third modifier, `c`, for char lists.
```elixir
> ~w(one two three)c
['one', 'two', 'three']
```
[source](http://elixir-lang.org/getting-started/sigils.html)