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()
>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}]