Elixir Blog Posts

The RSS Atom feed is up.

I also added an additional section on the IO Lists definition, since the typespec as shown in the documentation is not quite clear. It turns out iolists are made of ioheads and iotails, and tails cannot be bytes, but heads can. In the type maybe_improper_list(a, b), a is the contents and b the termination, as mentioned in Types and Function Specifications — Erlang System Documentation v29.0.2.

So if iolist is defined as maybe_improper_list(byte() | binary() | iolist(), binary() | [])

Then this works:

iex> :erlang.iolist_to_binary([1 | "2"])
<<1, 50>>

But this breaks with a not very useful error message:

iex> :erlang.iolist_to_binary([1 | 2])
** (ArgumentError) argument error
    :erlang.iolist_to_binary([1 | 2])
1 Like