Printing anonymous functions with ampersand

Is there anyway to print this &1?

I usually don’t know what the value is since was written by a generator, and doing IO.inspect(&1) gives an error.

Example Usage:

 def create(conn, %{"employee" => %{"email" => email}}) do
    if employee = Staff.get_employee_by_email(email) do
        Staff.deliver_employee_confirmation_instructions(
           employee,
           &Routes.employee_confirmation_url(conn, :edit, &1)
         )
  end

Did you include the capture operator aka the leading &?
In order to use &1, it needs to be &IO.inspect(&1).

Partials and function captures in Elixir | Erlang/Elixir Syntax: A Crash Course
Understanding the & (capture operator) in Elixir | Dockyard

2 Likes

To expand a bit, where did you put the IO.inpect(&1)? I could be wrong, but something is telling me you put it outside the capture expression. &Routes.employee_confirmation_url(conn, :edit, IO.inspect(&1)) should do the trick.

2 Likes

Great! Thanks. I’ve fighting with this one for awhile.
I was doing both of those things wrong, and so now it’s working.