In case it's helpful to see. The function implementation of this would
likely be something like this:

defmodule Function do
def pipe_to(val, fun) when is_function(fun, 1) do
fun.(val)
end
end

Allen Madsen
http://www.allenmadsen.com


On Tue, Aug 13, 2019 at 7:51 PM Allen Madsen <[email protected]>
wrote:

> This wouldn't be possible:
>
> def find_foos(string) do
> fun = Function.pipe_to(&Regex.scan(~r/foo/, &1))
> string
> |> String.upcase()
> |> fun
> end
>
> It's missing the first argument of Function.pipe_to/2. You'd have to do
> something like:
>
> def find_foos(string) do
> fun = &Function.pipe_to(&1, &Regex.scan(~r/foo/, &1))
> string
> |> String.upcase()
> |> fun.()
> end
>
> Though, I'm not sure what happens when there's shadowing of anonymous
> variables.
>
> Allen Madsen
> http://www.allenmadsen.com
>
>
> On Tue, Aug 13, 2019 at 5:34 PM Wiebe-Marten Wijnja <[email protected]>
> wrote:
>
>> On 13-08-2019 11:03, José Valim wrote:
>>
>>
>> [...] if I have experience with other functional programming languages, I
>> would expect to be able to write this:
>>
>> def find_foos(string) do
>>   fun = &Regex.scan(~r/foo/, &1)
>>   string
>>   |> String.upcase()
>>   |> fun
>> end
>>
>> But that won't work, it has to be "fun.()". So I think we need to work
>> consistently with calls. Allowing something that is not a call will be
>> confusing.
>>
>> This is a good counter-argument. 👍Maybe it is possible to super-charge
>> the &-macro to even work in those cases, but it might become too
>> abuse-enabling if we do.
>>
>> Playing devil’s advocate a little, however: what would you expect to
>> happen when someone does the same thing with Function.pipe_to (or
>> whatever name is decided upon)?:
>>
>>
>> def find_foos(string) do
>>   fun = Function.pipe_to(&Regex.scan(~r/foo/, &1))
>>   string
>>   |> String.upcase()
>>   |> fun
>> end
>>
>> ~Marten/Qqwy
>> ​
>>
>> --
>> 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/9ec4915c-436a-300f-7501-e5231e356c36%40resilia.nl
>> <https://groups.google.com/d/msgid/elixir-lang-core/9ec4915c-436a-300f-7501-e5231e356c36%40resilia.nl?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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cu09W4i1iKn5yp0mO%3D7qAT6nAU2Vn2Jo5mxF_EnyiTQzw%40mail.gmail.com.

Reply via email to