Skip to content

Instantly share code, notes, and snippets.

@theangryangel
Last active December 27, 2018 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theangryangel/9d046aaecd3fbbca73dbd8abc5981776 to your computer and use it in GitHub Desktop.
Save theangryangel/9d046aaecd3fbbca73dbd8abc5981776 to your computer and use it in GitHub Desktop.
src = %{
first: %{
buy: [
%{cost: 90.394, supply: 2.245},
%{cost: 90.15, supply: 1.305},
%{cost: 89.394, supply: 4.3}
],
sell: [%{cost: 100.003, supply: 2.4}, %{cost: 100.013, supply: 2.2}]
},
second: %{
buy: [%{cost: 100.01, supply: 4.0}, %{cost: 91.33, supply: 1.8}],
sell: [%{cost: 90.15, supply: 3.4}, %{cost: 100.15, supply: 3.8}]
}
}
src
|> Enum.reduce(%{buy: [], sell: []}, fn {_k, v}, acc ->
acc
|> Map.put(:buy, acc.buy ++ v.buy)
|> Map.put(:sell, acc.sell ++ v.sell)
end)
|> IO.inspect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment