Enum.map(?
Of course. Now show me a code snippet thatâs doing it.
|> Enum.map(%{customer: map["value"]})
Have you tried running that in iex? I donât want you to just write what you think it is, I want you to try and run it as well.
|> Map.get(:body) |> Enum.map(%{customer: map["value"]})
** (BadFunctionError) expected a function, got: %{customer: "EOG.Acme.ManualXML"}
(elixir 1.15.7) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
(elixir 1.15.7) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
Yep. Canât work.
How well do you know Elixir?
I have never really seen it since a couple of weeks maybe a bit longer but only a couple of weeks of really trying
Well that explains a lot.
Do you know what is the expected type of the 2nd argument to Enum.map?
a function
Yep. And %{customer: map["value"]} is not a function.
So what next?
Have you covered the official guide?
|> Enum.into( %{}, fn item -> {"Customer", item["value"]} end)
Yes, somewhat, but Enum.into only fills up a single map.
You want a list of maps as a result. Thatâs why you should be using Enum.map. You need that but you are giving it the wrong 2nd argument. It must be a function, not a map.
Do you know how to pass a function as an argument to another function?
Kind of like the one above?
|> Enum.map( fn item -> {"Customer", item["value"]} end)
which give me
[
{"Customer", "EOG.Acme.ManualXML"},
{"Customer",
"{\"variables\":{\"CUSTOMER\":\"EOG.Acme.ManualXML\",\"VERSION\":\"Version-8.6.2\"},\"id\":\"5112\",\"ref\":\"main\"}"},
{"Customer", "Version-8.6.2"}
]
You are almost there. ![]()
It is exciting
OK, put |> Map.new() at the end. ![]()
I do want
[
{"Customer", "EOG.Acme.ManualXML"},
{"Version", "Version-8.6.2"}
]
do I have to use some kind of if statement on item[âkeyâ] = âCUSTOMERâ etc.
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.
One tip, ask chatgpt how to do something in elixir, it can be your pair programmer who does nothing but knows everything. ![]()






















