--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/29f1a6c9-2329-464d-b45f-8669ba7dd254%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The cost of the operation is O(m * n). It doesn't matter the operands. If the left side has three elements and the right has two, you need to traverse the left side two times, resulting in (3 * 2) operations altogether. If you reverse, you need to traverse the left side three times, which results in (2 * 3).
Plus we cannot know which list is shorter since calculating the length of the list is linear itself. If you know which one is shorter or you know the elements to delete, then you can use List.delete/2.
Using -- in some cases is fine but, if you are performing it multiple times, then you do likely need a better data structure.
On Fri, Mar 31, 2017 at 12:24 AM, <ruby...@foxmail.com> wrote:
hi, elixir team!
I'm using elixir in some projects, and I often using `--` operator like this:
```
list1 = [1, 2, 3]
list2 = [2, 4]
new_list = list1 -- list2
```
I think is the easiest way to find the element in list1 and not in list2. But it seems very expensive, as this article said:
http://erlang.org/doc/efficiency_guide/commoncaveats.html#id64604
Could we add a function like `List.minus` or `List.remove` to do this operation in a better way?
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.