shahryarjb
Looping list and add to tuple
Hello, I have a list and want to move it to map or tuple or I have a 3 map records of Repo.all, then after editing this record I want to save these to a map
[a, b, c] |> Enum.map(fn item -> item + 1 end)
now I need to save them to a map like
[a, b, c] |> Enum.map(fn item -> item + 1 end) |> ADD_TO_MAP_OR_TUPLE
how can I do this?
Marked As Solved
mudasobwa
Creator of Cure
To produce a map, you might use Enum.into/3 directly:
[:a, :b, :c] |> Enum.into(%{}, fn item -> {item, to_string(item)} end)
#⇒ %{a: "a", b: "b", c: "c"}
3
Also Liked
mudasobwa
Creator of Cure
You are trying to convert map to tuple with List.to_tuple/1. It obviously does not work. It works on your initial mapped data:
3
mudasobwa
Creator of Cure
I am lost. It does not convert anything to the list. Please clarify what output do you expect to receive.
2
mudasobwa
Creator of Cure
NobbZ
What do you want to look the result like?
Perhaps take a look at List.to_tuple/1.
1
shahryarjb
This is what I need, but it converts to a list, but I need tuple too, is there a cod for tuple ?
1
Popular in Questions
Background
Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
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 the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it.
I’m very interested in Elixir,...
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
Student & New to elixir. Nice language.
I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
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
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
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







