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
The error is here… == not =
1
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
Popular in Questions
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
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
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
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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 have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217
Let’s say I have a map with required and optional k...
New
Other popular topics
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
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 that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New








