chrisdel101
How to use conditional inside Enum iterator - error:cannot invoke remote function Kernel.elem/2 inside a match
When first or last item in list is found, do something.
Even simply trying to check for this fails with error. How can I do it? Below is checking if item tuple index 1 is 0 (first item in list).
l = [owner: 0, developer: 1, admin: 2, editor: 3, contributor: 4, viewer: 5]
Enum.map(l, fn x ->
cond do
#check if tuple elem is 0
elem(x,1) = 0->
"hello"
end
end)
end
Marked As Solved
kokolegorille
Also Liked
kokolegorille
It is also possible to write an anonymous function with multiple heads.
Enum.map(l, fn
{_, 0} -> "hello"
_ -> ...
end)
No need for a case ![]()
UPDATE: it should be {_, 1} → “hello”
2
Last Post!
kokolegorille
It is also possible to write an anonymous function with multiple heads.
Enum.map(l, fn
{_, 0} -> "hello"
_ -> ...
end)
No need for a case ![]()
UPDATE: it should be {_, 1} → “hello”
2
Popular in Questions
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
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’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
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
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









