You may find MapSet <https://hexdocs.pm/elixir/MapSet.html> useful for your 
use case. 

On Thursday, 30 March 2017 16:40:02 UTC+1, [email protected] wrote:
>
> Thank you!
>
> On Thursday, March 30, 2017 at 11:34:58 PM UTC+8, José Valim wrote:
>>
>> 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.
>>
>>
>> *José Valim*
>> www.plataformatec.com.br
>> Skype: jv.ptec
>> Founder and Director of R&D
>>
>> On Fri, Mar 31, 2017 at 12:24 AM, <[email protected]> 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 [email protected].
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/elixir-lang-core/29f1a6c9-2329-464d-b45f-8669ba7dd254%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/elixir-lang-core/29f1a6c9-2329-464d-b45f-8669ba7dd254%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/6383f30a-0bca-4a19-9409-dab338d68da3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to