Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to partition IEnumerable(Of T) based on pattern in order of T?
    text
    copied!<p>Consider the following IEnumerable(Of String):</p> <pre><code> Moe1 Larry1 Curly1 Shemp1 Curly1 Moe2 Larry1 Curly1 Shemp1 Curly1 Curly2 Shemp2 Curly1 Curly2 Larry2 Curly1 Larry3 Shemp1 </code></pre> <p>They're visually split here to make the pattern easier to see. I want to partition an IEnumerable(Of String) using the .StartsWith() predicate, into an IEnumerable(Of IEnumerable(Of String).</p> <p>The rules are:</p> <ul> <li>every partitioned subset <em>must</em> have a <strong>Larry</strong>, and <em>might</em> have a Moe</li> <li>partition on <strong>Moe</strong> when <strong>Moe</strong> encountered</li> <li>if <strong>Larry</strong> immediately follows <strong>Moe</strong>, put him with the last <strong>Moe</strong></li> <li>if <strong>Larry</strong> immediately follows anyone else, partition on <strong>Larry</strong></li> <li>all other stooges are put with the current partition</li> <li>all stooges other than <strong>Moe</strong> and <strong>Larry</strong> can repeat in a partition</li> </ul> <p>I'm using the .StartsWith("Moe"), etc. to identify the type of stooge, but I'm having a hard time figuring out how to partition this set using LINQ operators so that <em>if</em> <strong>Moe</strong> is present, he represents the head of a partition, but since <strong>Larry</strong> must exist in each partition, he might represent the head of a partition if a <strong>Moe</strong> does not precede him.</p> <p>How can I create the IEnumerable(Of IEnumerable(Of String) so that the result is partitioned the way I display the set with blank lines?</p> <p>If there are no suitable LINQ operators for something like this (I'm programming in VB.NET if there are subtle differences in capabilities between VB.NET &amp; C#), and I simply need to write a method to do this, I can do that, but I thought this might be a problem that comes up and is solved easily with LINQ operators.</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload