find the unpaired items in a csv file

Say we have a csv file that has many trade items with its attributes. One of the attributes is the direction: in(1) or out(2). We expect the trades to be balanced (If there is a trade in, there is a trade out.) But there always are unbalanced trades. We should find out the unbalanced trades and check out the reason.
The csv file looks like this:

F_id,F_trade_id,F_direction,...
1,xxxx001,1,...
2,xxxx002,1,...
3,xxxx001,2,...
.......

Because I am learning elixir recently, so I am trying to solve this problem with elixir. And I found elixir is quite suitable for such tasks.
Here is the code snippet. In case you gays or myself from the future might need it.

{:ok, content} = File.read("trades.csv")

list = String.split(content, "\n") |> List.delete_at(0) |> Enum.map(&String.split(&1, ","))

unpaired = Enum.reduce(list, %{}, fn item, _acc ->
  case Map.get(_acc, Enum.at(item,1)) do
    nil ->
      Map.put(_acc, Enum.at(item, 1), Enum.at(item,2))
    _map ->
      _acc = Map.delete(_acc, Enum.at(item,1))
  end
end
)

Hello and welcome,

Using underscore prefix for variable has a special meaning.

You should not use _acc, but acc, because You are using it later.

Thanks~
Iā€™ve read so many of your posts and those helped a lot!

But without ā€œ_ā€, the compiler complained this: :grinning:

warning: variable "acc" is unused (if the variable is not meant to be used, prefix it with an underscore)
  iex:16

By the way, I excuted the snippet in the iex shell.

You also need to change it here I think :slight_smile: