How to convert list of list to map?

I have a list which consists of [A, B, C, D, E] and A has a list of values [1, 2, 3, 4, 5] similarly B has a list of values [1, 2, 3, 4, 5]

Date,SKU,Unit Price,Quantity,Total Price
2019-01-01,Death by Chocolate,180,5,900
2019-01-01,Cake Fudge,150,1,150
2019-01-01,Cake Fudge,150,1,150
2019-01-01,Cake Fudge,150,3,450
2019-01-01,Death by Chocolate,180,1,180
2019-01-01,Vanilla Double Scoop,80,3,240
2019-01-01,Butterscotch Single Scoop,60,5,300
2019-01-01,Vanilla Single Scoop,50,5,250
2019-01-01,Cake Fudge,150,5,750

Something like this but what I want is to create a map where the header is equal to values corresponding to it.

The expected output looks something like this:-

[%{date: '2019-01-01',SKU: 'Death by Chocolate', price: 50, quantity: 3},
    %{date: '2019-01-01',SKU: 'Cake Fudge', price: 150, quantity: 3}]

Enum.zip/1 and Enum.map/2 are your friends here.

[[1, 2, 3, 4], ~w[one two three four]]
|> Enum.zip()
|> Enum.map(fn {number, word} ->
  %{
    number: number,
    word: word
  }
end)
3 Likes

Thanks bro. You’re expert! :laughing:

This looks like a perfect candidate for CSV parsing?

2 Likes