Use keyword lists for ‘options’-style parameters that contains multiple key value pairs:

def myfunc(arg1, opts \\ []) do
  # Function body

We can call the function above like so:

iex> myfunc "hello", pizza: true, soda: false

which is equivalent to:

iex> myfunc("hello", [pizza: true, soda: false])

The argument values are available as and opts.soda respectively.

Other Examples

Ecto’s query language uses this pattern:

query = from p in EctoBlog.Post, where: == post_id

You can probably guess by now, but the above code is actually:

query = from(p in EctoBlog.Post, [where: == 1])

Yes, the second parameter of the from function is a keyword list.