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

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
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
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
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
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement