A.IO.iodata_empty-question-mark

You're seeing just the function iodata_empty-question-mark, go back to A.IO module for more information.

Specs

iodata_empty?(iodata()) :: boolean()

Checks if IO data is empty in "constant" time.

Should only need to loop until it finds one character or binary to stop, unlike IO.iodata_length(iodata) == 0 which needs to perform the complete loop to compute the length first.

Examples

iex> A.IO.iodata_empty?(["", []])
true
iex> A.IO.iodata_empty?('a')
false
iex> A.IO.iodata_empty?(["a"])
false
iex> A.IO.iodata_empty?(["", [], ["" | "c"]])
false

Rationale

Even if IO.iodata_length/1 is a very efficient BIF implemented in C, it has a linear algorithmic complexity and can become slow if invoked on an IO list with many elements.

This is not a far-fetched scenario, and a production use case can easily include "big" IO-lists with:

  • JSON encoding to IO-data of long lists / nested objects
  • loops within HTML templates