Skip to content

chore: Add printable_limit and limit to IO.inspect doc examples #14646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/elixir/lib/io.ex
Original file line number Diff line number Diff line change
Expand Up @@ -467,32 +467,36 @@ defmodule IO do

## Examples

The following code:

IO.inspect(<<0, 1, 2>>, width: 40)

Prints:

<<0, 1, 2>>

We can use the `:label` option to decorate the output:
You can use the `:label` option to decorate the output:

IO.inspect(1..100, label: "a wonderful range")

Prints:

a wonderful range: 1..100

The `:label` option is especially useful with pipelines:
Inspect truncates large inputs by default. The `:printable_limit` controls
the limit for strings and other string-like constructs (such as charlists):

[1, 2, 3]
|> IO.inspect(label: "before")
|> Enum.map(&(&1 * 2))
|> IO.inspect(label: "after")
|> Enum.sum()
"abc"
|> String.duplicate(9001)
|> IO.inspect(printable_limit: :infinity)

Prints:
For containers such as lists, maps, and tuples, the number of entries
is managed by the `:limit` option:

before: [1, 2, 3]
after: [2, 4, 6]
1..100
|> Enum.map(& {&1, &1})
|> Enum.into(%{})
|> IO.inspect(limit: :infinity)

"""
@spec inspect(item, inspect_opts) :: item when item: var
Expand Down