I can see how it might be hard to agree on a name. What if we just went with your gut then and called it `tap/1`? At some point you've just got to roll with something :D
On Mon, Dec 28, 2020 at 4:04 PM José Valim <jose.va...@dashbit.co> wrote: > This has been discussed a couple times. I would prefer to introduce a > general approach to this, such that: > > |> tap(&IO.inspect(Map.keys(&1)) > > But we always got stuck on what to call said function. > > On Mon, Dec 28, 2020 at 21:07 Zach Daniel <zachary.s.dan...@gmail.com> > wrote: > >> Yeah, this is a great idea. I would love this :) I also agree that it >> would better to do it with an option though. >> >> On Mon, Dec 28, 2020 at 3:01 PM Felipe Stival <v0id...@gmail.com> wrote: >> >>> 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 >>> <https://groups.google.com/d/msgid/elixir-lang-core/CAKC64%2ByAG0XvQwV%3DJq6r78AqU4xsNAivn6kX-Gr-fGPevYfzmg%40mail.gmail.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/CAK-yb0CQThUAaPveb4et%3DwVjcwrko9Tyb-vo-zBQJM0kRwSqRw%40mail.gmail.com >> <https://groups.google.com/d/msgid/elixir-lang-core/CAK-yb0CQThUAaPveb4et%3DwVjcwrko9Tyb-vo-zBQJM0kRwSqRw%40mail.gmail.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/CAGnRm4KmK%2BCDUbMx%2BVeoJgbVu0iOdb4xLw%3DNG2X%3DRzvACLULTA%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KmK%2BCDUbMx%2BVeoJgbVu0iOdb4xLw%3DNG2X%3DRzvACLULTA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > On Mon, Dec 28, 2020 at 4:04 PM José Valim <jose.va...@dashbit.co> wrote: > This has been discussed a couple times. I would prefer to introduce a > general approach to this, such that: > > |> tap(&IO.inspect(Map.keys(&1)) > > But we always got stuck on what to call said function. > > On Mon, Dec 28, 2020 at 21:07 Zach Daniel <zachary.s.dan...@gmail.com> > wrote: > >> Yeah, this is a great idea. I would love this :) I also agree that it >> would better to do it with an option though. >> >> On Mon, Dec 28, 2020 at 3:01 PM Felipe Stival <v0id...@gmail.com> wrote: >> >>> 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 >>> <https://groups.google.com/d/msgid/elixir-lang-core/CAKC64%2ByAG0XvQwV%3DJq6r78AqU4xsNAivn6kX-Gr-fGPevYfzmg%40mail.gmail.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/CAK-yb0CQThUAaPveb4et%3DwVjcwrko9Tyb-vo-zBQJM0kRwSqRw%40mail.gmail.com >> <https://groups.google.com/d/msgid/elixir-lang-core/CAK-yb0CQThUAaPveb4et%3DwVjcwrko9Tyb-vo-zBQJM0kRwSqRw%40mail.gmail.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/CAGnRm4KmK%2BCDUbMx%2BVeoJgbVu0iOdb4xLw%3DNG2X%3DRzvACLULTA%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KmK%2BCDUbMx%2BVeoJgbVu0iOdb4xLw%3DNG2X%3DRzvACLULTA%40mail.gmail.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/CAK-yb0C3pqaE%2BJq02nNxjz3tp7n8g%3DH%2BY%3D8Bqg_LkXuOhqbumg%40mail.gmail.com.