I like this proposal.

   - It doesn't add any new syntax constructs or special cases to the 
   language, correct? I know opinions vary, but I think this is a strength of 
   the proposal.
   - To me "&1" happens to also serve as a convenient visual indicator of 
   "where the value's gonna go." It's subjective, but for me it's just as 
   effective as the idea of using "_" that some people have mentioned, while 
   not changing or adding to the meaning of "_".
   - I found it quite intuitive
   - I also found it more clear than the existing (&foo..).() I see today. 
   I've never written code this way and found it a little odd to read at 
   first, but have since seen in in other code bases.

My only quibble is the name. pipe_to makes sense, but it also feels like it 
describes the use case more than describing what the function does. Am I 
correct in thinking this simply takes the first argument and passes it to 
the function capture on the right when it executes it?

A few of these have been floated already, but words that come to mind...

   - Function.call
   - Function.execute
   - Function.run
   - Function.dispatch
   - Function.apply
   - Function.send

All that said, I'd hate to see naming alone get in the way of the proposal, 
I'm in favor of it even as is.

On Friday, August 9, 2019 at 7:28:25 AM UTC-7, José Valim wrote:
>
> Hi everyone,
>
> With the addition of Function.identity/1, I would like to propose another 
> function to the Function module: pipe_to/2.
>
> The idea is that instead of:
>
> "foo
> |> String.upcase()
> |> (&Regex.scan(~r/foo/, &1)).()
>
> One can do:
>
> "foo
> |> String.upcase()
> |> Function.pipe_to(&Regex.scan(~r/foo/, &1))
>
> Or if you import it before:
>
> "foo
> |> String.upcase()
> |> pipe_to(&Regex.scan(~r/foo/, &1))
>
> While I wouldn't write the "pipe to anonymous" code, I have seen enough 
> code in the wild that uses it that having a more readable (albeit more 
> verbose) approach in the language sounds reasonable to me. The 
> implementation can be inlined by the compiler to avoid the extra dispatch 
> cost.
>
> What are your thoughts? If you "pipe to anonymous functions" in your code 
> today, would you prefer to use the new function? Yes/no? Why?
>
> Thank you,
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/030cb11c-9f85-4d8b-b7a6-fb4e16565445%40googlegroups.com.

Reply via email to