It happens that the `tee/2` function was not merged to elixir core because 
not too much people could bring real-life examples for using it except for 
debugging.

But for those who liked the idea and want to use the `tee/2` function, I've 
created the [`plumbing`](https://github.com/kelvinst/plumbing) package.

On Monday, January 15, 2018 at 11:26:02 PM UTC-2, Kelvin Raffael Stinghen 
wrote:
>
> The `tee/2` idea is wonderful!! This way we can use it for any function, 
> not just `IO.inspect`. One word: PERFECT!!!
>
> I am opening a PR for it...
>
> Best,
> Kelvin Stinghen
> kelvin.sting...@me.com
>
> On Jan 15, 2018, at 19:27, José Valim <jose.va...@gmail.com> wrote:
>
> The more general construct here would be a tee 
> <https://en.wikipedia.org/wiki/Tee_(command)>:
>
> ["thing1", "thing2"]
> |> generate_more_things()
> |> IO.inspect(transform: &length/1)
> |> do_something_with_things()
>
>
> could be written as:
>
>
> ["thing1", "thing2"]
> |> generate_more_things()
> |> tee(&IO.inspect(length(&1))
> |> do_something_with_things()
>
>
> Note IO.inspect is already a tee.
>
> *José Valimwww.plataformatec.com.br 
> <http://www.plataformatec.com.br/>Founder and Director of R&D*
>
> On Mon, Jan 15, 2018 at 10:14 PM, Martin Svalin <martin.sva...@gmail.com> 
> wrote:
>
>> `map` would have the connotation of applying a function to all elements 
>> of a collection. `apply` would more directly have the connotation of 
>> running a function with some arguments.
>>
>> `IO.inspect(value, apply: &length/1)`
>>
>> I like the idea of being able to narrow down what I'm inspecting during 
>> the print-debugging workflow I inevitably regress to. `nested_structure |> 
>> IO.inspect(apply: & get_in(&1, [:foo, :bar, :baz]))`. Thumbs up for the 
>> idea.
>>
>> mån 15 jan. 2018 kl 17:31 skrev Marcus Gartner <mar...@lob.com>:
>>
>>> Doh! I should have realized the issue with executing the function 
>>> passed. 
>>>
>>> I like the idea of a transform option that can be passed.
>>>
>>> IO.map makes sense in my example, but wouldn't make sense to me if the 
>>> pipeline wasn't dealing with an enumerable, and it would be nice if this 
>>> feature was general enough to work idiomatically with any possible values. 
>>>
>>> On Sat, Jan 13, 2018 at 7:38 PM OvermindDL1 <overmind...@gmail.com> 
>>> wrote:
>>>
>>>> Or call it `map` as it's shorter and perfectly descriptive.  I've made 
>>>> a few variants of this myself and I'd love it built into IO.inspect.
>>>>
>>>> On Jan 12, 2018 16:31, "Greg Vaughn" <gvau...@gmail.com> wrote:
>>>>
>>>>> I like the original idea and would like to suggest another approach. 
>>>>> What if there were an additional Inspect.Opts of :transform? It then 
>>>>> would 
>>>>> enable this sort of thing:
>>>>>
>>>>> ["thing1", "thing2"]
>>>>> |> generate_more_things()
>>>>> |> IO.inspect(transform: &length/1)
>>>>> |> do_something_with_things()
>>>>>
>>>>> -Greg Vaughn
>>>>>
>>>>> > On Jan 12, 2018, at 5:18 PM, José Valim <jose.va...@gmail.com> 
>>>>> wrote:
>>>>> >
>>>>> > Thanks for the proposal!
>>>>> >
>>>>> > Unfortunately that would make us unable to inspect functions 
>>>>> themselves, which is a valid argument to IO.inspect after all.
>>>>> >
>>>>> > Imagine the confusion of trying to inspect a pipeline that may emit 
>>>>> an anonymous function only to find it is being executed instead.
>>>>> >
>>>>> >
>>>>> >
>>>>> > José Valim
>>>>> > www.plataformatec.com.br
>>>>> > Founder and Director of R&D
>>>>> >
>>>>> > On Fri, Jan 12, 2018 at 10:59 PM, <mar...@lob.com> wrote:
>>>>> > I often find myself wanting to inspect things in the middle of a 
>>>>> chain of pipes, but I don’t always want to inspect the return values 
>>>>> as-is. 
>>>>> Sometimes I want to inspect sub-attributes or call functions on the 
>>>>> return 
>>>>> values to inspect them.
>>>>> >
>>>>> > For example, imagine the contrived pipeline below.
>>>>> >
>>>>> > ["thing1", "thing2"]
>>>>> > |> generate_more_things()
>>>>> > |> do_something_with_things()
>>>>> >
>>>>> > If I want to know the length of the list returned by 
>>>>> generate_more_things/1, I would do this:
>>>>> >
>>>>> > ["thing1", "thing2"]
>>>>> > |> generate_more_things()
>>>>> > |> (fn things ->
>>>>> >   things |> length() |> IO.inspect()
>>>>> >   things
>>>>> > end).()
>>>>> > |> do_something_with_things()
>>>>> >
>>>>> > If IO.inspect can take a function as an argument, print the 
>>>>> inspection of the result of calling that function, but still return the 
>>>>> un-altered input, I could do this:
>>>>> >
>>>>> > ["thing1", "thing2"]
>>>>> > |> generate_more_things()
>>>>> > |> IO.inspect(fn things -> length(things) end)
>>>>> > |> do_something_with_things()
>>>>> >
>>>>> > Or even:
>>>>> >
>>>>> > ["thing1", "thing2"]
>>>>> > |> generate_more_things()
>>>>> > |> IO.inspect(&length/1)
>>>>> > |> do_something_with_things()
>>>>> >
>>>>> > I think this would aid during debugging and be a useful feature in 
>>>>> the standard library. I'd love to implement and contribute on this, but I 
>>>>> wanted to see if such a thing would be accepted before beginning work.
>>>>> >
>>>>> > Open to feedback!
>>>>> >
>>>>> > --
>>>>> > 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/4e2bfad0-b745-4059-8736-996e641c7bb2%40googlegroups.com
>>>>> .
>>>>> > For more options, visit https://groups.google.com/d/optout.
>>>>> >
>>>>> >
>>>>> > --
>>>>> > 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/CAGnRm4KAvw%2BwWnh7d60%3DvKEkuLvWfyoh4XuM9rbuxz_CaLg9%3DA%40mail.gmail.com
>>>>> .
>>>>> > For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>> --
>>>>> 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/6CF01F3F-5848-4E19-BCA1-9D256824D6E0%40gmail.com
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> -- 
>>>>
>>> You received this message because you are subscribed to a topic in the 
>>>> Google Groups "elixir-lang-core" group.
>>>> To unsubscribe from this topic, visit 
>>>> https://groups.google.com/d/topic/elixir-lang-core/TUkmNHI4IbI/unsubscribe
>>>> .
>>>> To unsubscribe from this group and all its topics, 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/CAJhqboH_tYYRPFWf8HuVJru5phmOmU7tK_PDWVca36mUfWhJ8Q%40mail.gmail.com
>>>>  
>>>> <https://groups.google.com/d/msgid/elixir-lang-core/CAJhqboH_tYYRPFWf8HuVJru5phmOmU7tK_PDWVca36mUfWhJ8Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> -- 
>>> 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/CAONCvEwH7a8GzHtQb78gGo0H95BJVxq8KPAcvGy3cZKYXr9nGA%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/elixir-lang-core/CAONCvEwH7a8GzHtQb78gGo0H95BJVxq8KPAcvGy3cZKYXr9nGA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> -- 
>> 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/CAAHw6CLuxuNsnk-JWCTPtCr4_fsQG13eUQC3ajW5Ca2LkWwdLQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/CAAHw6CLuxuNsnk-JWCTPtCr4_fsQG13eUQC3ajW5Ca2LkWwdLQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> 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/CAGnRm4Ji7kAjv5i4_04AVp-hae4ghj1DgZx1zr%2B4LyGBYpj5_A%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Ji7kAjv5i4_04AVp-hae4ghj1DgZx1zr%2B4LyGBYpj5_A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
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/89564865-7b49-4987-ab94-667eb86c6302%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to