Maxximiliann

Maxximiliann

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:

Showing Posts 1 to 2

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.

Maxximiliann

Maxximiliann OP

Got it! Thanks for helping me make sense of it.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews