How to use IO.inspect on a long list without trimming it?

Elixir

Elixir Problem Overview


When I do:

IO.inspect [:right, :top, :left, ...very_long_list]

I only get the first items (it's a list of moves to solve a 15-puzzle) like this:

[:right, :top, :left, :bot, :bot, :left, :top, :top, :right, :right, :bot,
  :left, :bot, :left, :top, :right, :bot, :right, :top, :top, :left, :bot,
  :left, :top, :right, :right, :bot, :bot, :left, :top, :top, :left, :bot,
  :right, :top, :right, :bot, :left, :left, :top, :right, :bot, :right, :top,
  :left, :left, :bot, ...] # => See the '...'
                                instead, I would like 
                                to get the complete list

How can I tell IO.inspect to not trim the list? Is there an option or something?

Elixir Solutions


Solution 1 - Elixir

See Inspect.Opts for a description of the available options:

> * :limit - limits the number of items that are printed for tuples, bitstrings, maps, lists and any other collection of items. It does not > apply to strings nor charlists and defaults to 50. If you don't want > to limit the number of items to a particular number, use > :infinity.

Thus you can pass limit: :infinity to print all elements:

IO.inspect(list, limit: :infinity)

For strings and charlists there is a special option called :printable_limit. Both of these options can be combined to ensure that all elements are fully printed.

Solution 2 - Elixir

For those who wants this for strings which above solution is not for.

Use printable_limit: integer/:infinity https://hexdocs.pm/elixir/Inspect.Opts.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionItsASecretView Question on Stackoverflow
Solution 1 - ElixirPatrick OscityView Answer on Stackoverflow
Solution 2 - ElixirPhilipView Answer on Stackoverflow