title: Multiple (tuple-based) generators in list comprehension in Erlang
body: <p>I am trying to filter a list of tuples based on whether the first element of the tuples matches the elements in another list. </p>
  
  <p>For instance, the original list is</p>
  
  <pre><code>163&gt;Shoppinglist.
  [{oranges,2},{milk,1},{apples,2}]
  </code></pre>
  
  <p>If I try to use multiple generators with the <code>&lt;-</code> notation, it loops and results in elements repeated more than once like this:</p>
  
  <pre><code>164&gt; [(Item)||{Item,Unit}&lt;-Shoppinglist, Item&lt;-[apples,milk]].
  [apples,milk,apples,milk,apples,milk]
  </code></pre>
  
  <p>This is explained nicely in the answer by Alexey Romanov in this question: <a href="https://stackoverflow.com/questions/14321265/multiple-filters-in-list-comprehension-in-erlang#">Multiple filters in list comprehension in Erlang</a>. Based on this answer, I can do the below and it works fine. </p>
  
  <pre><code>165&gt;[{Item}||{Item,Unit}&lt;-Shoppinglist,(Item==apples) or (Item==milk)].
  [apples, milk]
  </code></pre>
  
  <p>But this doesn't really meet my need, since I would like the second list <code>Item&lt;-[apples,milk]</code> to come in as an input, and because it may not always be practical to manually list out all the matches like <code>(Item==apples) or (Item==milk)</code> for a very long list. </p>
  
  <p>So is there any way to actually use multiple lists as generators? Or a more clever way to solve my problem..I only started very recently with Erlang (with the Pragmatic Programming and the LYSE books) so I still know very little. </p>