New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show syntax for function capture in a pipeline #3916

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@wsmoak
Contributor

wsmoak commented Oct 25, 2015

I tried to use function capture syntax in a pipeline |> &(&1 != Empty) and got the error message

** (ArgumentError) cannot pipe Agent.get(Process.whereis(agent_name(@last_row, col)), &&1) into &&1 != Empty.(), can only pipe into local calls foo(), remote calls Foo.bar() or anonymous functions calls foo.()

I tried surrounding it with parentheses thinking it was just a problem with |> binding more tightly than something else, and that didn't work either. Stack Overflow [1] solved it with even more parentheses: (&(&1 != Empty)).(). (See [2].)

Assuming this is something reasonable to do in a pipeline, this adds an example of the function capture syntax to the list of possibilities in the error message.

[1] http://stackoverflow.com/questions/24593967/how-to-pass-an-anonymous-function-to-the-pipe-in-elixir
[2] https://github.com/wsmoak/connect_four/blob/master/lib/connect_four/board.ex#L121

@josevalim

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Oct 25, 2015

Member

Thank you @wsmoak! The reason why (& ...).() is not listed is:

  1. We don't want to encourage such format. One should really use a private function for it
  2. It theoretically is the same is as foo.()

For those two reasons, I am more inclined to leave the error message as is. :)

Member

josevalim commented Oct 25, 2015

Thank you @wsmoak! The reason why (& ...).() is not listed is:

  1. We don't want to encourage such format. One should really use a private function for it
  2. It theoretically is the same is as foo.()

For those two reasons, I am more inclined to leave the error message as is. :)

@wsmoak

This comment has been minimized.

Show comment
Hide comment
@wsmoak

wsmoak Oct 26, 2015

Contributor

works for me! thanks @josevalim.

Contributor

wsmoak commented Oct 26, 2015

works for me! thanks @josevalim.

@wsmoak wsmoak closed this Oct 26, 2015

@wsmoak wsmoak deleted the wsmoak:patch-2 branch Oct 26, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment