Reputation: 10866
Without using brute-force (i.e. checking element by element), is there a built-in function that can check if one list is contained within another?
Upvotes: 3
Views: 1229
Reputation: 121000
I am not sure if it is a brute-force, and it has some limitations, but one might use Kernel.--/2
{l1, l2} = {[1,2,3], [1,2,3,4]}
l1 -- l2
#⇒ []
l2 -- l1
#⇒ [4]
The exact requested checker would be:
Enum.count(contained -- container) == 0
Or, as noted in comments by @Hynek-Pichi-Vychodil
contained -- container == []
Upvotes: 10