Kernel.--
You're seeing just the function
--
, go back to Kernel module for more information.
Specs
List subtraction operator. Removes the first occurrence of an element on the left list for each element on the right.
Before Erlang/OTP 22, the complexity of a -- b
was proportional to
length(a) * length(b)
, meaning that it would be very slow if
both a
and b
were long lists. In such cases, consider
converting each list to a MapSet
and using MapSet.difference/2
.
As of Erlang/OTP 22, this operation is significantly faster even if both
lists are very long, and using --/2
is usually faster and uses less
memory than using the MapSet
-based alternative mentioned above.
See also the Erlang efficiency
guide.
Inlined by the compiler.
Examples
iex> [1, 2, 3] -- [1, 2]
[3]
iex> [1, 2, 3, 2, 1] -- [1, 2, 2]
[3, 1]
The --/2
operator is right associative, meaning:
iex> [1, 2, 3] -- [2] -- [3]
[1, 3]
As it is equivalent to:
iex> [1, 2, 3] -- ([2] -- [3])
[1, 3]