I was curious if this is possible using the Enum module, since Patrick Ocity's answer relies on Comprehensions , which look just like a wrapper for the Enum module.
The answer is yes. I tried Enum.each first. Which mysteriously just printed ok on the screen, but what does Enum.each ; it always returns an atom :ok .
I thought Enum.map would be better since it will return a list of results. Take a look:
<%= Enum.map(@list, fun(item) -> %> <p><%= item %></p> <% end) %>
EEx works almost the same as ERB . In the ERB example, you passed a “block”, which is similar to a lambda or anonymous function, to each . In my example, EEx fn (item) -> is replaced with do |item| .
So, now you can not only iterate over Lists , but you can experiment with a wider range of functions that use an anonymous function that controls the template.
Breedly
source share