🪄 Elixir's magic word-list sigil

Notes

Sometimes it’s a pain to write long lists…

Have you ever forgotten to remove that last trailing comma? Yeah, me too. 🤦

Thankfully, there’s a sigil that lets us type less (and have more power!)”

The word-list sigil (~w) only requires spaces between words. No commas. No quotes.

iex> ~w(aragorn legolas gimli)
=> ["aragorn", "legolas", "gimli"]

And here’s the magical bonus ✨ – it accepts modifiers at the end.

Type in a at the end to turn that word list into a list of atoms:

iex> ~w(aragorn legolas gimli)a
=> [:aragorn, :legolas, :gimli]

Nice. Not even Dumbledore could do better.

Want the latest Elixir Streams in your inbox?

    No spam. Unsubscribe any time.