defmodule Demo do
defp to_string_(%{} = m) do
m
|> Map.to_list()
|> to_string_()
end
defp to_string_(l) when is_list(l) do
values =
l
|> Enum.map(&to_string_/1)
|> Enum.join(",")
"[#{values}]"
end
defp to_string_({k,v}) when is_atom(k) do
"#{Atom.to_string(k)}=#{to_string_(v)}"
end
defp to_string_(s) when is_binary(s) do
s
end
def convert(l) when is_list(l) do
to_string_(l)
end
end
buyer = %{
id: "BY789",
name: "Micheal",
surname: "test"
}
address = %{
contactName: "test tes ",
city: "test",
country: "test",
address: "test"
}
item = %{
id: "BI101",
category: "test",
type: "PHYSICAL",
price: "0.3"
}
IO.inspect(
Demo.convert([buyer: buyer, address: address, item: item])
)