chrisdel101
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
Marked As Solved
sodapopcan
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
Also Liked
codeanpeace
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
Popular in Questions
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I would like to know what is the best IDE for elixir development?
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
I would like to know what is the best IDE for elixir development?
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New







