shahryarjb

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

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"}

Also Liked

mudasobwa

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:

mudasobwa

mudasobwa

Creator of Cure

I am lost. It does not convert anything to the list. Please clarify what output do you expect to receive.

mudasobwa

mudasobwa

Creator of Cure

Please refer to the answer by @NobbZ then. |> List.to_tuple() after map would do.

NobbZ

NobbZ

What do you want to look the result like?

Perhaps take a look at List.to_tuple/1.

shahryarjb

shahryarjb

This is what I need, but it converts to a list, but I need tuple too, is there a cod for tuple ?

Where Next?

Popular in Questions Top

Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
lastday4you
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
yawaramin
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
LegitStack
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
romenigld
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
Kagamiiiii
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
vertexbuffer
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
mgjohns61585
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
romenigld
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
lk-geimfari
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
vertexbuffer
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
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
mgjohns61585
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
vonH
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
siddhant3030
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement