Maxximiliann

Maxximiliann

(ArgumentError) argument error (stdlib 3.11.2) :maps.from_list

results = 
[
  {%{
     asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
     price: 0.10878614,
     priced_in: "WAVES",
     value_in_usd_n: 0.11197357390200001
   },
   %{
     asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
     price: 1.668e-5,
     priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
     value_in_usd_n: 0.126019068
   }},
  {%{
     asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
     price: 0.0257055,
     priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
     value_in_usd_n: 194.20762305
   },
   %{
     asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
     price: 191.02,
     priced_in: "WAVES",
     value_in_usd_n: 196.61688600000002
   }},
  {%{
     asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
     price: 0.078461,
     priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
     value_in_usd_n: 0.078461
   },
   %{
     asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
     price: 0.07653975,
     priced_in: "WAVES",
     value_in_usd_n: 0.07878236467500001
   }}
]

Code:

results
	|> Map.new(fn {%{
		asset: asset,
		price: ask,
		priced_in: buy_with,
		value_in_usd_n: purchase_value_in_usd_n
		},
		%{
			asset: asset,
			price: bid,
			priced_in: sell_into,
			value_in_usd_n: sell_value_in_usd_n
			}}
			->
				%{
					asset: asset,
					buy_with: buy_with,
					ask: ask,
					purchase_value_in_usd_n: purchase_value_in_usd_n, 
					sell_into: sell_into,
					bid: bid,
					sell_value_in_usd_n: sell_value_in_usd_n,
					profit_percentage: ((sell_value_in_usd_n - purchase_value_in_usd_n) / purchase_value_in_usd_n) * 100 |>Float.round(2)
		}
	end)

Error:

** (ArgumentError) argument error
    (stdlib 3.11.2) :maps.from_list([%{ask: 0.10878614, asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2", bid: 1.654e-5, buy_with: "WAVES", profit_percentage: 11.6, purchase_value_in_usd_n: 0.11197357390200001, sell_into: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS", sell_value_in_usd_n: 0.12496135400000001}, %{ask: 0.0257055, asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu", bid: 191.02, buy_with: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS", profit_percentage: 1.24, purchase_value_in_usd_n: 194.20762305, sell_into: "WAVES", sell_value_in_usd_n: 196.61688600000002}, %{ask: 0.078461, asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8", bid: 0.07653975, buy_with: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p", profit_percentage: 0.41, purchase_value_in_usd_n: 0.078461, sell_into: "WAVES", sell_value_in_usd_n: 0.07878236467500001}
    (elixir 1.10.1) lib/map.ex:213: Map.new_transform/3

What did I miss? Thanks so much for your patient help! :slight_smile:

Marked As Solved

al2o3cr

al2o3cr

The function passed to Map.new/2 is specced to have this type:

term -> {key, value}

The function in your example is returning a map instead of a two-element tuple.

Based on the code in the function, I believe you want Enum.map/2, not Map.new/2.

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

We're in Beta

About us Mission Statement