mirror of
https://github.com/jbranchaud/til
synced 2026-01-07 09:08:01 +00:00
Add Word Lists For Atoms as an elixir til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
|||||||
warrant a full blog post. These are mostly things I learn by pairing with
|
warrant a full blog post. These are mostly things I learn by pairing with
|
||||||
smart people at [Hashrocket](http://hashrocket.com/).
|
smart people at [Hashrocket](http://hashrocket.com/).
|
||||||
|
|
||||||
_438 TILs and counting..._
|
_439 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -86,6 +86,7 @@ _438 TILs and counting..._
|
|||||||
- [Expose Internal Representation](elixir/expose-internal-representation.md)
|
- [Expose Internal Representation](elixir/expose-internal-representation.md)
|
||||||
- [List Functions For A Module](elixir/list-functions-for-a-module.md)
|
- [List Functions For A Module](elixir/list-functions-for-a-module.md)
|
||||||
- [Replace Duplicates In A Keyword List](elixir/replace-duplicates-in-a-keyword-list.md)
|
- [Replace Duplicates In A Keyword List](elixir/replace-duplicates-in-a-keyword-list.md)
|
||||||
|
- [Word Lists For Atoms](elixir/word-lists-for-atoms.md)
|
||||||
|
|
||||||
### Git
|
### Git
|
||||||
|
|
||||||
|
|||||||
34
elixir/word-lists-for-atoms.md
Normal file
34
elixir/word-lists-for-atoms.md
Normal 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)
|
||||||
Reference in New Issue
Block a user