skedaddl3
How to access all values in a list of map using an identifier?
I have a list of maps containing different values
list =
[
%Samp1{
id: "11111",
sample_data1: "",
sample_data2: "",
other_datas: {}
},
%Samp2{
id: "22222",
sample_data1: "",
sample_data2: "",
other_datas: {}
},
%Samp3{
id: "33333",
sample_data1: "",
sample_data2: "",
other_datas: {}
},
]
How can i get all the values along with the ID i want to match, For Example:
if id == “33333” i want to traverse and get all values with it, so the expected result should be:
%Samp3{
id: "33333",
sample_data1: "",
sample_data2: "",
other_datas: {}
},
I tried Enum.map but I can only fetch single value each
list |> Enum.map(& &1.id)
Result: ["11111", "22222", "33333"]
Marked As Solved
trisolaran
Also Liked
benwilson512
Author of Craft GraphQL APIs in Elixir with Absinthe
Hi @skedaddl3 the function you’re looking for is Enum — Elixir v1.20.2 whoops! I mean Enum — Elixir v1.20.2
2
kokolegorille
Enum.find will stop after first match… probably for comprehension, with filter on id would do the trick.
1
Last Post!
skedaddl3
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
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
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
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
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
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
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
- #forms
- #api
- #metaprogramming
- #security
- #hex









