Delete multiple elements from a list
I think you are looking for this
# Example with static values
iex> [1, 2, 3, 4, 5] -- [1, 2]
[3, 4, 5]
# Example with Enum.drop/2, with multiple values
iex> Enum.drop([1, 2, 3, 4, 5], 2)
[3, 4, 5]
iex> Enum.drop([1, 2, 3, 4, 5], -2)
[1, 2, 3]
iex> Enum.drop([1, 2, 3, 4, 5], 20)
[]
iex> Enum.drop([1, 2, 3, 4, 5], -20)
[]
You can use List.delete/2
only can delete one at time and Enum.drop/2
can delete multiple depend how you use it.
If you want to remove elements based on some arbitrary condition, you can use Enum.reject/2
, and provide the reject condition as an argument.
iex(1)> Enum.reject([1,2,3,4,5], fn x -> x in [1,2] end)
[3, 4, 5]