title: LINQ method to join every n elements in a series by a function, and then re-aggregate those results into a new list?
body: <p>Not sure if the question is titled clearly, but here goes. I have some rather messy code in my ASP.NET MVC 3 app to wrap every 2 (but make this configurable from 1-n) items in a list in a div tag when they are printed out. I'd like to create a LINQ function like so:</p>
  
  <pre><code>// Can't think of a better name
  IEnumerable&lt;V&gt; FormattedSubsetList&lt;T, V&gt;(IEnumerable&lt;T&gt; items, int every = 2, [delegate to a method to join the N elements])
  {
  }
  </code></pre>
  
  <p>Sorry if this is kind of complicated... I'll try an example. Let's say I have a list of <code>Widget</code>. I want to print out the names of all my widgets (let's say I have 7) and I want every 2 widgets to be inside a div. So if I have...</p>
  
  <pre><code>var list = new List&lt;Widget&gt;();
  list.Add(new Widget() { Name = "One" });
  //... you get the picture
  list.Add(new Widget() { Name = "Seven" });
  
  IEnumerable&lt;string&gt; newList = FormattedSubsetList&lt;Widget, string&gt;(list, 2, (one, two) =&gt; (return "&lt;div&gt;" + string.Join(" ", one.Name, two.Name) + "&lt;/div&gt;");
  string finalString = string.Join(string.Empty, newList);
  // finalString == &lt;div&gt;One Two&lt;/div&gt;&lt;div&gt;Three Four&lt;/div&gt;&lt;div&gt;Five Six&lt;/div&gt;&lt;div&gt;Seven&lt;/div&gt;
  </code></pre>
  
  <p>I apologize if anything is unclear but I simply don't know what sort of thing this is called and have no idea how to go about implementing it. I know my LINQ syntax is a little off in some places too.</p>