roganjoshua
Retrieving information from a List of maps?
(Customerbuilder.GitLab.get!("/projects/5112/pipelines/245667/variables", [{"Accept", "Application/json"}, {"PRIVATE-TOKEN", token}]) |> Map.get(:body),
This is an array of maps coming from gitlab
[
%{
"key" => "CUSTOMER",
"raw" => false,
"value" => "EOG.Acme.ManualXML",
"variable_type" => "env_var"
},
%{
"key" => "TRIGGER_PAYLOAD",
"raw" => false,
"value" => "{\"variables\":{\"CUSTOMER\":\"EOG.Acme.ManualXML\",\"VERSION\":\"Version-8.6.2\"},\"id\":\"5112\",\"ref\":\"main\"}",
"variable_type" => "file"
},
%{
"key" => "VERSION",
"raw" => false,
"value" => "Version-8.6.2",
"variable_type" => "env_var"
}
]
I want to put the version and customer into a new struct or something so I can pass it to a heex template. I need to add some other details like if the build is running/failed/success.
This seems easy but I am finding this difficult ![]()
|> Enum.into(%{ “key” => key})
|> Map.get(:body), :key)
|> Map.get(:body), “key”)
|> [ key: “CUSTOMER” ]
|> Map.get(:body) |> [ key: “CUSTOMER” ]
Most Liked
benwilson512
Honestly though if you’re this new to the language… don’t. ChatGPT is as often wrong as it is right with Elixir and if you’re at the phase where you’re not sure how to pass a function to Enum.map, how are you supposed to tell the difference?
dimitarvp
No, this is a single record. If you put |> Map.new() at the end of the above processing you’ll get a single map. To have a list of maps / records then use Enum.map.
Look, I can give you the solution in a minute but IMO you should practice Elixir more, it’s really easy.
dimitarvp
I hate how people immediately decided that ChatGPT is credible. ![]()
It hallucinates, and it does it well for the areas where it had trillion+ trainings / tokens. For everything else you might as well ask the local grocery store seller lady, she’ll give you a better answer. ![]()
But apart from that, I don’t get it how actually onboarding yourself in the language is viewed as this monumental task that should never be done. Boggles my mind. We’re not talking about Rust and OCaml here, which might easily take you months to properly onboard, we’re talking Elixir where one weekend is enough to start writing apps and parallel code and make a Phoenix project even.
roganjoshua
So I think after a bit more reading
I can get from
[
%{
"key" => "CUSTOMER",
"raw" => false,
"value" => "EOG.Acme.ManualXML",
"variable_type" => "env_var"
},
%{
"key" => "TRIGGER_PAYLOAD",
"raw" => false,
"value" => "{\"variables\":{\"CUSTOMER\":\"EOG.Acme.ManualXML\",\"VERSION\":\"Version-8.6.2\"},\"id\":\"5112\",\"ref\":\"main\"}",
"variable_type" => "file"
},
%{
"key" => "VERSION",
"raw" => false,
"value" => "Version-8.6.2",
"variable_type" => "env_var"
}
]
Because I only want the value for CUSTOME and VERSION
|> Enum.filter(fn %{key: key} -> key == "CUSTOMER" or key == "VERSION" end)
|> Enum.map(fn item -> item[:value] end)
["EOG.Acme.ManualXML", "Version-8.6.2"]
Which is quite close but I think if “key” was key: and “value” was value:
The main takeaway so far is
- Far more interest than I thought I would get
- iex is great but iex -S mix phx.server is fantastic
- dbg/2 (why this is dbg and not debug?)
- RTFM
dimitarvp
Then let’s start trying stuff that actually works. ![]()
Say you have a single map, only one:
%{
"key" => "CUSTOMER",
"raw" => false,
"value" => "EOG.Acme.ManualXML",
"variable_type" => "env_var"
}
How do you get the customer out of it?







