Elixir Language

Sigils

Build a list of strings

iex> ~w(a b c)
["a", "b", "c"]

Build a list of atoms

iex> ~w(a b c)a
[:a, :b, :c]

Custom sigils

Custom sigils can be made by creating a method sigil_X where X is the letter you want to use (this can only be a single letter).

defmodule Sigils do
  def sigil_j(string, options) do
    # Split on the letter p, or do something more useful
    String.split string, "p"
  end
  # Use this sigil in this module, or import it to use it elsewhere
end

The options argument is a binary of the arguments given at the end of the sigil, for example:

~j/foople/abc # string is "foople", options are 'abc'
# ["foo", "le"]

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow