Inspect.Algebra.container_doc

You're seeing just the function container_doc, go back to Inspect.Algebra module for more information.
Link to this function

container_doc(left, collection, right, inspect_opts, fun, opts \\ [])

View Source (since 1.6.0)

Specs

container_doc(
  t(),
  [any()],
  t(),
  Inspect.Opts.t(),
  (term(), Inspect.Opts.t() -> t()),
  keyword()
) :: t()

Wraps collection in left and right according to limit and contents.

It uses the given left and right documents as surrounding and the separator document separator to separate items in docs. If all entries in the collection are simple documents (texts or strings), then this function attempts to put as much as possible on the same line. If they are not simple, only one entry is shown per line if they do not fit.

The limit in the given inspect_opts is respected and when reached this function stops processing and outputs "..." instead.

Options

  • :separator - the separator used between each doc
  • :break - If :strict, always break between each element. If :flex, breaks only when necessary. If :maybe, chooses :flex only if all elements are text-based, otherwise is :strict

Examples

iex> inspect_opts = %Inspect.Opts{limit: :infinity}
iex> fun = fn i, _opts -> to_string(i) end
iex> doc = Inspect.Algebra.container_doc("[", Enum.to_list(1..5), "]", inspect_opts, fun)
iex> Inspect.Algebra.format(doc, 5) |> IO.iodata_to_binary()
"[1,\n 2,\n 3,\n 4,\n 5]"

iex> inspect_opts = %Inspect.Opts{limit: 3}
iex> fun = fn i, _opts -> to_string(i) end
iex> doc = Inspect.Algebra.container_doc("[", Enum.to_list(1..5), "]", inspect_opts, fun)
iex> Inspect.Algebra.format(doc, 20) |> IO.iodata_to_binary()
"[1, 2, 3, ...]"

iex> inspect_opts = %Inspect.Opts{limit: 3}
iex> fun = fn i, _opts -> to_string(i) end
iex> opts = [separator: "!"]
iex> doc = Inspect.Algebra.container_doc("[", Enum.to_list(1..5), "]", inspect_opts, fun, opts)
iex> Inspect.Algebra.format(doc, 20) |> IO.iodata_to_binary()
"[1! 2! 3! ...]"