Skip to content

Commit 9b729ca

Browse files
vasspilkajosevalim
authored andcommitted
Add printable_limit and limit to IO.inspect doc examples (#14646)
1 parent 8cba20c commit 9b729ca

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lib/elixir/lib/io.ex

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -467,32 +467,36 @@ defmodule IO do
467467
468468
## Examples
469469
470+
The following code:
471+
470472
IO.inspect(<<0, 1, 2>>, width: 40)
471473
472474
Prints:
473475
474476
<<0, 1, 2>>
475477
476-
We can use the `:label` option to decorate the output:
478+
You can use the `:label` option to decorate the output:
477479
478480
IO.inspect(1..100, label: "a wonderful range")
479481
480482
Prints:
481483
482484
a wonderful range: 1..100
483485
484-
The `:label` option is especially useful with pipelines:
486+
Inspect truncates large inputs by default. The `:printable_limit` controls
487+
the limit for strings and other string-like constructs (such as charlists):
485488
486-
[1, 2, 3]
487-
|> IO.inspect(label: "before")
488-
|> Enum.map(&(&1 * 2))
489-
|> IO.inspect(label: "after")
490-
|> Enum.sum()
489+
"abc"
490+
|> String.duplicate(9001)
491+
|> IO.inspect(printable_limit: :infinity)
491492
492-
Prints:
493+
For containers such as lists, maps, and tuples, the number of entries
494+
is managed by the `:limit` option:
493495
494-
before: [1, 2, 3]
495-
after: [2, 4, 6]
496+
1..100
497+
|> Enum.map(& {&1, &1})
498+
|> Enum.into(%{})
499+
|> IO.inspect(limit: :infinity)
496500
497501
"""
498502
@spec inspect(item, inspect_opts) :: item when item: var

0 commit comments

Comments
 (0)