I'm 100% in for this as a `:with` or `:apply` option for IO.inspect/2. I believe adding it as a new function may add unnecessary cognitive overhead.
On Mon, Dec 28, 2020, 16:49 Jonathan Moraes <altjohn...@gmail.com> wrote: > Hello alchemists, > > I have a simple yet powerful proposal for an inspection function that can > apply a desired function in a value and return the value itself. > > For example, if today I want to inspect the keys of a given map inside a > chain of pipes, I need to do the following: > > ... > |> map > |> inspect_keys() > |> ... > > defp inspect_keys(map) do > IO.inspect(Map.keys(map)) > map > end > > Another example: if I want to count an Enumerable inside a function: > > defp my_function(param) do > list = build_list(param) > IO.inspect(Enum.count(list)) > list > end > > With a function that can inspect using a function AND return the value > itself, both examples can be simplified: > > ... > |> map > |> IO.inspect_with(&Map.keys/1) > |> ... > > defp my_function(param) do > param > |> build_list() > |> IO.inspect_with(&Enum.count/1) > end > > Since the second parameter from IO.inspect/2 is a keyword list of options, > @v0idpwn (from Elixir Brasil Telegram group) suggested a new option called > :apply. For example: > > IO.inspect([1, 2, 3], apply: &Enum.count/1) > > -- > 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-core+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/b0a390d1-9530-492c-b1fb-8ead8c9b938an%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/b0a390d1-9530-492c-b1fb-8ead8c9b938an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAKC64%2ByAG0XvQwV%3DJq6r78AqU4xsNAivn6kX-Gr-fGPevYfzmg%40mail.gmail.com.