Elixir getting information from a list of maps -


i have structure being sent me via post: contacts = [%{"john" => ["0724573977"]}, %{"mary" => ["0724573111", "0744556778"]}] list of contacts each contact being map name => phone_numbers

i'm trying make list phone numbers, ignoring names, list of numbers:

a = [%{"1" => ["0724573977"]}, %{"2" => ["0724573111", "0744556778"]}]  p = enum.reduce a, [], fn(contact, acc) ->     {_record_id, phones} <- contact         phone <- phones             acc ++ phone         end     end end  io.inspect p 

this 1 produces: [[[["0724573977"] | "0724573111"], [["0724573977"] | "0744556778"]]] odd don't know doing wrong.

this may not idiomatic elixir i'm new language works me:

iex(11)> list.flatten(enum.map(a, fn(x) -> map.values(x) end)) ["0724573977", "0724573111", "0744556778"] 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -