Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set substract operation

I want to do set operation for two tuple item’s list and "-" operation not work.

My code is as follows, can it be simplied?

iex(6)> b = [{1,0,0},{1,0,1}]
[{1, 0, 0}, {1, 0, 1}]
iex(7)> c = [{1,0,1}]

iex(9)> MapSet.difference(MapSet.new(b),MapSet.new(c)).to_list()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You do not need to use MapSet for that, -- is enough:

iex> [{1,0,0},{1,0,1}] -- [{1,0,1}]
[{1, 0, 0}]

For your code above, .to_list is tying to access a :to_list key on the MapSet struct, which does not exist. Elixir does not have methods, you cannot use data.function() to call a function, you have to always use the module name (except for Kernel, where it can be omitted). The correct syntax is to use a pipe:

iex> MapSet.difference(MapSet.new(b),MapSet.new(c)) |> MapSet.to_list()
[{1, 0, 0}]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading