tajihiro
tajihiro

Reputation: 2443

How to put label to tuple and convert map by elixir

I would like to put label to tuple data. I have following tuple data.

{"Bob","34","jp"}

Then I want to put label and make map.

%{name: "Bob", age: "34", from: "jp"}

I don't mind whatever labels come from. list or map or whatever else.

Please give me advice. Thanks.

Upvotes: 0

Views: 350

Answers (1)

tajihiro
tajihiro

Reputation: 2443

    members = 
    [{"Bob","34","jp"}, {"Geo","25","en"}, {"Cha","31","us"}]
       |> Enum.map(fn({n, a, f}) -> %{name: n, age: a, from: f} end)

It was easy.

Upvotes: 1

Related Questions