Add a `label:` option to IO.inspect

36 views
Skip to first unread message

pragdave

unread,
Feb 19, 2018, 8:32:52 PM2/19/18
to elixir-lang-core
When I use IO.inspect in a pipeline, I often find myself wanting to tag the output with some kind of label:

~~~ elixir
get_name()
|> IO.inspect()
|> lookup_score()
|> IO.inspect
~~~

so I sometimes write a trivial helper

~~~
def dump(value, label) do
  IO.puts "#{label}: #{inspect value}"
  value
end
~~~

This means I can write:

~~~ elixir
get_name()
|> dump("Name is")
|> lookup_score()
|> dump("score")
~~~

Any chance we could

1. Add a `label: "text"` option to IO.inspect?

2. Add a new signature to IO.inspect, so that

  ~~~~
  def inspect(value, label) when  is_binary(label) do
    inspect(value, label: label)
  end
  ~~~

I'd happily do the PR


Dave


Paul Schoenfelder

unread,
Feb 19, 2018, 8:40:07 PM2/19/18
to elixir-l...@googlegroups.com
You can already do this today with IO.inspect(foo, label: "label") :)

Paul 

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/402e74bd-6c13-4433-b5f1-b6a42a2813d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pragdave

unread,
Feb 19, 2018, 8:45:23 PM2/19/18
to elixir-lang-core
Damn. That was quick.



(hides head in shame)
Reply all
Reply to author
Forward
0 new messages