defmodule Sandbox do
def currencies do
[
%{
"USD" => %{
asset: "USD",
exchange_currencies: ["JPY"],
priced_in: "KHR"
}
},
%{
"CVE" => %{
asset: "CVE",
exchange_currencies: ["JPY"],
priced_in: "KHR"
}
},
%{
"CVE" => %{
asset: "CVE",
exchange_currencies: ["KHR", "JPY"],
priced_in: "USD"
}
},
%{
"AUD" => %{
asset: "AUD",
exchange_currencies: ["JPY"],
priced_in: "KHR"
}
},
%{
"AUD" => %{
asset: "AUD",
exchange_currencies: ["KHR", "USD", "JPY", "ZAR"],
priced_in: "KRW"
}
},
%{
"AUD" => %{
asset: "AUD",
exchange_currencies: ["KHR", "JPY"],
priced_in: "USD"
}
},
%{
"AUD" => %{
asset: "AUD",
exchange_currencies: ["KHR", "KRW", "LAK", "MGA", "XOF", "USD", "JPY", "AUD", "EUR"],
priced_in: "ZAR"
}
},
%{
"ZAR" => %{
asset: "ZAR",
exchange_currencies: ["JPY"],
priced_in: "KHR"
}
},
%{
"ZAR" => %{
asset: "ZAR",
exchange_currencies: ["KHR", "USD", "JPY", "ZAR"],
priced_in: "KRW"
}
},
%{
"ZAR" => %{
asset: "ZAR",
exchange_currencies: ["JPY", "ZAR"],
priced_in: "LAK"
}
},
%{
"ZAR" => %{
asset: "ZAR",
exchange_currencies: ["KHR", "USD", "ZAR"],
priced_in: "MGA"
}
},
%{
"ZAR" => %{
asset: "ZAR",
exchange_currencies: ["KHR", "USD", "JPY", "ZAR"],
priced_in: "XOF"
}
},
%{
"ZAR" => %{
asset: "ZAR",
exchange_currencies: ["KHR", "JPY"],
priced_in: "USD"
}
},
%{
"ZAR" => %{
asset: "ZAR",
exchange_currencies: ["KHR", "KRW", "USD", "JPY", "ZAR"],
priced_in: "AUD"
}
},
%{
"ZAR" => %{
asset: "ZAR",
exchange_currencies: ["LAK", "ZAR"],
priced_in: "EUR"
}
},
%{
"MNT" => %{
asset: "MNT",
exchange_currencies: ["JPY"],
priced_in: "KHR"
}
}
]
end
def foo do
currencies = currencies()
Enum.map(currencies, fn {_asset, record} -> record end)
end
def bar do
data = %{"USD" => %{asset: "USD", exchange_currencies: ["JPY"], priced_in: "KHR"}}
Enum.map(data, fn {_asset, record} -> record end)
end
end
iex(1)> Sandbox.bar
[%{asset: "USD", exchange_currencies: ["JPY"], priced_in: "KHR"}]
iex(2)> Sandbox.foo
** (FunctionClauseError) no function clause matching in anonymous fn/1 in Sandbox.foo/0
The following arguments were given to anonymous fn/1 in Sandbox.foo/0:
# 1
%{"USD" => %{asset: "USD", exchange_currencies: ["JPY"], priced_in: "KHR"}}
(arbit 0.1.0) lib/Sandbox.ex:122: anonymous fn/1 in Sandbox.foo/0
(elixir 1.10.3) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
Why exactly does Sandbox.foo
fail but Sandbox.bar
succeed? How shouldSandbox.foo
be corrected for it to succeed as well?