anantharaman445
List of nested maps
Hi I’ve a list of nested maps as like this
[
%{
ingredients: [
%{"measuring_unit" => "gms", "name" => "okra/bhindi", "qty" => 450},
%{"measuring_unit" => "tbsp", "name" => "vegetable oil", "qty" => "2"},
%{
"measuring_unit" => "tbsp",
"name" => "desiccated coconut powder",
"qty" => 4
},
%{"measuring_unit" => "tbsp", "name" => "coriander powder", "qty" => 2},
%{"measuring_unit" => "tbsp", "name" => "cumin powder", "qty" => 2},
%{"measuring_unit" => "tbsp", "name" => "ground cumin", "qty" => 1.5},
%{"measuring_unit" => "tbsp", "name" => "cinnamon stick", "qty" => 1},
%{
"measuring_unit" => "tbsp",
"name" => "dried mango powder, also known as amchur",
"qty" => 1
},
%{
"measuring_unit" => "tbsp",
"name" => "red pepper flakes",
"qty" => 0.25
},
%{"measuring_unit" => "tbsp", "name" => "red chili powder", "qty" => 1},
%{"measuring_unit" => "tbsp", "name" => "garam masala", "qty" => 1},
%{"measuring_unit" => "tbsp", "name" => "turmeric powder", "qty" => 0.25},
%{"measuring_unit" => "tbsp", "name" => "salt, or to taste", "qty" => 2},
%{
"measuring_unit" => "tbsp",
"name" => "vegetable oil, divided",
"qty" => 2
}
],
name: "Stuffed Bhindi",
other_ingredients: []
},
%{
ingredients: [
%{"measuring_unit" => "gms", "name" => "okra/bhindi", "qty" => 450},
%{"measuring_unit" => "tbsp", "name" => "vegetable oil", "qty" => "2"},
%{
"measuring_unit" => "tbsp",
"name" => "desiccated coconut powder",
"qty" => 4
},
%{"measuring_unit" => "tbsp", "name" => "coriander powder", "qty" => 2},
%{"measuring_unit" => "tbsp", "name" => "cumin powder", "qty" => 2},
%{"measuring_unit" => "tbsp", "name" => "ground cumin", "qty" => 1.5},
%{"measuring_unit" => "tbsp", "name" => "cinnamon stick", "qty" => 1},
%{
"measuring_unit" => "tbsp",
"name" => "dried mango powder, also known as amchur",
"qty" => 1
},
%{
"measuring_unit" => "tbsp",
"name" => "red pepper flakes",
"qty" => 0.25
},
%{"measuring_unit" => "tbsp", "name" => "red chili powder", "qty" => 1},
%{"measuring_unit" => "tbsp", "name" => "garam masala", "qty" => 1},
%{"measuring_unit" => "tbsp", "name" => "turmeric powder", "qty" => 0.25},
%{"measuring_unit" => "tbsp", "name" => "salt, or to taste", "qty" => 2},
%{
"measuring_unit" => "tbsp",
"name" => "vegetable oil, divided",
"qty" => 2
}
],
name: "Normal Bhindi",
other_ingredients: []
}
]
I just wanted to extract the data where name = “Stuffed Bhindhi”
I tried this ingre_map = Enum.take_while(ingredientslist, fn x -> ingredientslist[:name] == “Stuffed Bhindhi”)
but didn’t work getting nil
Marked As Solved
idi527

How about
Enum.find(ingredients, fn %{name: name} -> name == "Stuffed Bhindi" end)
4
Also Liked
mudasobwa
Creator of Cure
I vote for comprehensions!
for %{name: "Stuffed Bhindi"} = map <- ings, do: map # hd() if there is only one
4
gerbal
In a pipeline if all instances implement Access
ingredients
|> Enum.filter(& &1[:name] == "Stuffed Bhindi")
|> Enum.map(& get_in(&1, [:ingredients, Access.all(), "name"]))
[
["okra/bhindi", "vegetable oil", "desiccated coconut powder",
"coriander powder", "cumin powder", "ground cumin", "cinnamon stick",
"dried mango powder, also known as amchur", "red pepper flakes",
"red chili powder", "garam masala", "turmeric powder", "salt, or to taste",
"vegetable oil, divided"]
]
1
mudasobwa
Creator of Cure
Indeed!
get_in ingrs, [Access.filter(& &1[:name] == "Stuffed Bhindi"), :ingredients, Access.all(), "name"]
1
Popular in Questions
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
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
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Background
Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Other popular topics
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
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
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
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








