softshipper
softshipper

Reputation: 34071

How does this expression work

I am pretty new in elixir and tried following code:

iex(19)> [1,2,true,false,true] -- [true, false]
[1, 2, true]

Can someone please explain, how this works?

Upvotes: 0

Views: 46

Answers (2)

Onorio Catenacci
Onorio Catenacci

Reputation: 15293

In addition to Christian's excellent answer you might also want to look at the Elixir Kernel Module docs (here). Specifically this:

Removes the first occurrence of an item on the left for each item on the right.

Upvotes: 2

Christian Di Lorenzo
Christian Di Lorenzo

Reputation: 3612

You've subtracted two lists here and the result is the set difference. The 3rd and 4th items were not included in the final result. Is this what you're asking?

iex(19)> [1,2,true,false,true] -- [true, false]  # [1,2,_,_,true] is the union
[1, 2, true]

Does this answer your question?

Upvotes: 2

Related Questions