Maxximiliann

Maxximiliann

Error: ** (Protocol.UndefinedError) protocol Enumerable not implemented for "WAVES" of type BitString

Given:

market_data = 
[
  %{
    asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
    last_price: 0.1249534,
    priced_in: "WAVES",
    volume: 13793.6013752778
  },
  %{
    asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
    last_price: 1.626e-5,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 10311.7855749146
  },
  %{
    asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
    last_price: 189.658785,
    priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
    volume: 52373.8805236538
  },
  %{
    asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
    last_price: 186.06, 
    priced_in: "WAVES",
    volume: 24023.1442492862
  },
  %{
    asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
    last_price: 0.02497085,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 8690.02335386836
  },
  %{
    asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
    last_price: 0.08150997,
    priced_in: "WAVES",
    volume: 40979.8114711376
  },
  %{
    asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
    last_price: 1.097e-5,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 252.945468613465
  },
  %{
    asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
    last_price: 0.08329,
    priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
    volume: 201.247929171753
  },
  %{
    asset: "5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3",
    last_price: 0.00808268,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 3248.6225669422
  },
  %{
    asset: "5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3",
    last_price: 60.20503371,
    priced_in: "WAVES",
    volume: 516.180493091221
  },
  %{
    asset: "7Z5peMVTuyEesJcYn7B6DDtV8oqKAFueBA52vPuf59rh",
    last_price: 0.91104345,
    priced_in: "WAVES", 
    volume: 26300.1502283905
  },
  %{
    asset: "7Z5peMVTuyEesJcYn7B6DDtV8oqKAFueBA52vPuf59rh",
    last_price: 1.2554e-4,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 577.404317777729
  },
  %{
    asset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    last_price: 7532.54,
    priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
    volume: 163617.091159899
  },
  %{
    asset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    last_price: 8250,
    priced_in: "34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ",
    volume: 1489.58529413729
  },
  %{
    asset: "Bwn3tDxj1rqqFGsnEy7Z829aj8Gs2UVQA7yktaJ6auHN",
    last_price: 7.1e-7,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 1259.50422417225
  },
  %{
    asset: "Bwn3tDxj1rqqFGsnEy7Z829aj8Gs2UVQA7yktaJ6auHN",
    last_price: 0.00430558,
    priced_in: "WAVES",
    volume: 290.292294688471
  },
  %{
    asset: "DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J",
    last_price: 300000000005,
    priced_in: "7b4tRbsy8zNDW35gW9DETdRU5yaNoFGm2SvmwRuCns3f",
    volume: 447641.500005591
  },
  %{
    asset: "DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J",
    last_price: 0.05229596,
    priced_in: "WAVES",
    volume: 14287.8709376739
  },
  %{
    asset: "DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J",
    last_price: 0.05294568,
    priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
    volume: 13348.2393706553
  },
  %{
    asset: "DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J",
    last_price: 7.94e-6,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 10824.4211299108
  },
  %{
    asset: "EYz8Zvs62D4d7F5ZgXHCWuzuFaZg63FYnfVQrTWQoLSK",
    last_price: 7.9e-5,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 1666.02995108187
  },
  %{
    asset: "EYz8Zvs62D4d7F5ZgXHCWuzuFaZg63FYnfVQrTWQoLSK",
    last_price: 0.57,
    priced_in: "WAVES",
    volume: 1582.6257
  },
  %{
    asset: "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk",
    last_price: 0.00594059,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 4020.64881215575
  },
  %{
    asset: "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk",
    last_price: 43.9669216,
    priced_in: "WAVES",
    volume: 2384.30279291976
  },
  %{
    asset: "WAVES",
    last_price: 1.010899,
    priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
    volume: 383661.118208469
  },
  %{
    asset: "WAVES",
    last_price: 1.3345e-4,
    priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    volume: 51539.1607843401
  },
  %{
    asset: "WAVES",
    last_price: 1.0467, 
    priced_in: "34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ",
    volume: 705.83415129
  }
]

Code:

def conversions do
		market_data
		|> Enum.map(fn map -> if Enum.member?(map.priced_in, "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS") do
				%{
					asset: map.asset,
					btc_price: map.last_price
				}
			else
				%{
					asset: map.asset,
					price: map.last_price,
					priced_in: map.priced_in,
					asset_to_btc_rate: asset_to_btc_rate(map.priced_in),
					btc_price: map.last_price * asset_to_btc_rate(map.priced_in)
				}
			end
		end) 
end
Error: ** (Protocol.UndefinedError) protocol Enumerable not implemented for "WAVES" of type BitString. This protocol is implemented for the following type(s): Ecto.Adapters.SQL.Stream, Postgrex.Stream, DBConnection.PrepareStream, DBConnection.Stream, HashSet, Map, Function, List, File.Stream, Date.Range, Range, HashDict, MapSet, Stream, IO.Stream, GenEvent.Stream

What’s going on here and how do I resolve this issue? Thanks for your patient help! :slight_smile:

Marked As Solved

Marcus

Marcus

Hello,

you are mapping over a list of maps. Therefore you get a map and map.prieced_in is a binary and this you give to Enum.member?, but Enum.member? needs an enumerable not a binary. The first data, in this case, is "WAVES" and for this protocol Enumerable not implemented ...

Also Liked

andreolvr

andreolvr

The compile error is happening because this is not the correct syntax for case, take a look at https://elixir-lang.org/getting-started/case-cond-and-if.html. Another problem in this logic is that the third clause (_) will never be reached, the value is equals 8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS or not. There is no third option. Maybe you are looking for an if/else instead of a case?

Marcus

Marcus

Maybe, you needs …

def conversions(nil), do: nil
def conversions(market_data) do
	Enum.map(market_data, fn map -> 
		if map.priced_in != "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS" do
			%{
				asset: map.asset,
				price: map.last_price,
				priced_in: map.priced_in,
				asset_to_btc_rate: asset_to_btc_rate(map.priced_in),
				btc_price: map.last_price * asset_to_btc_rate(map.priced_in)
			}
		else
			%{
				asset: map.asset,
				btc_price: map.last_price
			}
		end
	end)
end

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
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
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
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement