title: Combining multiple lambda functions together with efficient execution
body: <p>I'm trying to create a dynamic filter using a combination of lambda functions.  But the number of lambda functions could vary based on the number of different filters the user applies.</p>
  
  <p>I want something that behaves like this</p>
  
  <pre><code>//images is a List&lt;ImageInfo&gt;
  var result1 = images
  .Where(image =&gt; image.Bytes &lt; 1000)
  .Where(image =&gt; image.Height &lt; 100)
  .Where(image =&gt; image.Width &lt; 100);
  </code></pre>
  
  <p>Where the height filter is only applied to those images that pass the bytes filter.  And the width filter is only applied by to those images that pass the height filter.</p>
  
  <p>But, the dynamic fashion of how the filters are turned on and off by the users doesnt allow me to create a single lambda function.</p>
  
  <p>Instead I'll create a list of lambda functions and then need to apply them to the list of images.  So I would end up with something like this; multiple individual lambda functions.</p>
  
  <pre><code>var filter1 = images.Where(image =&gt; image.Bytes &lt; 1000);
  var filter2 = images.Where(image =&gt; image.Height &lt; 100);
  var filter3 = images.Where(image =&gt; image.Width &lt; 100);
  </code></pre>
  
  <p>How can I join multiple lambda functions together to get my final list of filtered images?</p>
  
  <p>I did this</p>
  
  <pre><code>var result = filter1.Intersect&lt;ImageInfo&gt;(filter2).Intersect&lt;ImageInfo&gt;(filter3);
  </code></pre>
  
  <p>But each filter spins through the main list of images to get its subset of images, and then does an intersection calculation, which takes way too much CPU.</p>
  
  <p>So what I'm looking for is a way to take an arbitrary list of lambda functions (Expressions...whatever) and join them in a way that gets executed the way the first example I showed does.</p>