Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

elixir

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?

like image 404
ItsASecret Avatar asked Apr 10 '15 16:04

ItsASecret


2 Answers

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.

like image 98
Patrick Oscity Avatar answered Sep 21 '22 16:09

Patrick Oscity


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

like image 40
Philip Avatar answered Sep 20 '22 16:09

Philip